Skip to content

Commit 142345a

Browse files
committed
Improve inferability of offsets by using StaticInt for indices. Resolves #92
1 parent 99d0e49 commit 142345a

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
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 = "2.14.0"
3+
version = "2.14.1"
44

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

src/dimensions.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -151,22 +151,22 @@ julia> ArrayInterface.size(A)
151151
(StaticInt{3}(), StaticInt{4}())
152152
```
153153
"""
154-
size(A) = Base.size(A)
155-
size(A, d) = Base.size(A, to_dims(A, d))
156-
size(x::LinearAlgebra.Adjoint{T,V}) where {T, V <: AbstractVector{T}} = (One(), static_length(x))
157-
size(x::LinearAlgebra.Transpose{T,V}) where {T, V <: AbstractVector{T}} = (One(), static_length(x))
154+
@inline size(A) = Base.size(A)
155+
@inline size(A, d) = Base.size(A, to_dims(A, d))
156+
@inline size(x::LinearAlgebra.Adjoint{T,V}) where {T, V <: AbstractVector{T}} = (One(), static_length(x))
157+
@inline size(x::LinearAlgebra.Transpose{T,V}) where {T, V <: AbstractVector{T}} = (One(), static_length(x))
158158

159159
"""
160160
axes(A, d)
161161
162162
Return a valid range that maps to each index along dimension `d` of `A`.
163163
"""
164-
axes(A, d) = Base.axes(A, to_dims(A, d))
164+
@inline axes(A, d) = Base.axes(A, to_dims(A, d))
165165

166166
"""
167167
axes(A)
168168
169169
Return a tuple of ranges where each range maps to each element along a dimension of `A`.
170170
"""
171-
axes(A) = Base.axes(A)
171+
@inline axes(A) = Base.axes(A)
172172

src/stridelayout.jl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -337,10 +337,11 @@ end
337337
# @inline offsets(A::AbstractArray{<:Any,N}) where {N} = ntuple(n -> offsets(A, n), Val{N}())
338338
# Explicit tuple needed for inference.
339339
@generated function offsets(A::AbstractArray{<:Any,N}) where {N}
340-
quote
341-
$(Expr(:meta, :inline))
342-
Base.Cartesian.@ntuple $N n -> offsets(A, n)
340+
t = Expr(:tuple)
341+
for n 1:N
342+
push!(t.args, :(offsets(A, StaticInt{$n}())))
343343
end
344+
Expr(:block, Expr(:meta, :inline), t)
344345
end
345346

346347
@inline size(B::Union{Transpose{T,A},Adjoint{T,A}}) where {T,A<:AbstractMatrix{T}} = permute(size(parent(B)), Val{(2,1)}())

0 commit comments

Comments
 (0)