Skip to content

[Type] Tensor 4: Add qd.tensor_annotation(backend) helper#524

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

[Type] Tensor 4: Add qd.tensor_annotation(backend) helper#524
hughperkins wants to merge 7 commits intohp/tensor-stork-3from
hp/tensor-stork-4

Conversation

@hughperkins
Copy link
Copy Markdown
Collaborator

Returns the kernel-argument annotation appropriate for a given backend: qd.template() instance for FIELD, qd.types.ndarray() instance for NDARRAY.

Mirrors the Genesis V_ANNOTATION = qd.types.ndarray() if use_ndarray else qd.template pattern as a single first-class call so users can pick a backend in one place and reuse the annotation across kernels.

Adds:

  • tensor_annotation(backend) in _flexible.py.
  • Re-export through init.py.
  • 6 tests: return type per backend, invalid-backend rejection, IntEnum coercion, end-to-end kernel use on each backend.
  • "Annotating kernel arguments" section in the user guide.

All tests pass; sphinx build clean.

Issue: #

Brief Summary

copilot:summary

Walkthrough

copilot:walkthrough

Returns the kernel-argument annotation appropriate for a given backend:
qd.template() instance for FIELD, qd.types.ndarray() instance for NDARRAY.

Mirrors the Genesis V_ANNOTATION = qd.types.ndarray() if use_ndarray
else qd.template pattern as a single first-class call so users can pick a
backend in one place and reuse the annotation across kernels.

Adds:
- tensor_annotation(backend) in _flexible.py.
- Re-export through __init__.py.
- 6 tests: return type per backend, invalid-backend rejection, IntEnum
  coercion, end-to-end kernel use on each backend.
- "Annotating kernel arguments" section in the user guide.

All tests pass; sphinx build clean.
@@ -102,6 +102,40 @@ m = qd.tensor_mat(2, 2, qd.f32, shape=(3,))
These match the existing `qd.Vector.*` / `qd.Matrix.*` factories one-for-one;
`qd.tensor_vec` / `qd.tensor_mat` simply add the per-tensor `backend=` knob.

Subsequent releases will add a `qd.tensor_annotation(backend)` helper for
kernel argument typing, and a `layout=` keyword for per-tensor physical-memory
## Annotating kernel arguments: `qd.tensor_annotation`
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.

maybe qd.Tensor?

@hughperkins hughperkins force-pushed the hp/tensor-stork-4 branch 2 times, most recently from 2743267 to e1540b7 Compare April 20, 2026 20:59
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-4

Made-with: Cursor

# Conflicts:
#	python/quadrants/__init__.py
…ion to API test

- Use pylint disable comments on the late imports inside `tensor_annotation`,
  matching the style used by the sibling dispatchers.
- Add `tensor_annotation` to the expected public-API symbol list in
  `tests/python/test_api.py`.

Made-with: Cursor
Use _types.template() (re-exported via quadrants.types) instead of a
separate `from quadrants.types.annotations import template` so the line
fits within ruff's import line-length and doesn't get auto-wrapped into
a form that misplaces the # pylint: disable=import-outside-toplevel
comment.

Made-with: Cursor
…r-stork-4

# Conflicts:
#	python/quadrants/_tensor.py
#	tests/python/test_api.py
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