Skip to content

Commit 60c20b3

Browse files
move more static over
1 parent 8af091c commit 60c20b3

File tree

2 files changed

+29
-26
lines changed

2 files changed

+29
-26
lines changed

lib/ArrayInterfaceCore/src/ArrayInterfaceCore.jl

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -356,32 +356,6 @@ struct CheckParent end
356356
struct CPUIndex <: AbstractCPU end
357357
struct GPU <: AbstractDevice end
358358

359-
"""
360-
device(::Type{T}) -> AbstractDevice
361-
362-
Indicates the most efficient way to access elements from the collection in low-level code.
363-
For `GPUArrays`, will return `ArrayInterfaceCore.GPU()`.
364-
For `AbstractArray` supporting a `pointer` method, returns `ArrayInterfaceCore.CPUPointer()`.
365-
For other `AbstractArray`s and `Tuple`s, returns `ArrayInterfaceCore.CPUIndex()`.
366-
Otherwise, returns `nothing`.
367-
"""
368-
device(A) = device(typeof(A))
369-
device(::Type) = nothing
370-
device(::Type{<:Tuple}) = CPUTuple()
371-
device(::Type{T}) where {T<:Array} = CPUPointer()
372-
device(::Type{T}) where {T<:AbstractArray} = _device(has_parent(T), T)
373-
function _device(::True, ::Type{T}) where {T}
374-
if defines_strides(T)
375-
return device(parent_type(T))
376-
else
377-
return _not_pointer(device(parent_type(T)))
378-
end
379-
end
380-
_not_pointer(::CPUPointer) = CPUIndex()
381-
_not_pointer(x) = x
382-
_device(::False, ::Type{T}) where {T<:DenseArray} = CPUPointer()
383-
_device(::False, ::Type{T}) where {T} = CPUIndex()
384-
385359
"""
386360
can_avx(f) -> Bool
387361

src/ArrayInterface.jl

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ import ArrayInterfaceCore: ArrayIndex, MatrixIndex, VectorIndex, BidiagonalIndex
1212
import ArrayInterfaceCore: ismutable, can_change_size, can_setindex, deleteat, insert
1313
# constants
1414
import ArrayInterfaceCore: MatAdjTrans, VecAdjTrans, UpTri, LoTri
15+
#
16+
import ArrayInterfaceCore: AbstractDevice, AbstractCPU, CPUPointer, CPUTuple, CheckParent,
17+
CPUIndex, GPU
1518

1619
using Static
1720
using Static: Zero, One, nstatic, eq, ne, gt, ge, lt, le, eachop, eachop_tuple,
@@ -71,6 +74,32 @@ end
7174
@inline static_last(x) = Static.maybe_static(known_last, last, x)
7275
@inline static_step(x) = Static.maybe_static(known_step, step, x)
7376

77+
"""
78+
device(::Type{T}) -> AbstractDevice
79+
80+
Indicates the most efficient way to access elements from the collection in low-level code.
81+
For `GPUArrays`, will return `ArrayInterfaceCore.GPU()`.
82+
For `AbstractArray` supporting a `pointer` method, returns `ArrayInterfaceCore.CPUPointer()`.
83+
For other `AbstractArray`s and `Tuple`s, returns `ArrayInterfaceCore.CPUIndex()`.
84+
Otherwise, returns `nothing`.
85+
"""
86+
device(A) = device(typeof(A))
87+
device(::Type) = nothing
88+
device(::Type{<:Tuple}) = CPUTuple()
89+
device(::Type{T}) where {T<:Array} = CPUPointer()
90+
device(::Type{T}) where {T<:AbstractArray} = _device(has_parent(T), T)
91+
function _device(::True, ::Type{T}) where {T}
92+
if defines_strides(T)
93+
return device(parent_type(T))
94+
else
95+
return _not_pointer(device(parent_type(T)))
96+
end
97+
end
98+
_not_pointer(::CPUPointer) = CPUIndex()
99+
_not_pointer(x) = x
100+
_device(::False, ::Type{T}) where {T<:DenseArray} = CPUPointer()
101+
_device(::False, ::Type{T}) where {T} = CPUIndex()
102+
74103
include("array_index.jl")
75104
include("axes.jl")
76105
include("broadcast.jl")

0 commit comments

Comments
 (0)