Skip to content

NDArray setDataType() and dataType() - #33

Merged
andrewdalpino merged 6 commits into
mainfrom
ndarray-as-type
Sep 1, 2026
Merged

andrewdalpino merged 6 commits into
mainfrom
ndarray-as-type

Conversation

@andrewdalpino

@andrewdalpino andrewdalpino commented Sep 1, 2026 •

Copy link
Copy Markdown
Member

Implement NDArray->setDataType(string $dtype) API. Also provide an accessor for the data type.

@andrewdalpino
andrewdalpino requested review from a team and a lite review from Copilot September 1, 2026 14:46

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new NDArray::astype(string $dtype) method to the PHP extension, exposing existing dtype-casting functionality while preserving the array’s device (CPU/GPU) and returning a new NDArray. The PR also adds PHPT coverage for CPU and GPU casting behavior and error handling.

Changes:

  • Implement NDArray::astype() in numpower.c, including dtype canonicalization/validation and returning the cast result as an NDArray.
  • Register the new method in class_NDArray_methods.
  • Add PHPT tests validating dtype conversion semantics on CPU and GPU, plus error cases.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
numpower.c Adds and registers NDArray::astype() method with dtype validation and casting via existing internal APIs.
tests/types/029-astype-dtype-change.phpt Adds CPU-focused tests for value conversion, immutability (original unchanged), device preservation, scalar behavior, and errors.
tests/types/030-astype-dtype-change-gpu.phpt Adds GPU-focused tests ensuring astype() preserves GPU residency and converts values, plus invalid-dtype behavior.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread tests/types/030-astype-dtype-change-gpu.phpt Outdated
Comment thread numpower.c Outdated
andrewdalpino and others added 3 commits September 1, 2026 09:54
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

Comment thread numpower.c
Comment on lines +313 to +317
* `fill()`. The device (CPU or GPU) is preserved. If the target dtype
* equals the current dtype, the call is a true no-op with no allocation.
*
* Supported dtypes: float4, float8, float16, float32, float64, float128,
* int8, uint8, int16, uint16, int32, uint32, int64, uint64.

@andrewdalpino andrewdalpino Sep 1, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SkibidiProduction thought this would be helpful to you

Comment thread numpower.c
Comment thread tests/types/029-settype-dtype-change.phpt Outdated
Comment thread tests/types/030-settype-dtype-change-gpu.phpt Outdated
@andrewdalpino andrewdalpino changed the title NDArray asType() NDArray setDataType() and dataType() Sep 1, 2026
@andrewdalpino andrewdalpino reopened this Sep 1, 2026
@andrewdalpino
andrewdalpino merged commit 964de8c into main Sep 1, 2026
92 of 102 checks passed
@andrewdalpino
andrewdalpino deleted the ndarray-as-type branch September 1, 2026 21:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants