|
1 | 1 | module ArrayLayouts |
2 | 2 | using Base: _typed_hcat |
3 | 3 | using Base, Base.Broadcast, LinearAlgebra, FillArrays, SparseArrays |
4 | | -import LinearAlgebra.BLAS |
5 | | - |
6 | | -import Base: AbstractArray, AbstractMatrix, AbstractVector, |
7 | | - ReinterpretArray, ReshapedArray, AbstractCartesianIndex, Slice, |
8 | | - RangeIndex, BroadcastStyle, copyto!, length, broadcastable, axes, |
9 | | - getindex, eltype, tail, IndexStyle, IndexLinear, getproperty, |
10 | | - *, +, -, /, \, ==, isinf, isfinite, sign, angle, show, isless, |
11 | | - fld, cld, div, min, max, minimum, maximum, mod, |
12 | | - <, ≤, >, ≥, promote_rule, convert, copy, |
13 | | - size, step, isempty, length, first, last, ndims, |
14 | | - getindex, setindex!, intersect, @_inline_meta, inv, |
15 | | - sort, sort!, issorted, sortperm, diff, cumsum, sum, in, broadcast, |
16 | | - eltype, parent, real, imag, |
17 | | - conj, transpose, adjoint, permutedims, vec, |
18 | | - exp, log, sqrt, cos, sin, tan, csc, sec, cot, |
19 | | - cosh, sinh, tanh, csch, sech, coth, |
20 | | - acos, asin, atan, acsc, asec, acot, |
21 | | - acosh, asinh, atanh, acsch, asech, acoth, (:), |
22 | | - AbstractMatrix, AbstractArray, checkindex, unsafe_length, OneTo, one, zero, |
23 | | - to_shape, _sub2ind, print_matrix, print_matrix_row, print_matrix_vdots, |
24 | | - checkindex, Slice, @propagate_inbounds, @_propagate_inbounds_meta, |
25 | | - _in_range, _range, Ordered, |
26 | | - ArithmeticWraps, floatrange, reverse, unitrange_last, |
27 | | - AbstractArray, AbstractVector, axes, (:), _sub2ind_recurse, broadcast, promote_eltypeof, |
28 | | - similar, @_gc_preserve_end, @_gc_preserve_begin, |
29 | | - @nexprs, @ncall, @ntuple, tuple_type_tail, |
30 | | - all, any, isbitsunion, issubset, replace_in_print_matrix, replace_with_centered_mark, |
31 | | - strides, unsafe_convert, first_index, unalias, union |
32 | | - |
33 | | -import Base.Broadcast: BroadcastStyle, AbstractArrayStyle, Broadcasted, broadcasted, |
34 | | - combine_eltypes, DefaultArrayStyle, instantiate, materialize, |
35 | | - materialize!, eltypes |
36 | | - |
37 | | -import LinearAlgebra: AbstractTriangular, AbstractQ, QRCompactWYQ, QRPackedQ, checksquare, pinv, |
38 | | - fill!, tilebufsize, factorize, qr, lu, cholesky, |
39 | | - norm2, norm1, normInf, normMinusInf, qr, lu, qr!, lu!, AdjOrTrans, HermOrSym, AdjointAbsVec, |
40 | | - TransposeAbsVec, cholcopy, checknonsingular, _apply_ipiv_rows!, ipiv2perm, RealHermSymComplexHerm, chkfullrank |
41 | | - |
42 | | -import LinearAlgebra.BLAS: BlasFloat, BlasReal, BlasComplex |
43 | | - |
44 | | -import FillArrays: AbstractFill, getindex_value, axes_print_matrix_row, _copy_oftype |
45 | | - |
46 | | -import Base: require_one_based_indexing |
| 4 | +using LinearAlgebra.BLAS |
| 5 | + |
| 6 | +using Base: AbstractCartesianIndex, OneTo, RangeIndex, ReinterpretArray, ReshapedArray, |
| 7 | + Slice, tuple_type_tail, unalias, |
| 8 | + @propagate_inbounds, @_propagate_inbounds_meta |
| 9 | + |
| 10 | +import Base: axes, size, length, eltype, ndims, first, last, diff, isempty, union, sort!, |
| 11 | + ==, *, +, -, /, \, copy, copyto!, similar, getproperty, getindex, strides, |
| 12 | + reverse, unsafe_convert |
| 13 | + |
| 14 | +using Base.Broadcast: Broadcasted |
| 15 | + |
| 16 | +import Base.Broadcast: BroadcastStyle, broadcastable, instantiate, materialize, materialize! |
| 17 | + |
| 18 | +using LinearAlgebra: AbstractTriangular, AbstractQ, QRCompactWYQ, QRPackedQ, checksquare, |
| 19 | + pinv, tilebufsize, cholcopy, |
| 20 | + norm2, norm1, normInf, normMinusInf, |
| 21 | + AdjOrTrans, HermOrSym, RealHermSymComplexHerm, AdjointAbsVec, TransposeAbsVec, |
| 22 | + checknonsingular, _apply_ipiv_rows!, ipiv2perm, chkfullrank |
| 23 | + |
| 24 | +using LinearAlgebra.BLAS: BlasFloat, BlasReal, BlasComplex |
| 25 | + |
| 26 | +using FillArrays: AbstractFill, getindex_value, axes_print_matrix_row, _copy_oftype |
| 27 | + |
| 28 | +using Base: require_one_based_indexing |
47 | 29 |
|
48 | 30 | export materialize, materialize!, MulAdd, muladd!, Ldiv, Rdiv, Lmul, Rmul, Dot, |
49 | | - lmul, rmul, mul, ldiv, rdiv, mul, MemoryLayout, AbstractStridedLayout, |
| 31 | + lmul, mul, ldiv, rdiv, mul, MemoryLayout, AbstractStridedLayout, |
50 | 32 | DenseColumnMajor, ColumnMajor, ZerosLayout, FillLayout, AbstractColumnMajor, RowMajor, AbstractRowMajor, UnitStride, |
51 | 33 | DiagonalLayout, ScalarLayout, SymTridiagonalLayout, TridiagonalLayout, BidiagonalLayout, |
52 | 34 | HermitianLayout, SymmetricLayout, TriangularLayout, |
53 | 35 | UnknownLayout, AbstractBandedLayout, ApplyBroadcastStyle, ConjLayout, AbstractFillLayout, DualLayout, |
54 | | - colsupport, rowsupport, layout_getindex, QLayout, LayoutArray, LayoutMatrix, LayoutVector, |
| 36 | + colsupport, rowsupport, layout_getindex, AbstractQLayout, LayoutArray, LayoutMatrix, LayoutVector, |
55 | 37 | RangeCumsum |
56 | 38 |
|
57 | 39 | if VERSION < v"1.7-" |
@@ -81,7 +63,8 @@ abstract type LayoutArray{T,N} <: AbstractArray{T,N} end |
81 | 63 | const LayoutMatrix{T} = LayoutArray{T,2} |
82 | 64 | const LayoutVector{T} = LayoutArray{T,1} |
83 | 65 |
|
84 | | -## TODO: Following are type piracy whch may be removed in Julia v1.5 |
| 66 | +## TODO: Following are type piracy which may be removed in Julia v1.5 |
| 67 | +## No, it can't, because strides(::AdjointAbsMat) is defined only for real eltype! |
85 | 68 | _transpose_strides(a) = (a,1) |
86 | 69 | _transpose_strides(a,b) = (b,a) |
87 | 70 | strides(A::Adjoint) = _transpose_strides(strides(parent(A))...) |
@@ -145,16 +128,16 @@ Base.@propagate_inbounds layout_getindex(A::AbstractArray, I::CartesianIndex) = |
145 | 128 |
|
146 | 129 | macro _layoutgetindex(Typ) |
147 | 130 | esc(quote |
148 | | - @inline Base.getindex(A::$Typ, kr::Colon, jr::Colon) = ArrayLayouts.layout_getindex(A, kr, jr) |
149 | | - @inline Base.getindex(A::$Typ, kr::Colon, jr::AbstractUnitRange) = ArrayLayouts.layout_getindex(A, kr, jr) |
150 | | - @inline Base.getindex(A::$Typ, kr::AbstractUnitRange, jr::Colon) = ArrayLayouts.layout_getindex(A, kr, jr) |
151 | | - @inline Base.getindex(A::$Typ, kr::AbstractUnitRange, jr::AbstractUnitRange) = ArrayLayouts.layout_getindex(A, kr, jr) |
152 | | - @inline Base.getindex(A::$Typ, kr::AbstractVector, jr::AbstractVector) = ArrayLayouts.layout_getindex(A, kr, jr) |
153 | | - @inline Base.getindex(A::$Typ, kr::Colon, jr::AbstractVector) = ArrayLayouts.layout_getindex(A, kr, jr) |
154 | | - @inline Base.getindex(A::$Typ, kr::Colon, jr::Integer) = ArrayLayouts.layout_getindex(A, kr, jr) |
155 | | - @inline Base.getindex(A::$Typ, kr::AbstractVector, jr::Colon) = ArrayLayouts.layout_getindex(A, kr, jr) |
156 | | - @inline Base.getindex(A::$Typ, kr::Integer, jr::Colon) = ArrayLayouts.layout_getindex(A, kr, jr) |
157 | | - @inline Base.getindex(A::$Typ, kr::Integer, jr::AbstractVector) = ArrayLayouts.layout_getindex(A, kr, jr) |
| 131 | + @inline getindex(A::$Typ, kr::Colon, jr::Colon) = ArrayLayouts.layout_getindex(A, kr, jr) |
| 132 | + @inline getindex(A::$Typ, kr::Colon, jr::AbstractUnitRange) = ArrayLayouts.layout_getindex(A, kr, jr) |
| 133 | + @inline getindex(A::$Typ, kr::AbstractUnitRange, jr::Colon) = ArrayLayouts.layout_getindex(A, kr, jr) |
| 134 | + @inline getindex(A::$Typ, kr::AbstractUnitRange, jr::AbstractUnitRange) = ArrayLayouts.layout_getindex(A, kr, jr) |
| 135 | + @inline getindex(A::$Typ, kr::AbstractVector, jr::AbstractVector) = ArrayLayouts.layout_getindex(A, kr, jr) |
| 136 | + @inline getindex(A::$Typ, kr::Colon, jr::AbstractVector) = ArrayLayouts.layout_getindex(A, kr, jr) |
| 137 | + @inline getindex(A::$Typ, kr::Colon, jr::Integer) = ArrayLayouts.layout_getindex(A, kr, jr) |
| 138 | + @inline getindex(A::$Typ, kr::AbstractVector, jr::Colon) = ArrayLayouts.layout_getindex(A, kr, jr) |
| 139 | + @inline getindex(A::$Typ, kr::Integer, jr::Colon) = ArrayLayouts.layout_getindex(A, kr, jr) |
| 140 | + @inline getindex(A::$Typ, kr::Integer, jr::AbstractVector) = ArrayLayouts.layout_getindex(A, kr, jr) |
158 | 141 | end) |
159 | 142 | end |
160 | 143 |
|
|
243 | 226 |
|
244 | 227 |
|
245 | 228 | _copyto!(_, _, dest::AbstractArray{T,N}, src::AbstractArray{V,N}) where {T,V,N} = |
246 | | - Base.invoke(copyto!, Tuple{AbstractArray{T,N},AbstractArray{V,N}}, dest, src) |
| 229 | + invoke(copyto!, Tuple{AbstractArray{T,N},AbstractArray{V,N}}, dest, src) |
247 | 230 |
|
248 | 231 |
|
249 | 232 | _copyto!(dest, src) = _copyto!(MemoryLayout(dest), MemoryLayout(src), dest, src) |
@@ -281,7 +264,7 @@ function zero!(_, A::AbstractArray{<:AbstractArray}) |
281 | 264 | A |
282 | 265 | end |
283 | 266 |
|
284 | | -_norm(_, A, p) = Base.invoke(norm, Tuple{Any,Real}, A, p) |
| 267 | +_norm(_, A, p) = invoke(norm, Tuple{Any,Real}, A, p) |
285 | 268 | LinearAlgebra.norm(A::LayoutArray, p::Real=2) = _norm(MemoryLayout(A), A, p) |
286 | 269 | LinearAlgebra.norm(A::SubArray{<:Any,N,<:LayoutArray}, p::Real=2) where N = _norm(MemoryLayout(A), A, p) |
287 | 270 |
|
@@ -353,7 +336,7 @@ layout_replace_in_print_matrix(_, A, i, j, s) = |
353 | 336 | i in colsupport(A,j) ? s : Base.replace_with_centered_mark(s) |
354 | 337 |
|
355 | 338 | Base.replace_in_print_matrix(A::Union{LayoutVector, |
356 | | - LayoutMatrix, |
| 339 | + LayoutMatrix, |
357 | 340 | UpperTriangular{<:Any,<:LayoutMatrix}, |
358 | 341 | UnitUpperTriangular{<:Any,<:LayoutMatrix}, |
359 | 342 | LowerTriangular{<:Any,<:LayoutMatrix}, |
|
0 commit comments