Skip to content

Commit 2c1eb9e

Browse files
authored
Add doc strings and update old methods (#279)
* @assume_effects replaces @pure now * Fix docs and outdated methods More docs that got lost transitioning to libraries * Fix typo in ArrayInterfaceOffsetArrays test
1 parent cab9462 commit 2c1eb9e

File tree

8 files changed

+64
-8
lines changed

8 files changed

+64
-8
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "ArrayInterface"
22
uuid = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9"
3-
version = "6.0.3"
3+
version = "6.0.4"
44

55
[deps]
66
ArrayInterfaceCore = "30b0a656-2188-435a-8636-2ec0e6a096e2"

docs/src/api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ ArrayInterfaceCore.findstructralnz
2626
ArrayInterfaceCore.lu_instance
2727
ArrayInterfaceCore.matrix_colors
2828
ArrayInterfaceCore.issingular
29-
ArrayInterfaceCoreCore.parent_type
29+
ArrayInterfaceCore.parent_type
3030
ArrayInterfaceCore.restructure
3131
ArrayInterfaceCore.safevec
3232
ArrayInterfaceCore.zeromatrix

lib/ArrayInterfaceCore/Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "ArrayInterfaceCore"
22
uuid = "30b0a656-2188-435a-8636-2ec0e6a096e2"
33
authors = ["Zachary P. Christensen <[email protected]>"]
4-
version = "0.1.3"
4+
version = "0.1.4"
55

66
[deps]
77
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"

lib/ArrayInterfaceCore/src/ArrayInterfaceCore.jl

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,15 @@ using SuiteSparse
1010
end
1111
_is_reshaped(::Type{<:Base.ReinterpretArray}) = false
1212

13-
@generated function merge_tuple_type(::Type{X}, ::Type{Y}) where {X<:Tuple,Y<:Tuple}
14-
Tuple{X.parameters...,Y.parameters...}
13+
@static if isdefined(Base, Symbol("@assume_effects"))
14+
using Base: @constprop
15+
else
16+
macro assume_effects(_, ex)
17+
Base.@pure ex
18+
end
1519
end
16-
Base.@pure __parameterless_type(T) = Base.typename(T).wrapper
20+
21+
@assume_effects :total __parameterless_type(T) = Base.typename(T).wrapper
1722
parameterless_type(x) = parameterless_type(typeof(x))
1823
parameterless_type(x::Type) = __parameterless_type(x)
1924

lib/ArrayInterfaceOffsetArrays/test/runtests.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,5 @@ o = OffsetArray(vec(A), 8);
2727
@test @inferred(ArrayInterface.device(OffsetArray(zeros(2,2,2),8,-2,-5))) === ArrayInterface.CPUPointer()
2828

2929
offset_view = @view OffsetArrays.centered(zeros(eltype(A), 5, 5))[:, begin]; # SubArray of OffsetArray
30-
@test @inferred(ArrayInterface.known_offsets(out)) == (-2,)
30+
@test @inferred(ArrayInterface.known_offsets(offset_view)) == (-2,)
3131

src/ArrayInterface.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ using ArrayInterfaceCore
44
import ArrayInterfaceCore: allowed_getindex, allowed_setindex!, aos_to_soa, buffer,
55
parent_type, fast_matrix_colors, findstructralnz, has_sparsestruct,
66
issingular, isstructured, matrix_colors, restructure, lu_instance,
7-
safevec, zeromatrix, ColoringAlgorithm, merge_tuple_type,
7+
safevec, zeromatrix, ColoringAlgorithm,
88
fast_scalar_indexing, parameterless_type, _is_reshaped, ndims_index, is_splat_index
99

1010
# ArrayIndex subtypes and methods
@@ -34,6 +34,10 @@ using LinearAlgebra
3434

3535
import Compat
3636

37+
@generated function merge_tuple_type(::Type{X}, ::Type{Y}) where {X<:Tuple,Y<:Tuple}
38+
Tuple{X.parameters...,Y.parameters...}
39+
end
40+
3741
const CanonicalInt = Union{Int,StaticInt}
3842
canonicalize(x::Integer) = Int(x)
3943
canonicalize(@nospecialize(x::StaticInt)) = x

src/axes.jl

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
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+
"""
18
@inline axes_types(x, dim) = axes_types(x, to_dims(x, dim))
29
@inline function axes_types(x, dim::StaticInt{D}) where {D}
310
if D > ndims(x)
@@ -77,6 +84,17 @@ end
7784
# conditionally typed (but inferrable) axes. It also means we can't depend on constant
7885
# propagation to preserve statically sized axes. This should probably be addressed before
7986
# 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+
"""
8098
@inline axes(A) = Base.axes(A)
8199
axes(A::ReshapedArray) = Base.axes(A)
82100
axes(A::PermutedDimsArray) = permute(axes(parent(A)), to_parent_dims(A))
@@ -261,6 +279,20 @@ end
261279

262280
Base.show(io::IO, x::LazyAxis{N}) where {N} = print(io, "LazyAxis{$N}($(parent(x))))")
263281

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))
264296
@generated function lazy_axes(x::X) where {X}
265297
Expr(:block, Expr(:meta, :inline), Expr(:tuple, [:(LazyAxis{$dim}(x)) for dim in 1:ndims(X)]...))
266298
end

src/broadcast.jl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,21 @@ struct BroadcastAxisDefault <: BroadcastAxis end
1010
BroadcastAxis(x) = BroadcastAxis(typeof(x))
1111
BroadcastAxis(::Type{T}) where {T} = BroadcastAxisDefault()
1212

13+
"""
14+
broadcast_axis(x, y)
15+
16+
Broadcast axis `x` and `y` into a common space. The resulting axis should be equal in length
17+
to both `x` and `y` unless one has a length of `1`, in which case the longest axis will be
18+
equal to the output.
19+
20+
```julia
21+
julia> ArrayInterface.broadcast_axis(1:10, 1:10)
22+
23+
julia> ArrayInterface.broadcast_axis(1:10, 1)
24+
1:10
25+
26+
```
27+
"""
1328
broadcast_axis(x, y) = broadcast_axis(BroadcastAxis(x), x, y)
1429
# stagger default broadcasting in case y has something other than default
1530
broadcast_axis(::BroadcastAxisDefault, x, y) = _broadcast_axis(BroadcastAxis(y), x, y)

0 commit comments

Comments
 (0)