Skip to content

Commit b572dc1

Browse files
authored
More documentation organization + fix offset1 mess. (#190)
* Separate API traits in docs * Fix offset1 and simplify OffsetArrays code * Resolve deprecation of qr(A, Val(true)) * Remove dead code * version bump * test qr differently on v1.7
1 parent d57f72d commit b572dc1

File tree

9 files changed

+116
-51
lines changed

9 files changed

+116
-51
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 = "3.1.23"
3+
version = "3.1.24"
44

55
[deps]
66
IfElse = "615f187c-cbe4-4ef1-ba3b-2fcf58d6d173"

docs/make.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ makedocs(;
66
sitename="ArrayInterface",
77
pages=[
88
"Home" => "index.md",
9+
"API" => "api.md"
910
],
1011
)
1112

docs/src/api.md

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# API
2+
3+
## Traits
4+
5+
```@docs
6+
ArrayInterface.can_avx
7+
ArrayInterface.can_change_size
8+
ArrayInterface.can_setindex
9+
ArrayInterface.contiguous_axis
10+
ArrayInterface.contiguous_axis_indicator
11+
ArrayInterface.contiguous_batch_size
12+
ArrayInterface.defines_strides
13+
ArrayInterface.device
14+
ArrayInterface.dimnames
15+
ArrayInterface.fast_matrix_colors
16+
ArrayInterface.fast_scalar_indexing
17+
ArrayInterface.has_dimnames
18+
ArrayInterface.has_parent
19+
ArrayInterface.has_sparsestruct
20+
ArrayInterface.is_canonical
21+
ArrayInterface.is_column_major
22+
ArrayInterface.is_lazy_conjugate
23+
ArrayInterface.ismutable
24+
ArrayInterface.issingular
25+
ArrayInterface.isstructured
26+
ArrayInterface.known_first
27+
ArrayInterface.known_last
28+
ArrayInterface.known_length
29+
ArrayInterface.known_offset1
30+
ArrayInterface.known_offsets
31+
ArrayInterface.known_size
32+
ArrayInterface.known_step
33+
ArrayInterface.known_strides
34+
```
35+
36+
## Functions
37+
38+
```@docs
39+
ArrayInterface.allowed_getindex
40+
ArrayInterface.allowed_setindex!
41+
ArrayInterface.aos_to_soa
42+
ArrayInterface.axes
43+
ArrayInterface.axes_types
44+
ArrayInterface.broadcast_axis
45+
ArrayInterface.canonicalize
46+
ArrayInterface.deleteat
47+
ArrayInterface.dense_dims
48+
ArrayInterface.findstructralnz
49+
ArrayInterface.from_parent_dims
50+
ArrayInterface.getindex
51+
ArrayInterface.indices
52+
ArrayInterface.insert
53+
ArrayInterface.lazy_axes
54+
ArrayInterface.lu_instance
55+
ArrayInterface.matrix_colors
56+
ArrayInterface.offset1
57+
ArrayInterface.offsets
58+
ArrayInterface.parent_type
59+
ArrayInterface.reduce_tup
60+
ArrayInterface.restructure
61+
ArrayInterface.safevec
62+
ArrayInterface.setindex!
63+
ArrayInterface.size
64+
ArrayInterface.strides
65+
ArrayInterface.to_axes
66+
ArrayInterface.to_axis
67+
ArrayInterface.to_dims
68+
ArrayInterface.to_index
69+
ArrayInterface.to_indices
70+
ArrayInterface.to_parent_dims
71+
ArrayInterface.unsafe_reconstruct
72+
ArrayInterface.zeromatrix
73+
```
74+
75+
## Types
76+
77+
```@docs
78+
ArrayInterface.ArrayIndex
79+
ArrayInterface.BroadcastAxis
80+
ArrayInterface.LazyAxis
81+
ArrayInterface.OptionallyStaticStepRange
82+
ArrayInterface.OptionallyStaticUnitRange
83+
ArrayInterface.StrideIndex
84+
```
85+

docs/src/index.md

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,3 @@ f(x, dim::StaticInt) = ...
9393
If `x`'s first dimension is named `:dim_1` then calling `f(x, :dim_1)` would result in `f(x, 1)`.
9494
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.
9595

96-
## API
97-
98-
```@index
99-
```
100-
101-
```@autodocs
102-
Modules = [ArrayInterface]
103-
```
104-

src/ArrayInterface.jl

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -915,35 +915,16 @@ function __init__()
915915
end
916916
end
917917
@require OffsetArrays = "6fe1bfb0-de20-5000-8ca7-80f57d26f881" begin
918-
size(A::OffsetArrays.OffsetArray) = size(parent(A))
919-
strides(A::OffsetArrays.OffsetArray) = strides(parent(A))
920-
function parent_type(
921-
::Type{O},
922-
) where {T,N,A<:AbstractArray{T,N},O<:OffsetArrays.OffsetArray{T,N,A}}
923-
return A
924-
end
925-
device(::Type{A}) where {A<:OffsetArrays.OffsetArray} = device(parent_type(A))
926-
function contiguous_axis(::Type{A}) where {A<:OffsetArrays.OffsetArray}
927-
return contiguous_axis(parent_type(A))
928-
end
929-
function contiguous_batch_size(::Type{A}) where {A<:OffsetArrays.OffsetArray}
930-
return contiguous_batch_size(parent_type(A))
931-
end
932-
918+
parent_type(::Type{O}) where {T,N,A<:AbstractArray{T,N},O<:OffsetArrays.OffsetArray{T,N,A}} = A
933919
function _offset_axis_type(::Type{T}, dim::StaticInt{D}) where {T,D}
934-
return OffsetArrays.IdOffsetRange{Int,ArrayInterface.axes_types(T, dim)}
920+
OffsetArrays.IdOffsetRange{Int,ArrayInterface.axes_types(T, dim)}
935921
end
936922
function ArrayInterface.axes_types(::Type{T}) where {T<:OffsetArrays.OffsetArray}
937-
return Static.eachop_tuple(_offset_axis_type, Static.nstatic(Val(ndims(T))), ArrayInterface.parent_type(T))
938-
end
939-
function stride_rank(::Type{A}) where {A<:OffsetArrays.OffsetArray}
940-
return stride_rank(parent_type(A))
923+
Static.eachop_tuple(_offset_axis_type, Static.nstatic(Val(ndims(T))), ArrayInterface.parent_type(T))
941924
end
942925
@inline axes(A::OffsetArrays.OffsetArray) = Base.axes(A)
943926
@inline _axes(A::OffsetArrays.OffsetArray, dim::Integer) = Base.axes(A, dim)
944927
@inline axes(A::OffsetArrays.OffsetArray{T,N}, ::StaticInt{M}) where {T,M,N} = _axes(A, StaticInt{M}(), gt(StaticInt{M}(),StaticInt{N}()))
945-
@inline known_offset1(::Type{<:OffsetArrays.OffsetArray}) = 1
946-
@inline known_offset1(::Type{<:OffsetArrays.OffsetVector}) = nothing
947928
end
948929
end
949930

src/array_index.jl

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -189,16 +189,15 @@ end
189189
Subtype of `ArrayIndex` that transforms and index using stride layout information
190190
derived from `x`.
191191
"""
192-
struct StrideIndex{N,R,C,S,O,O1} <: ArrayIndex{N}
192+
struct StrideIndex{N,R,C,S,O} <: ArrayIndex{N}
193193
strides::S
194194
offsets::O
195-
offset1::O1
196195

197-
function StrideIndex{N,R,C}(s::S, o::O, o1::O1) where {N,R,C,S,O,O1}
198-
return new{N,R::NTuple{N,Int},C::Int,S,O,O1}(s, o, o1)
196+
function StrideIndex{N,R,C}(s::S, o::O) where {N,R,C,S,O}
197+
return new{N,R::NTuple{N,Int},C::Int,S,O}(s, o)
199198
end
200199
function StrideIndex{N,R,C}(a::A) where {N,R,C,A}
201-
return StrideIndex{N,R,C}(strides(a),offsets(a),offset1(a))
200+
return StrideIndex{N,R,C}(strides(a), offsets(a))
202201
end
203202
function StrideIndex(a::A) where {A}
204203
return StrideIndex{ndims(A),known(stride_rank(A)), known(contiguous_axis(A))}(a)

src/indexing.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ function to_index(::IndexLinear, x, arg::AbstractCartesianIndex{N}) where {N}
145145
inds = Tuple(arg)
146146
o = offsets(x)
147147
s = size(x)
148-
return first(inds) + (offset1(x) - first(o)) + _subs2int(first(s), tail(s), tail(o), tail(inds))
148+
return first(inds) + (static(1) - first(o)) + _subs2int(first(s), tail(s), tail(o), tail(inds))
149149
end
150150
@inline function _subs2int(stride, s::Tuple{Any,Vararg}, o::Tuple{Any,Vararg}, inds::Tuple{Any,Vararg})
151151
i = ((first(inds) - first(o)) * stride)
@@ -215,7 +215,7 @@ end
215215
@boundscheck checkbounds(x, arg)
216216
return LogicalIndex{Int}(arg)
217217
end
218-
to_index(::IndexCartesian, x, i::Integer) = NDIndex(_int2subs(offsets(x), size(x), i - offset1(x)))
218+
to_index(::IndexCartesian, x, i::Integer) = NDIndex(_int2subs(offsets(x), size(x), i - static(1)))
219219
@inline function _int2subs(o::Tuple{Any,Vararg{Any}}, s::Tuple{Any,Vararg{Any}}, i)
220220
len = first(s)
221221
inext = div(i, len)

src/stridelayout.jl

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ function known_offsets(::Type{T}) where {T}
4242
end
4343
_known_offsets(::Type{T}, dim::StaticInt) where {T} = known_first(_get_tuple(T, dim))
4444

45-
known_offsets(::Type{<:StrideIndex{N,R,C,S,O,O1}}) where {N,R,C,S,O,O1} = known(O)
45+
known_offsets(::Type{<:StrideIndex{N,R,C,S,O}}) where {N,R,C,S,O} = known(O)
4646

4747
"""
4848
offsets(A) -> Tuple
@@ -70,11 +70,14 @@ end
7070
7171
Returns the linear offset of array `x` if known at compile time.
7272
"""
73-
known_offset1(x) = known_offset1(typeof(x))
74-
known_offset1(::Type{T}) where {T} = _known_offset1(has_parent(T), T)
75-
_known_offset1(::True, ::Type{T}) where {T} = known_offset1(parent_type(T))
76-
_known_offset1(::False, ::Type{T}) where {T} = 1
77-
known_offset(::Type{<:StrideIndex{N,R,C,S,O,O1}}) where {N,R,C,S,O,O1} = known(O1)
73+
@inline known_offset1(x) = known_offset1(typeof(x))
74+
@inline function known_offset1(::Type{T}) where {T}
75+
if ndims(T) === 0
76+
return 1
77+
else
78+
return known_offsets(T, 1)
79+
end
80+
end
7881

7982
"""
8083
offset1(x) -> Union{Int,StaticInt}
@@ -84,12 +87,15 @@ Returns the offset of the linear indices for `x`.
8487
@inline function offset1(x::X) where {X}
8588
o1 = known_offset1(X)
8689
if o1 === nothing
87-
return firstindex(x)
90+
if ndims(X) === 0
91+
return 1
92+
else
93+
return offsets(x, 1)
94+
end
8895
else
8996
return static(o1)
9097
end
9198
end
92-
offset1(x::StrideIndex) = getfield(x, :offset1)
9399

94100
"""
95101
contiguous_axis(::Type{T}) -> StaticInt{N}
@@ -442,7 +448,7 @@ function known_strides(::Type{T}, dim::Integer) where {T}
442448
return known_strides(T)[dim]
443449
end
444450
end
445-
known_strides(::Type{<:StrideIndex{N,R,C,S,O,O1}}) where {N,R,C,S,O,O1} = known(S)
451+
known_strides(::Type{<:StrideIndex{N,R,C,S,O}}) where {N,R,C,S,O} = known(S)
446452

447453
known_strides(x) = known_strides(typeof(x))
448454
known_strides(::Type{T}) where {T<:Vector} = (1,)

test/runtests.jl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,11 @@ rowind,colind=findstructralnz(Sp)
5353

5454

5555
@test !fast_scalar_indexing(qr(rand(10, 10)).Q)
56-
@test !fast_scalar_indexing(qr(rand(10, 10), Val(true)).Q)
56+
if VERSION >= v"1.7"
57+
@test !fast_scalar_indexing(qr(rand(10, 10), ColumnNorm()).Q)
58+
else
59+
@test !fast_scalar_indexing(qr(rand(10, 10), Val(true)).Q)
60+
end
5761
@test !fast_scalar_indexing(lq(rand(10, 10)).Q)
5862

5963
using BandedMatrices
@@ -682,8 +686,6 @@ end
682686
@test @inferred(ArrayInterface.offsets(Op)) === (11, 4, 8)
683687

684688
@test @inferred(ArrayInterface.offsets((1,2,3))) === (StaticInt(1),)
685-
@test @inferred(ArrayInterface.offset1(O)) === StaticInt(1)
686-
@test @inferred(ArrayInterface.offset1(Op)) === StaticInt(1)
687689
o = OffsetArray(vec(A), 8);
688690
@test @inferred(ArrayInterface.offset1(o)) === 9
689691

0 commit comments

Comments
 (0)