Skip to content

Commit d88c230

Browse files
committed
Improved check_args, make some literals static for calls like axes, and bump compat requirements on VectorizationBase/ArrayInterface to force using their inference improvements.
1 parent c16af29 commit d88c230

File tree

3 files changed

+19
-24
lines changed

3 files changed

+19
-24
lines changed

Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ UnPack = "3a884ed6-31ef-47d7-9d2a-63182c4928ed"
1414
VectorizationBase = "3d5dd08c-fd9d-11e8-17fa-ed2836048c2f"
1515

1616
[compat]
17-
ArrayInterface = "2.14"
17+
ArrayInterface = "2.14.1"
1818
DocStringExtensions = "0.8"
1919
IfElse = "0.1"
2020
OffsetArrays = "1"
2121
SLEEFPirates = "0.6"
2222
UnPack = "0,1"
23-
VectorizationBase = "0.13"
23+
VectorizationBase = "0.13.2"
2424
julia = "1.5"
2525

2626
[extras]

src/condense_loopset.jl

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -255,28 +255,13 @@ It returns true for `AbstractArray{T}`s when `check_type(T) == true` and the arr
255255
To provide support for a custom array type, ensure that `check_args` returns true, either through overloading it or subtyping `DenseArray`.
256256
Additionally, define `pointer` and `stride` methods.
257257
"""
258-
@inline check_args(A::SubArray{T,N,P,I}) where {T,N,P,I<:Tuple{Vararg{Union{Int,Colon,AbstractRange}}}} = check_args(parent(A))
259-
@inline check_args(A::OffsetArray) = check_args(parent(A))
260-
@inline check_args(A::Adjoint) = check_args(parent(A))
261-
@inline check_args(A::Transpose) = check_args(parent(A))
262-
@inline check_args(A::PermutedDimsArray) = check_args(parent(A))
263-
@inline check_args(A::StridedArray) = check_type(eltype(A))
264-
@inline check_args(A::AbstractRange) = check_type(eltype(A))
265-
@inline check_args(A::BitVector) = true
266-
@inline check_args(A::BitMatrix) = true
267-
@inline function check_args(A::AbstractArray)
268-
M = parentmodule(typeof(A))
269-
if parent(A) === A # SparseMatrix, StaticArray, etc
270-
false
271-
elseif M === Base || M === Core || M ===LinearAlgebra
272-
# reshapes which aren't StridedArrays, plus UpperTriangular, etc.
273-
false
274-
else
275-
check_args(parent(A)) # PermutedDimsArray, NamedDimsArray
276-
end
258+
@inline function check_args(A::AbstractArray{T}) where {T}
259+
check_type(T) && ArrayInterface.device(A) === ArrayInterface.CPUPointer()
277260
end
278-
@inline check_args(A::VectorizationBase.AbstractStridedPointer{T}) where {T} = check_type(T)
279-
@inline check_args(A, Bs...) = check_args(A) && check_args(Bs...)
261+
@inline check_args(A::BitVector) = true
262+
@inline check_args(A::BitArray) = iszero(size(A,1) & 7)
263+
@inline check_args(_) = false
264+
@inline check_args(A, B, C::Vararg{Any,K}) where {K} = check_args(A) && check_args(B, C...)
280265
"""
281266
check_type(::Type{T}) where {T}
282267

src/graphs.jl

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,16 @@ function add_loop_bound!(ls::LoopSet, itersym::Symbol, bound, upper::Bool = true
458458
pushprepreamble!(ls, Expr(:(=), N, bound))
459459
N
460460
end
461+
function static_literals!(q::Expr)
462+
for (i,ex) enumerate(q.args)
463+
if ex isa Number
464+
q.args[i] = staticexpr(ex)
465+
elseif ex isa Expr
466+
static_literals!(ex)
467+
end
468+
end
469+
q
470+
end
461471

462472
"""
463473
This function creates a loop, while switching from 1 to 0 based indices
@@ -503,7 +513,7 @@ function register_single_loop!(ls::LoopSet, looprange::Expr)
503513
end
504514
else
505515
N = gensym("loop" * string(itersym))
506-
pushprepreamble!(ls, Expr(:(=), N, Expr(:call, lv(:maybestaticrange), r)))
516+
pushprepreamble!(ls, Expr(:(=), N, Expr(:call, lv(:maybestaticrange), static_literals!(r))))
507517
L = add_loop_bound!(ls, itersym, Expr(:call, lv(:maybestaticfirst), N), false)
508518
U = add_loop_bound!(ls, itersym, Expr(:call, lv(:maybestaticlast), N), true)
509519
Loop(itersym, L, U)

0 commit comments

Comments
 (0)