@@ -2,36 +2,43 @@ module ArrayInterface
2
2
3
3
using ArrayInterfaceCore
4
4
import 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
11
16
12
17
# ArrayIndex subtypes and methods
13
- import ArrayInterfaceCore: ArrayIndex, MatrixIndex, VectorIndex, BidiagonalIndex, TridiagonalIndex
18
+ import ArrayInterfaceCore: ArrayIndex, MatrixIndex, VectorIndex, BidiagonalIndex,
19
+ TridiagonalIndex
14
20
# managing immutables
15
21
import ArrayInterfaceCore: ismutable, can_change_size, can_setindex
16
22
# constants
17
23
import ArrayInterfaceCore: MatAdjTrans, VecAdjTrans, UpTri, LoTri
18
24
# device pieces
19
25
import ArrayInterfaceCore: AbstractDevice, AbstractCPU, CPUPointer, CPUTuple, CheckParent,
20
- CPUIndex, GPU, can_avx, device
26
+ CPUIndex, GPU, can_avx, device
21
27
22
28
import ArrayInterfaceCore: known_first, known_step, known_last
23
29
24
30
using Static
25
31
using 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
29
36
30
37
using IfElse
31
38
32
39
using Base. Cartesian
33
40
using Base: @propagate_inbounds , tail, OneTo, LogicalIndex, Slice, ReinterpretArray,
34
- ReshapedArray, AbstractCartesianIndex
41
+ ReshapedArray, AbstractCartesianIndex
35
42
36
43
using Base. Iterators: Pairs
37
44
using LinearAlgebra
@@ -41,11 +48,11 @@ import Compat
41
48
_add1 (@nospecialize x) = x + oneunit (x)
42
49
_sub1 (@nospecialize x) = x - oneunit (x)
43
50
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... }
46
53
end
47
54
48
- abstract type AbstractArray2{T,N} <: AbstractArray{T,N} end
55
+ abstract type AbstractArray2{T, N} <: AbstractArray{T, N} end
49
56
50
57
Base. size (A:: AbstractArray2 ) = map (Int, ArrayInterface. size (A))
51
58
Base. size (A:: AbstractArray2 , dim) = Int (ArrayInterface. size (A, dim))
@@ -54,7 +61,7 @@ function Base.axes(A::AbstractArray2)
54
61
is_forwarding_wrapper (A) && return ArrayInterface. axes (parent (A))
55
62
throw (ArgumentError (" Subtypes of `AbstractArray2` must define an axes method" ))
56
63
end
57
- function Base. axes (A:: AbstractArray2 , dim:: Union{Symbol,StaticSymbol} )
64
+ function Base. axes (A:: AbstractArray2 , dim:: Union{Symbol, StaticSymbol} )
58
65
axes (A, to_dims (A, dim))
59
66
end
60
67
@@ -64,7 +71,7 @@ function Base.strides(A::AbstractArray2)
64
71
end
65
72
Base. strides (A:: AbstractArray2 , dim) = Int (ArrayInterface. strides (A, dim))
66
73
67
- function Base. IndexStyle (:: Type{T} ) where {T<: AbstractArray2 }
74
+ function Base. IndexStyle (:: Type{T} ) where {T <: AbstractArray2 }
68
75
is_forwarding_wrapper (T) ? IndexStyle (parent_type (T)) : IndexCartesian ()
69
76
end
70
77
94
101
@inline function _to_cartesian (a, i:: IntType )
95
102
@inbounds (CartesianIndices (ntuple (dim -> indices (a, dim), Val (ndims (a))))[i])
96
103
end
97
- @inline function _to_linear (a, i:: Tuple{IntType,Vararg{IntType}} )
104
+ @inline function _to_linear (a, i:: Tuple{IntType, Vararg{IntType}} )
98
105
_strides2int (offsets (a), size_to_strides (size (a), static (1 )), i) + static (1 )
99
106
end
100
107
@@ -106,7 +113,7 @@ Returns `static(true)` if `parent_type(T)` a type unique to `T`.
106
113
has_parent (x) = has_parent (typeof (x))
107
114
has_parent (:: Type{T} ) where {T} = _has_parent (parent_type (T), T)
108
115
_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 ()
110
117
111
118
"""
112
119
is_lazy_conjugate(::AbstractArray) -> Bool
@@ -132,10 +139,10 @@ Examples
132
139
False()
133
140
134
141
"""
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 ())
136
143
is_lazy_conjugate (:: AbstractArray{<:Real} ) = False ()
137
144
138
- function _is_lazy_conjugate (:: Type{T} , isconj) where {T<: AbstractArray }
145
+ function _is_lazy_conjugate (:: Type{T} , isconj) where {T <: AbstractArray }
139
146
Tp = parent_type (T)
140
147
if T != = Tp
141
148
_is_lazy_conjugate (Tp, isconj)
@@ -144,7 +151,7 @@ function _is_lazy_conjugate(::Type{T}, isconj) where {T<:AbstractArray}
144
151
end
145
152
end
146
153
147
- function _is_lazy_conjugate (:: Type{T} , isconj) where {T<: Adjoint }
154
+ function _is_lazy_conjugate (:: Type{T} , isconj) where {T <: Adjoint }
148
155
Tp = parent_type (T)
149
156
if T != = Tp
150
157
_is_lazy_conjugate (Tp, ! isconj)
@@ -161,17 +168,17 @@ Returns a new instance of `collection` with `item` inserted into at the given `i
161
168
Base. @propagate_inbounds function insert (collection, index, item)
162
169
@boundscheck checkbounds (collection, index)
163
170
ret = similar (collection, length (collection) + 1 )
164
- @inbounds for i = firstindex (ret): (index- 1 )
171
+ @inbounds for i in firstindex (ret): (index - 1 )
165
172
ret[i] = collection[i]
166
173
end
167
174
@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 ]
170
177
end
171
178
return ret
172
179
end
173
180
174
- function insert (x:: Tuple{Vararg{Any,N}} , index, item) where {N}
181
+ function insert (x:: Tuple{Vararg{Any, N}} , index, item) where {N}
175
182
@boundscheck if ! checkindex (Bool, StaticInt {1} (): StaticInt {N} (), index)
176
183
throw (BoundsError (x, index))
177
184
end
@@ -197,7 +204,8 @@ Base.@propagate_inbounds function deleteat(collection::AbstractVector, index)
197
204
end
198
205
return unsafe_deleteat (collection, index)
199
206
end
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}
201
209
@boundscheck if ! checkindex (Bool, StaticInt {1} (): StaticInt {N} (), index)
202
210
throw (BoundsError (collection, index))
203
211
end
@@ -210,7 +218,7 @@ function unsafe_deleteat(src::AbstractVector, index)
210
218
if i < index
211
219
dst[i] = src[i]
212
220
else
213
- dst[i] = src[i+ 1 ]
221
+ dst[i] = src[i + 1 ]
214
222
end
215
223
end
216
224
return dst
241
249
end
242
250
243
251
@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 ],)
246
253
@inline function unsafe_deleteat (x:: Tuple , i)
247
254
if i === one (i)
248
255
return tail (x)
@@ -262,4 +269,14 @@ include("indexing.jl")
262
269
include (" stridelayout.jl" )
263
270
include (" broadcast.jl" )
264
271
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
265
282
end
0 commit comments