Skip to content

[Type] Tensor 5: Document and test needs_grad on the factories#525

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

[Type] Tensor 5: Document and test needs_grad on the factories#525
hughperkins wants to merge 5 commits intohp/tensor-stork-4from
hp/tensor-stork-5

Conversation

@hughperkins
Copy link
Copy Markdown
Collaborator

needs_grad already passes through the factory **kwargs (PRs 2-3); this PR makes that contract explicit with tests and a user-guide section.

Adds:

  • 6 tests covering grad allocation, primal+grad kernel round-trip on field and ndarray scalar backends, and grad on tensor_vec/tensor_mat field.
  • "Gradients" section in the user guide showing the needs_grad= usage on both backends with a runnable example.

Documented limitation: qd.Vector.ndarray and qd.Matrix.ndarray do not currently accept needs_grad — that's an upstream Quadrants limitation and is noted in a code comment inside the test file.

All tests pass; sphinx build clean.

Issue: #

Brief Summary

copilot:summary

Walkthrough

copilot:walkthrough

needs_grad already passes through the factory **kwargs (PRs 2-3); this PR
makes that contract explicit with tests and a user-guide section.

Adds:
- 6 tests covering grad allocation, primal+grad kernel round-trip on field
  and ndarray scalar backends, and grad on tensor_vec/tensor_mat field.
- "Gradients" section in the user guide showing the needs_grad= usage on
  both backends with a runnable example.

Documented limitation: qd.Vector.ndarray and qd.Matrix.ndarray do not
currently accept needs_grad — that's an upstream Quadrants limitation and
is noted in a code comment inside the test file.

All tests pass; sphinx build clean.
@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).
- Apply black/ruff auto-fixes to _tensor.py and import ordering
- Add pylint disable=import-outside-toplevel for late imports
- Fix broken anchors #fields/#ndarrays in tensor.md (point to tensor_types.md)
- Add Backend, tensor*, tensor_annotation to test_api.py expected names

Made-with: Cursor
…r-stork-5

Made-with: Cursor

# Conflicts:
#	docs/source/user_guide/tensor.md
#	python/quadrants/_tensor.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