|
| 1 | + |
| 2 | +""" |
| 3 | + axes_types(::Type{T}) -> Type{Tuple{Vararg{AbstractUnitRange{Int}}}} |
| 4 | + axes_types(::Type{T}, dim) -> Type{AbstractUnitRange{Int}} |
| 5 | +
|
| 6 | +Returns the type of each axis for the `T`, or the type of of the axis along dimension `dim`. |
| 7 | +""" |
1 | 8 | @inline axes_types(x, dim) = axes_types(x, to_dims(x, dim)) |
2 | 9 | @inline function axes_types(x, dim::StaticInt{D}) where {D} |
3 | 10 | if D > ndims(x) |
|
77 | 84 | # conditionally typed (but inferrable) axes. It also means we can't depend on constant |
78 | 85 | # propagation to preserve statically sized axes. This should probably be addressed before |
79 | 86 | # merging into Base Julia. |
| 87 | +""" |
| 88 | + axes(A) -> Tuple{Vararg{AbstractUnitRange{Int}}} |
| 89 | + axes(A, dim) -> AbstractUnitRange{Int} |
| 90 | +
|
| 91 | +Returns the axis associated with each dimension of `A` or dimension `dim`. |
| 92 | +`ArrayInterface.axes(::AbstractArray)` behaves nearly identical to `Base.axes` with the |
| 93 | +exception of a handful of types replace `Base.OneTo{Int}` with `ArrayInterface.SOneTo`. For |
| 94 | +example, the axis along the first dimension of `Transpose{T,<:AbstractVector{T}}` and |
| 95 | +`Adjoint{T,<:AbstractVector{T}}` can be represented by `SOneTo(1)`. Similarly, |
| 96 | +`Base.ReinterpretArray`'s first axis may be statically sized. |
| 97 | +""" |
80 | 98 | @inline axes(A) = Base.axes(A) |
81 | 99 | axes(A::ReshapedArray) = Base.axes(A) |
82 | 100 | axes(A::PermutedDimsArray) = permute(axes(parent(A)), to_parent_dims(A)) |
|
261 | 279 |
|
262 | 280 | Base.show(io::IO, x::LazyAxis{N}) where {N} = print(io, "LazyAxis{$N}($(parent(x))))") |
263 | 281 |
|
| 282 | +""" |
| 283 | + lazy_axes(x) |
| 284 | +
|
| 285 | +Produces a tuple of axes where each axis is constructed lazily. If an axis of `x` is already |
| 286 | +constructed or it is simply retrieved. |
| 287 | +""" |
| 288 | +@generated function lazy_axes(x::X) where {X} |
| 289 | + Expr(:block, Expr(:meta, :inline), Expr(:tuple, [:(LazyAxis{$dim}(x)) for dim in 1:ndims(X)]...)) |
| 290 | +end |
| 291 | +lazy_axes(x::LinearIndices) = axes(x) |
| 292 | +lazy_axes(x::CartesianIndices) = axes(x) |
| 293 | +@inline lazy_axes(x::MatAdjTrans) = reverse(lazy_axes(parent(x))) |
| 294 | +@inline lazy_axes(x::VecAdjTrans) = (SOneTo{1}(), first(lazy_axes(parent(x)))) |
| 295 | +@inline lazy_axes(x::PermutedDimsArray) = permute(lazy_axes(parent(x)), to_parent_dims(x)) |
264 | 296 | @generated function lazy_axes(x::X) where {X} |
265 | 297 | Expr(:block, Expr(:meta, :inline), Expr(:tuple, [:(LazyAxis{$dim}(x)) for dim in 1:ndims(X)]...)) |
266 | 298 | end |
|
0 commit comments