Rename the named-dimension interface and make construction strict - #264
Merged
Merged
Conversation
Brings the named-dimension interface onto plainer names, with `dimnames` becoming `Base.names` and the lowercase constructors giving way to the CamelCase ones. Breaking: a dimension given as an index now asserts its space on construction, and `matricize` returns a plain matrix. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #264 +/- ##
==========================================
+ Coverage 77.83% 77.91% +0.07%
==========================================
Files 30 30
Lines 1796 1807 +11
==========================================
+ Hits 1398 1408 +10
- Misses 398 399 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
A new tensor type overloads `names`, and `Base.names` forwards to it, so both spellings work while there is one place to implement. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
The internal helpers and the `NamedDimsCartesianIndex` types still read in the `nameddims` vocabulary the public surface moved off, so they take the `namedtensor` stem matching `NamedTensor`. `rename` also moves to `export`, since it replaces `replaceinds` and `mapinds`, which were both exported. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
`NamedCartesianIndex` subtypes `Base.AbstractCartesianIndex` and is not a tensor, so it takes the `Named` plus Base-type form used by `NamedInteger`, `NamedUnitRange` and the `NamedIndexCartesian` style beside it. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
`NamedTensor(array, codomain_inds, domain_inds)` now rejects a bipartition the array contradicts, which `TensorAlgebra.has_bipartition` makes possible to check. Raises the floors to TensorAlgebra 0.21.1 and GradedArrays 0.16.5. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
A broadcast that is not a sum, a scalar multiple or `conj` now throws rather than falling back to a generic element-wise broadcast over the unnamed operands. `map` broadcasts, so it goes the same way. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
`check_input` is now the whole argument contract for building a `NamedTensor`. The dimension count and the distinctness of names had been checked in the inner constructor instead, so the contract read in two places. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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.
Summary
Brings the named-dimension interface onto plainer names, makes construction strict, and restricts broadcasting to linear expressions.
What changes
replaceinds->rename, now exported, absorbingreplacedimnames,mapindsandmapdimnamesdimnames->names, which is ITensorBase's own function withBase.namesforwarding to it, so a new tensor type has one place to overload.dimnametype->nametypealigndims->align,aligneddims->alignednamed,nameddims,namedunitrange,namedarrayandnamedoneto-> the explicitNamed,NamedTensor,NamedUnitRange,NamedArrayandNamedOneTomatricizereturns a plain matrix, andunmatricizetakes named axes and returns a named tensorconjfold as before, and anything else throws rather than falling back to a generic element-wise broadcast over the unnamed operands.mapbroadcasts, so it goes the same wayNamedTensor(array, codomain_inds, domain_inds)for a map-shaped tensor, taking the domain inds codomain-facing and rejecting a bipartition the array itself contradicts