Skip to content

[Type] Tensor 3: Add qd.tensor_vec / qd.tensor_mat#523

Draft
hughperkins wants to merge 7 commits intohp/tensor-stork-2from
hp/tensor-stork-3
Draft

[Type] Tensor 3: Add qd.tensor_vec / qd.tensor_mat#523
hughperkins wants to merge 7 commits intohp/tensor-stork-2from
hp/tensor-stork-3

Conversation

@hughperkins
Copy link
Copy Markdown
Collaborator

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.

Issue: #

Brief Summary

copilot:summary

Walkthrough

copilot:walkthrough

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.
Comment thread docs/source/user_guide/tensor.md Outdated
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,))
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

wait, wouldnt it be better to preserve the xisting interface, just swap qd.Vector.field and qd.Vector.ndarray with qd.Vector.tensor ?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

(and same for Matrix of course)

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.
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.

1 participant