Rework named-type parameters around a single Named scalar#173
Merged
Conversation
Reworks the type parameters of the named array and scalar types so the name leads and every parameter is inferable from the fields, and collapses the named-integer type hierarchy into a single `Named` scalar.
The named types now read `Named{Name, Denamed}` (the scalar), `AbstractNamedArray{Name, DenamedT, N} <: AbstractArray{Named{Name, DenamedT}, N}`, and `AbstractNamedUnitRange{Name, DenamedT<:Integer}`, with `Name` leading to match `AbstractITensor{DimName}` and the element type derived as `Named{Name, DenamedT}` rather than carried as a separate parameter. The concrete `NamedArray`, `NamedUnitRange`, and `Index` infer all of their parameters from their `value` and `name` fields.
A single `Named` wrapper replaces `AbstractNamedInteger`, the `NamedInteger` struct, `IndexVal`, and `NoncontiguousIndex`: a named integer is `Named{Name, <:Integer}`, an index value is `Named{IndexName, <:Integer}`, and a non-contiguous index is a `NamedArray` with an `IndexName` name. `NamedInteger` stays available as a parametric alias, `const NamedInteger{Name, Denamed<:Integer} = Named{Name, Denamed}`. Because the wrapper is universal, a `NamedArray` now works for any element type, where a non-integer `NamedArray` errored before.
Equality and hashing across named array types are type-agnostic, following Base's array convention (`[1, 2, 3] == 1:3` and they hash equally): one generic `hash(::AbstractNamedArray)` uses a single shared tag rather than the concrete type, so `a == b` implies `hash(a) == hash(b)`.
Breaking: the type-parameter order and shape change, and the `AbstractNamedInteger`, `NamedInteger` struct, `IndexVal`, and `NoncontiguousIndex` names are removed.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #173 +/- ##
==========================================
+ Coverage 73.44% 74.18% +0.73%
==========================================
Files 21 21
Lines 1141 1131 -10
==========================================
+ Hits 838 839 +1
+ Misses 303 292 -11
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:
|
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
Reworks the type parameters of the named array and scalar types so the name leads and every parameter is inferable from the fields, and collapses the named-integer type hierarchy into a single
Namedscalar.The named types now read
Named{Name, Denamed}(the scalar),AbstractNamedArray{Name, DenamedT, N} <: AbstractArray{Named{Name, DenamedT}, N}, andAbstractNamedUnitRange{Name, DenamedT<:Integer}, withNameleading to matchAbstractITensor{DimName}and the element type derived asNamed{Name, DenamedT}rather than carried as a separate parameter. The concreteNamedArray,NamedUnitRange, andIndexinfer all of their parameters from theirvalueandnamefields.A single
Namedwrapper replacesAbstractNamedInteger, theNamedIntegerstruct,IndexVal, andNoncontiguousIndex: a named integer isNamed{Name, <:Integer}, an index value isNamed{IndexName, <:Integer}, and a non-contiguous index is aNamedArraywith anIndexNamename.NamedIntegerstays available as a parametric alias,const NamedInteger{Name, Denamed<:Integer} = Named{Name, Denamed}. Because the wrapper is universal, aNamedArraynow works for any element type, where a non-integerNamedArrayerrored before.Equality and hashing across named array types are type-agnostic, following Base's array convention (
[1, 2, 3] == 1:3and they hash equally): one generichash(::AbstractNamedArray)uses a single shared tag rather than the concrete type, soa == bimplieshash(a) == hash(b).Breaking: the type-parameter order and shape change, and the
AbstractNamedInteger,NamedIntegerstruct,IndexVal, andNoncontiguousIndexnames are removed.