You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This provides a specific example of supporting `dimnames`.
Also removed the need to specify a method per dimension access to
dimnames so `dimnames(::Type{T})` is all that's necessary.
Copy file name to clipboardExpand all lines: docs/src/index.md
+16-1Lines changed: 16 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -82,7 +82,7 @@ For example, all `Integers` passed to `to_dims` are converted to `Int` (unless `
82
82
This is also useful for arrays that uniquely label dimensions, in which case `to_dims` serves as a safe point of hooking into existing methods with dimension arguments.
83
83
`ArrayInterface` also defines native `Symbol` to `Int` and `StaticSymbol` to `StaticInt` mapping for arrays defining [`ArrayInterface.dimnames`](@ref).
84
84
85
-
Methods accepting dimension specific arguments should use some variation of the following pattern.
85
+
Methods requiring dimension specific arguments should use some variation of the following pattern.
86
86
87
87
```julia
88
88
f(x, dim) =f(x, ArrayInterface.to_dims(x, dim))
@@ -93,3 +93,18 @@ f(x, dim::StaticInt) = ...
93
93
If `x`'s first dimension is named `:dim_1` then calling `f(x, :dim_1)` would result in `f(x, 1)`.
94
94
If users knew they always wanted to call `f(x, 2)` then they could define `h(x) = f(x, static(2))`, ensuring `f` passes along that information while compiling.
95
95
96
+
New types defining dimension names can do something similar to:
97
+
```julia
98
+
using Static
99
+
using ArrayInterface
100
+
101
+
struct NewType{dnames} end# where dnames::Tuple{Vararg{Symbol}}
Dimension names should be appropriately propagated between nested arrays using `ArrayInterface.to_parent_dims`.
107
+
This allows types such as `SubArray` and `PermutedDimsArray` to work with named dimensions.
108
+
Similarly, other methods that return information corresponding to dimensions (e.g., `ArrayInterfce.size`, `ArrayInterface.axes`) use `to_parent_dims` to appropriately propagate parent information.
0 commit comments