@@ -16,7 +16,7 @@ import ArrayInterface: allowed_getindex, allowed_setindex!, aos_to_soa, buffer,
1616
1717# ArrayIndex subtypes and methods
1818import ArrayInterface: ArrayIndex, MatrixIndex, VectorIndex, BidiagonalIndex,
19- TridiagonalIndex
19+ TridiagonalIndex, StrideIndex
2020# managing immutables
2121import ArrayInterface: ismutable, can_change_size, can_setindex
2222# constants
@@ -27,6 +27,11 @@ import ArrayInterface: AbstractDevice, AbstractCPU, CPUPointer, CPUTuple, CheckP
2727
2828import ArrayInterface: known_first, known_step, known_last
2929
30+ import ArrayInterface: offsets, axes_types, offset1, indices, known_offsets, stride_rank, strides, dense_dims, contiguous_axis, known_length, contiguous_batch_size,
31+ contiguous_axis_indicator, is_column_major, _all_dense, AbstractArray2, dimnames, known_dimnames, known_offset1, known_strides, LazyAxis, lazy_axes, BroadcastAxis, broadcast_axis,
32+ to_axes, find_all_dimnames, to_dims, known_size, deleteat, insert, static_size, is_lazy_conjugate, static_stride, static_strides, has_dimnames, unsafe_reconstruct, static_to_indices,
33+ to_index, unsafe_setindex!, unsafe_getindex, static_axes, to_axis, is_dense, static_getindex
34+
3035using Static
3136using Static: Zero, One, nstatic, eq, ne, gt, ge, lt, le, eachop, eachop_tuple,
3237 permute, invariant_permutation, field_type, reduce_tup, find_first_eq,
@@ -52,24 +57,22 @@ _sub1(@nospecialize x) = x - oneunit(x)
5257 Tuple{X. parameters... , Y. parameters... }
5358end
5459
55- abstract type AbstractArray2{T, N} <: AbstractArray{T, N} end
56-
57- Base. size (A:: AbstractArray2 ) = map (Int, ArrayInterface. size (A))
58- Base. size (A:: AbstractArray2 , dim) = Int (ArrayInterface. size (A, dim))
60+ Base. size (A:: AbstractArray2 ) = map (Int, ArrayInterface. static_size (A))
61+ Base. size (A:: AbstractArray2 , dim) = Int (ArrayInterface. static_size (A, dim))
5962
6063function Base. axes (A:: AbstractArray2 )
61- is_forwarding_wrapper (A) && return ArrayInterface. axes (parent (A))
64+ is_forwarding_wrapper (A) && return ArrayInterface. static_axes (parent (A))
6265 throw (ArgumentError (" Subtypes of `AbstractArray2` must define an axes method" ))
6366end
6467function Base. axes (A:: AbstractArray2 , dim:: Union{Symbol, StaticSymbol} )
65- axes (A, to_dims (A, dim))
68+ static_axes (A, to_dims (A, dim))
6669end
6770
6871function Base. strides (A:: AbstractArray2 )
69- defines_strides (A) && return map (Int, ArrayInterface. strides (A))
72+ defines_strides (A) && return map (Int, ArrayInterface. static_strides (A))
7073 throw (MethodError (Base. strides, (A,)))
7174end
72- Base. strides (A:: AbstractArray2 , dim) = Int (ArrayInterface. strides (A, dim))
75+ Base. strides (A:: AbstractArray2 , dim) = Int (ArrayInterface. static_strides (A, dim))
7376
7477function Base. IndexStyle (:: Type{T} ) where {T <: AbstractArray2 }
7578 is_forwarding_wrapper (T) ? IndexStyle (parent_type (T)) : IndexCartesian ()
7881function Base. length (A:: AbstractArray2 )
7982 len = known_length (A)
8083 if len === nothing
81- return Int (prod (size (A)))
84+ return Int (prod (static_size (A)))
8285 else
8386 return Int (len)
8487 end
8588end
8689
87- @propagate_inbounds Base. getindex (A:: AbstractArray2 , args... ) = getindex (A, args... )
88- @propagate_inbounds Base. getindex (A:: AbstractArray2 ; kwargs... ) = getindex (A; kwargs... )
90+ @propagate_inbounds Base. getindex (A:: AbstractArray2 , args... ) = static_getindex (A, args... )
91+ @propagate_inbounds Base. getindex (A:: AbstractArray2 ; kwargs... ) = static_getindex (A; kwargs... )
8992
9093@propagate_inbounds function Base. setindex! (A:: AbstractArray2 , val, args... )
9194 return setindex! (A, val, args... )
102105 @inbounds (CartesianIndices (ntuple (dim -> indices (a, dim), Val (ndims (a))))[i])
103106end
104107@inline function _to_linear (a, i:: Tuple{IntType, Vararg{IntType}} )
105- _strides2int (offsets (a), size_to_strides (size (a), static (1 )), i) + static (1 )
108+ _strides2int (offsets (a), size_to_strides (static_size (a), static (1 )), i) + static (1 )
106109end
107110
108111"""
@@ -167,7 +170,7 @@ Returns a new instance of `collection` with `item` inserted into at the given `i
167170"""
168171Base. @propagate_inbounds function insert (collection, index, item)
169172 @boundscheck checkbounds (collection, index)
170- ret = similar (collection, length (collection) + 1 )
173+ ret = similar (collection, static_length (collection) + 1 )
171174 @inbounds for i in firstindex (ret): (index - 1 )
172175 ret[i] = collection[i]
173176 end
@@ -213,7 +216,7 @@ Base.@propagate_inbounds function deleteat(collection::Tuple{Vararg{Any, N}},
213216end
214217
215218function unsafe_deleteat (src:: AbstractVector , index)
216- dst = similar (src, length (src) - 1 )
219+ dst = similar (src, static_length (src) - 1 )
217220 @inbounds for i in indices (dst)
218221 if i < index
219222 dst[i] = src[i]
@@ -225,7 +228,7 @@ function unsafe_deleteat(src::AbstractVector, index)
225228end
226229
227230@inline function unsafe_deleteat (src:: AbstractVector , inds:: AbstractVector )
228- dst = similar (src, length (src) - length (inds))
231+ dst = similar (src, static_length (src) - static_length (inds))
229232 dst_index = firstindex (dst)
230233 @inbounds for src_index in indices (src)
231234 if ! in (src_index, inds)
237240end
238241
239242@inline function unsafe_deleteat (src:: Tuple , inds:: AbstractVector )
240- dst = Vector {eltype(src)} (undef, length (src) - length (inds))
243+ dst = Vector {eltype(src)} (undef, static_length (src) - static_length (inds))
241244 dst_index = firstindex (dst)
242- @inbounds for src_index in static (1 ): length (src)
245+ @inbounds for src_index in static (1 ): static_length (src)
243246 if ! in (src_index, inds)
244247 dst[dst_index] = src[src_index]
245248 dst_index += one (dst_index)
253256@inline function unsafe_deleteat (x:: Tuple , i)
254257 if i === one (i)
255258 return tail (x)
256- elseif i == length (x)
259+ elseif i == static_length (x)
257260 return Base. front (x)
258261 else
259262 return (first (x), unsafe_deleteat (tail (x), i - one (i))... )
0 commit comments