Repository navigation
Conversation
andrewdalpino
left a comment
Member
There was a problem hiding this comment.
So we have setDataType() that casts in-place but does not return this, cast that casts in place but does return this, and toDataType() which is an alias of cast? Is that right @apphp?
| --TEST-- | ||
| NDArray::cast() / toDataType() change the dtype in place and return $this | ||
| --FILE-- | ||
| <?php |
Member
There was a problem hiding this comment.
Totally unrelated, but what are your thoughts on either
A. Converting tests that only test the public API to PHP Unit
B. Only testing the extension through the public API, i.e. subsystems are tested indirectly, and dropping all these .phpt style tests
?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
NDArray::cast(string $dtype)and its aliasNDArray::toDataType(string $dtype)to change an array's datatype at runtime.setDataType(): the same PHP object (and every reference to it) gets the new dtype, so no new NDArray needs to be created.$this, so calls can be chained:$x->cast('float16')->toArray().Errorand leaves the array unchanged.NumPower::copy($x)->cast('int8').Ticket: #38
Testing
make testpasses withUSE_ZEND_ALLOC=1andUSE_ZEND_ALLOC=0(273 passed, 0 failed, 129 skipped — GPU tests) on PHP 8.4;tests/typesalso on PHP 8.1 and 8.5.tests/typesrun under Valgrind 3.19 (run-tests.php -mwithVALGRIND_OPTS="--leak-check=full --errors-for-leak-kinds=definite"): 31 passed, 0 leaked, 0 memory errors.Sanity check: with
NDArray_FREE(prev)removed from the cast path, the same run reportsLEAKon031-cast.phpt.Submission Checklist:
export USE_ZEND_ALLOC=1 && make testexport USE_ZEND_ALLOC=0 && make test(alsotests/typesunder Valgrind: 0 leaks, 0 memory errors — see Testing)Change to methods and operations
setDataType()now also rejects dtype names containing a NUL byte)NDARRAY_VCHECKenabled?Changes to Core Components:
N/A — no changes to
buffer.c,gpu_alloc.c,ndarray.c,iterators.cor their headers. Onlynumpower.c(method bindings) was modified.