@@ -2,36 +2,43 @@ module ArrayInterface
22
33using ArrayInterfaceCore
44import ArrayInterfaceCore: allowed_getindex, allowed_setindex!, aos_to_soa, buffer,
5- parent_type, fast_matrix_colors, findstructralnz, has_sparsestruct,
6- issingular, isstructured, matrix_colors, restructure, lu_instance,
7- safevec, zeromatrix, undefmatrix, ColoringAlgorithm, fast_scalar_indexing, parameterless_type,
8- ndims_index, ndims_shape, is_splat_index, is_forwarding_wrapper, IndicesInfo, childdims,
9- parentdims, map_tuple_type, flatten_tuples, GetIndex, SetIndex!, defines_strides,
10- stride_preserving_index
5+ parent_type, fast_matrix_colors, findstructralnz,
6+ has_sparsestruct,
7+ issingular, isstructured, matrix_colors, restructure,
8+ lu_instance,
9+ safevec, zeromatrix, undefmatrix, ColoringAlgorithm,
10+ fast_scalar_indexing, parameterless_type,
11+ ndims_index, ndims_shape, is_splat_index, is_forwarding_wrapper,
12+ IndicesInfo, childdims,
13+ parentdims, map_tuple_type, flatten_tuples, GetIndex, SetIndex!,
14+ defines_strides,
15+ stride_preserving_index
1116
1217# ArrayIndex subtypes and methods
13- import ArrayInterfaceCore: ArrayIndex, MatrixIndex, VectorIndex, BidiagonalIndex, TridiagonalIndex
18+ import ArrayInterfaceCore: ArrayIndex, MatrixIndex, VectorIndex, BidiagonalIndex,
19+ TridiagonalIndex
1420# managing immutables
1521import ArrayInterfaceCore: ismutable, can_change_size, can_setindex
1622# constants
1723import ArrayInterfaceCore: MatAdjTrans, VecAdjTrans, UpTri, LoTri
1824# device pieces
1925import ArrayInterfaceCore: AbstractDevice, AbstractCPU, CPUPointer, CPUTuple, CheckParent,
20- CPUIndex, GPU, can_avx, device
26+ CPUIndex, GPU, can_avx, device
2127
2228import ArrayInterfaceCore: known_first, known_step, known_last
2329
2430using Static
2531using Static: Zero, One, nstatic, eq, ne, gt, ge, lt, le, eachop, eachop_tuple,
26- permute, invariant_permutation, field_type, reduce_tup, find_first_eq,
27- OptionallyStaticUnitRange, OptionallyStaticStepRange, OptionallyStaticRange, IntType,
28- SOneTo, SUnitRange
32+ permute, invariant_permutation, field_type, reduce_tup, find_first_eq,
33+ OptionallyStaticUnitRange, OptionallyStaticStepRange, OptionallyStaticRange,
34+ IntType,
35+ SOneTo, SUnitRange
2936
3037using IfElse
3138
3239using Base. Cartesian
3340using Base: @propagate_inbounds , tail, OneTo, LogicalIndex, Slice, ReinterpretArray,
34- ReshapedArray, AbstractCartesianIndex
41+ ReshapedArray, AbstractCartesianIndex
3542
3643using Base. Iterators: Pairs
3744using LinearAlgebra
@@ -41,11 +48,11 @@ import Compat
4148_add1 (@nospecialize x) = x + oneunit (x)
4249_sub1 (@nospecialize x) = x - oneunit (x)
4350
44- @generated function merge_tuple_type (:: Type{X} , :: Type{Y} ) where {X<: Tuple ,Y <: Tuple }
45- Tuple{X. parameters... ,Y. parameters... }
51+ @generated function merge_tuple_type (:: Type{X} , :: Type{Y} ) where {X <: Tuple , Y <: Tuple }
52+ Tuple{X. parameters... , Y. parameters... }
4653end
4754
48- abstract type AbstractArray2{T,N} <: AbstractArray{T,N} end
55+ abstract type AbstractArray2{T, N} <: AbstractArray{T, N} end
4956
5057Base. size (A:: AbstractArray2 ) = map (Int, ArrayInterface. size (A))
5158Base. size (A:: AbstractArray2 , dim) = Int (ArrayInterface. size (A, dim))
@@ -54,7 +61,7 @@ function Base.axes(A::AbstractArray2)
5461 is_forwarding_wrapper (A) && return ArrayInterface. axes (parent (A))
5562 throw (ArgumentError (" Subtypes of `AbstractArray2` must define an axes method" ))
5663end
57- function Base. axes (A:: AbstractArray2 , dim:: Union{Symbol,StaticSymbol} )
64+ function Base. axes (A:: AbstractArray2 , dim:: Union{Symbol, StaticSymbol} )
5865 axes (A, to_dims (A, dim))
5966end
6067
@@ -64,7 +71,7 @@ function Base.strides(A::AbstractArray2)
6471end
6572Base. strides (A:: AbstractArray2 , dim) = Int (ArrayInterface. strides (A, dim))
6673
67- function Base. IndexStyle (:: Type{T} ) where {T<: AbstractArray2 }
74+ function Base. IndexStyle (:: Type{T} ) where {T <: AbstractArray2 }
6875 is_forwarding_wrapper (T) ? IndexStyle (parent_type (T)) : IndexCartesian ()
6976end
7077
94101@inline function _to_cartesian (a, i:: IntType )
95102 @inbounds (CartesianIndices (ntuple (dim -> indices (a, dim), Val (ndims (a))))[i])
96103end
97- @inline function _to_linear (a, i:: Tuple{IntType,Vararg{IntType}} )
104+ @inline function _to_linear (a, i:: Tuple{IntType, Vararg{IntType}} )
98105 _strides2int (offsets (a), size_to_strides (size (a), static (1 )), i) + static (1 )
99106end
100107
@@ -106,7 +113,7 @@ Returns `static(true)` if `parent_type(T)` a type unique to `T`.
106113has_parent (x) = has_parent (typeof (x))
107114has_parent (:: Type{T} ) where {T} = _has_parent (parent_type (T), T)
108115_has_parent (:: Type{T} , :: Type{T} ) where {T} = False ()
109- _has_parent (:: Type{T1} , :: Type{T2} ) where {T1,T2} = True ()
116+ _has_parent (:: Type{T1} , :: Type{T2} ) where {T1, T2} = True ()
110117
111118"""
112119 is_lazy_conjugate(::AbstractArray) -> Bool
@@ -132,10 +139,10 @@ Examples
132139 False()
133140
134141"""
135- is_lazy_conjugate (:: T ) where {T<: AbstractArray } = _is_lazy_conjugate (T, False ())
142+ is_lazy_conjugate (:: T ) where {T <: AbstractArray } = _is_lazy_conjugate (T, False ())
136143is_lazy_conjugate (:: AbstractArray{<:Real} ) = False ()
137144
138- function _is_lazy_conjugate (:: Type{T} , isconj) where {T<: AbstractArray }
145+ function _is_lazy_conjugate (:: Type{T} , isconj) where {T <: AbstractArray }
139146 Tp = parent_type (T)
140147 if T != = Tp
141148 _is_lazy_conjugate (Tp, isconj)
@@ -144,7 +151,7 @@ function _is_lazy_conjugate(::Type{T}, isconj) where {T<:AbstractArray}
144151 end
145152end
146153
147- function _is_lazy_conjugate (:: Type{T} , isconj) where {T<: Adjoint }
154+ function _is_lazy_conjugate (:: Type{T} , isconj) where {T <: Adjoint }
148155 Tp = parent_type (T)
149156 if T != = Tp
150157 _is_lazy_conjugate (Tp, ! isconj)
@@ -161,17 +168,17 @@ Returns a new instance of `collection` with `item` inserted into at the given `i
161168Base. @propagate_inbounds function insert (collection, index, item)
162169 @boundscheck checkbounds (collection, index)
163170 ret = similar (collection, length (collection) + 1 )
164- @inbounds for i = firstindex (ret): (index- 1 )
171+ @inbounds for i in firstindex (ret): (index - 1 )
165172 ret[i] = collection[i]
166173 end
167174 @inbounds ret[index] = item
168- @inbounds for i = (index+ 1 ): lastindex (ret)
169- ret[i] = collection[i- 1 ]
175+ @inbounds for i in (index + 1 ): lastindex (ret)
176+ ret[i] = collection[i - 1 ]
170177 end
171178 return ret
172179end
173180
174- function insert (x:: Tuple{Vararg{Any,N}} , index, item) where {N}
181+ function insert (x:: Tuple{Vararg{Any, N}} , index, item) where {N}
175182 @boundscheck if ! checkindex (Bool, StaticInt {1} (): StaticInt {N} (), index)
176183 throw (BoundsError (x, index))
177184 end
@@ -197,7 +204,8 @@ Base.@propagate_inbounds function deleteat(collection::AbstractVector, index)
197204 end
198205 return unsafe_deleteat (collection, index)
199206end
200- Base. @propagate_inbounds function deleteat (collection:: Tuple{Vararg{Any,N}} , index) where {N}
207+ Base. @propagate_inbounds function deleteat (collection:: Tuple{Vararg{Any, N}} ,
208+ index) where {N}
201209 @boundscheck if ! checkindex (Bool, StaticInt {1} (): StaticInt {N} (), index)
202210 throw (BoundsError (collection, index))
203211 end
@@ -210,7 +218,7 @@ function unsafe_deleteat(src::AbstractVector, index)
210218 if i < index
211219 dst[i] = src[i]
212220 else
213- dst[i] = src[i+ 1 ]
221+ dst[i] = src[i + 1 ]
214222 end
215223 end
216224 return dst
241249end
242250
243251@inline unsafe_deleteat (x:: Tuple{T} , i) where {T} = ()
244- @inline unsafe_deleteat (x:: Tuple{T1,T2} , i) where {T1,T2} =
245- isone (i) ? (x[2 ],) : (x[1 ],)
252+ @inline unsafe_deleteat (x:: Tuple{T1, T2} , i) where {T1, T2} = isone (i) ? (x[2 ],) : (x[1 ],)
246253@inline function unsafe_deleteat (x:: Tuple , i)
247254 if i === one (i)
248255 return tail (x)
@@ -262,4 +269,14 @@ include("indexing.jl")
262269include (" stridelayout.jl" )
263270include (" broadcast.jl" )
264271
272+ using SnoopPrecompile
273+ @precompile_setup begin
274+ # Putting some things in `setup` can reduce the size of the
275+ # precompile file and potentially make loading faster.
276+ arrays = [rand (4 ), Base. oneto (5 )]
277+ @precompile_all_calls begin for x in arrays
278+ known_size (x)
279+ known_length (x)
280+ end end
281+ end
265282end
0 commit comments