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
Use is_forwarding_wrapper trait instead of parent_type(T) <: T (#296)
Using the heuristic parent_type(T) <: T sometimes gives incorrect results and may hide holes in the interface (as I found when making these changes).
Some problems I found:
* is_increasing(stride_rank(A)) didn't account for A having zero dimensions
* is_dense(A) didn't know how to handle when dense_dims(A) returned nothing.
* contiguous_axis(::Type{<:ReshapedArray}) would sometimes return nothing (meaning the contiguous axis is unknown) instead of StaticInt(-1) when we actually knew there couldn't be a contiguous axis because it didn't exist in the parent array.
* (known)_dimnames(A) was often returning incorrect results for ReinterpretArray and ReshapedArray.
Copy file name to clipboardExpand all lines: docs/src/index.md
+9-5Lines changed: 9 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -34,15 +34,19 @@ Creating an array type with unique behavior in Julia is often accomplished by cr
34
34
This allows the new array type to inherit functionality by redirecting methods to the parent array (e.g., `Base.size(x::Wrapper) = size(parent(x))`).
35
35
Generic design limits the need to define an excessive number of methods like this.
36
36
However, methods used to describe a type's traits often need to be explicitly defined for each trait method.
37
-
`ArrayInterface` assists with this by providing information about the parent type using [`ArrayInterface.parent_type`](@ref).
38
-
By default `ArrayInterface.parent_type(::Type{T})` returns `T` (analogous to `Base.parent(x) = x`).
39
-
If any type other than `T` is returned we assume `T` wraps a parent structure, so methods know to unwrap instances of `T`.
40
-
It is also assumed that if `T` has a parent type `Base.parent` is defined.
37
+
If the the underlying data and access to it are unchanged by it's wrapper the [`ArrayInterface.is_forwarding_wrapper`](@ref) trait can signal to other trait methods to access its parent data structure.
38
+
Supporting this for a new type only requires defines these methods:
0 commit comments