[Type] Tensor 3: Add qd.tensor_vec / qd.tensor_mat#523
Draft
hughperkins wants to merge 7 commits intohp/tensor-stork-2from
Draft
[Type] Tensor 3: Add qd.tensor_vec / qd.tensor_mat#523hughperkins wants to merge 7 commits intohp/tensor-stork-2from
hughperkins wants to merge 7 commits intohp/tensor-stork-2from
Conversation
Element-typed companions to qd.tensor: dispatch over qd.Vector.field / qd.Vector.ndarray and qd.Matrix.field / qd.Matrix.ndarray via the same backend= keyword. kwargs pass through verbatim. Adds: - tensor_vec(n, dtype, shape, *, backend=, **kwargs) and tensor_mat(n, m, dtype, shape, *, backend=, **kwargs). - Re-export through quadrants/__init__.py. - 11 tests covering type-equivalence to the underlying Vector/Matrix factories on each backend, invalid-backend rejection, and end-to-end kernel round-trips for vec and mat on both backends. - "Vector and matrix tensors" section in the user guide. All tests pass; sphinx build clean.
hughperkins
commented
Apr 20, 2026
| qd.init(arch=qd.x64) | ||
|
|
||
| # A 1-D tensor of 4 length-3 vectors, on the field backend (default). | ||
| v = qd.tensor_vec(3, qd.f32, shape=(4,)) |
Collaborator
Author
There was a problem hiding this comment.
wait, wouldnt it be better to preserve the xisting interface, just swap qd.Vector.field and qd.Vector.ndarray with qd.Vector.tensor ?
Collaborator
Author
There was a problem hiding this comment.
(and same for Matrix of course)
837ff7d to
bde8965
Compare
241b28a to
83a0456
Compare
bde8965 to
650d40c
Compare
83a0456 to
2d97d7f
Compare
Drops the 'flexible' prefix from filenames and identifiers introduced in this branch series so the user-visible names are simply 'tensor'. Also strips PR-N back-references that will be meaningless once these PRs land. Touches only files owned by this series (no changes to external/ or unrelated tests).
…r-stork-3 Made-with: Cursor # Conflicts: # python/quadrants/_tensor.py
- Reformat _tensor.py for black, fix ruff import sorting in __init__.py and the new test, and silence pylint import-outside-toplevel for the late imports that break circular dependencies. - Drop broken #fields / #ndarrays anchors in tensor.md. - Add Backend / tensor / tensor_mat / tensor_vec to the user_api[qd] snapshot in test_api. Made-with: Cursor
…r-stork-3 Made-with: Cursor # Conflicts: # docs/source/user_guide/tensor.md # python/quadrants/_tensor.py # tests/python/test_api.py
… / qd.Matrix.tensor The two top-level dispatcher functions added alongside qd.tensor() in the original PR 3 turned out to be redundant with the symmetry that the rest of the matrix/vector API uses (qd.Vector.field, qd.Vector.ndarray, ...). Genesis never adopted them; the user-facing docs already pointed at the classmethod form. Rename them to private impls (_tensor_vec, _tensor_mat) and drop them from quadrants._tensor.__all__, so they no longer leak into qd.*. Surface the per-tensor backend dispatch as qd.Vector.tensor and qd.Matrix.tensor classmethods on Vector / Matrix (in lang/matrix.py), both delegating to the private impls. The dispatch logic stays in one place; the public API gains the Vector.tensor / Matrix.tensor symmetry with the existing .field / .ndarray classmethods. Tests: - All vec/mat factory tests rewritten to call qd.Vector.tensor / qd.Matrix.tensor; same coverage (default/explicit FIELD, NDARRAY, invalid backend, kernel roundtrip on each backend). - New regression test_tensor_vec_mat_not_public asserts the old names are gone from the qd.* surface. - test_api.py: drop tensor_vec / tensor_mat from the expected set.
… / qd.Matrix.tensor The "Vector and matrix tensors" section in tensor.md (introduced alongside the original tensor_vec / tensor_mat dispatchers in this branch) still pointed at qd.tensor_vec / qd.tensor_mat — names that the privatization commit moved to private impls and dropped from the public API. Update the section text and code samples to use the new qd.Vector.tensor / qd.Matrix.tensor classmethod surface, matching what the rest of the doc already does on later branches. Cosmetic only; no API or test changes.
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.
Element-typed companions to qd.tensor: dispatch over qd.Vector.field / qd.Vector.ndarray and qd.Matrix.field / qd.Matrix.ndarray via the same backend= keyword. kwargs pass through verbatim.
Adds:
All tests pass; sphinx build clean.
Issue: #
Brief Summary
copilot:summary
Walkthrough
copilot:walkthrough