@@ -2,7 +2,7 @@ module ArrayLayouts
2
2
using Base, Base. Broadcast, LinearAlgebra, FillArrays
3
3
import LinearAlgebra. BLAS
4
4
5
- import Base: AbstractArray, AbstractMatrix, AbstractVector,
5
+ import Base: AbstractArray, AbstractMatrix, AbstractVector,
6
6
ReinterpretArray, ReshapedArray, AbstractCartesianIndex, Slice,
7
7
RangeIndex, BroadcastStyle, copyto!, length, broadcastable, axes,
8
8
getindex, eltype, tail, IndexStyle, IndexLinear, getproperty,
@@ -33,33 +33,33 @@ import Base.Broadcast: BroadcastStyle, AbstractArrayStyle, Broadcasted, broadcas
33
33
combine_eltypes, DefaultArrayStyle, instantiate, materialize,
34
34
materialize!, eltypes
35
35
36
- import LinearAlgebra: AbstractTriangular, AbstractQ, checksquare, pinv, fill!, tilebufsize, Abuf, Bbuf, Cbuf, dot, factorize, qr, lu, cholesky,
37
- norm2, norm1, normInf, normMinusInf, qr, lu, qr!, lu!
36
+ import LinearAlgebra: AbstractTriangular, AbstractQ, checksquare, pinv, fill!, tilebufsize, Abuf, Bbuf, Cbuf, dot, factorize, qr, lu, cholesky,
37
+ norm2, norm1, normInf, normMinusInf, qr, lu, qr!, lu!, AdjOrTrans, HermOrSym
38
38
39
39
import LinearAlgebra. BLAS: BlasFloat, BlasReal, BlasComplex
40
40
41
- import FillArrays: AbstractFill, getindex_value
41
+ import FillArrays: AbstractFill, getindex_value, axes_print_matrix_row
42
42
43
43
if VERSION < v " 1.2-"
44
44
import Base: has_offset_axes
45
45
require_one_based_indexing (A... ) = ! has_offset_axes (A... ) || throw (ArgumentError (" offset arrays are not supported but got an array with index other than 1" ))
46
46
else
47
- import Base: require_one_based_indexing
48
- end
47
+ import Base: require_one_based_indexing
48
+ end
49
49
50
50
export materialize, materialize!, MulAdd, muladd!, Ldiv, Rdiv, Lmul, Rmul, lmul, rmul, ldiv, rdiv, mul, MemoryLayout, AbstractStridedLayout,
51
51
DenseColumnMajor, ColumnMajor, ZerosLayout, FillLayout, AbstractColumnMajor, RowMajor, AbstractRowMajor, UnitStride,
52
- DiagonalLayout, ScalarLayout, SymTridiagonalLayout, HermitianLayout, SymmetricLayout, TriangularLayout,
52
+ DiagonalLayout, ScalarLayout, SymTridiagonalLayout, HermitianLayout, SymmetricLayout, TriangularLayout,
53
53
UnknownLayout, AbstractBandedLayout, ApplyBroadcastStyle, ConjLayout, AbstractFillLayout,
54
54
colsupport, rowsupport, layout_getindex, QLayout, LayoutArray, LayoutMatrix, LayoutVector
55
55
56
56
struct ApplyBroadcastStyle <: BroadcastStyle end
57
- @inline function copyto! (dest:: AbstractArray , bc:: Broadcasted{ApplyBroadcastStyle} )
57
+ @inline function copyto! (dest:: AbstractArray , bc:: Broadcasted{ApplyBroadcastStyle} )
58
58
@assert length (bc. args) == 1
59
59
copyto! (dest, first (bc. args))
60
60
end
61
61
62
- # Subtypes of LayoutArray default to
62
+ # Subtypes of LayoutArray default to
63
63
# ArrayLayouts routines
64
64
abstract type LayoutArray{T,N} <: AbstractArray{T,N} end
65
65
const LayoutMatrix{T} = LayoutArray{T,2 }
@@ -76,15 +76,15 @@ strides(A::Transpose) = _transpose_strides(strides(parent(A))...)
76
76
77
77
represents that the entry is the complex-conjugate of the pointed to entry.
78
78
"""
79
- struct ConjPtr{T}
79
+ struct ConjPtr{T}
80
80
ptr:: Ptr{T}
81
81
end
82
82
83
83
unsafe_convert (:: Type{Ptr{T}} , A:: Adjoint{<:Real} ) where T<: Real = unsafe_convert (Ptr{T}, parent (A))
84
84
unsafe_convert (:: Type{Ptr{T}} , A:: Transpose ) where T = unsafe_convert (Ptr{T}, parent (A))
85
85
# work-around issue with complex conjugation of pointer
86
86
unsafe_convert (:: Type{Ptr{T}} , Ac:: Adjoint{<:Complex} ) where T<: Complex = unsafe_convert (ConjPtr{T}, parent (Ac))
87
- unsafe_convert (:: Type{ConjPtr{T}} , Ac:: Adjoint{<:Complex} ) where T<: Complex = unsafe_convert (Ptr{T}, parent (Ac))
87
+ unsafe_convert (:: Type{ConjPtr{T}} , Ac:: Adjoint{<:Complex} ) where T<: Complex = unsafe_convert (Ptr{T}, parent (Ac))
88
88
function unsafe_convert (:: Type{ConjPtr{T}} , V:: SubArray{T,2} ) where {T,N,P}
89
89
kr, jr = parentindices (V)
90
90
unsafe_convert (Ptr{T}, view (parent (V)' , jr, kr))
@@ -125,32 +125,34 @@ end
125
125
126
126
@layoutmatrix LayoutMatrix
127
127
128
- _copyto! (_, _, dest:: AbstractArray{T,N} , src:: AbstractArray{V,N} ) where {T,V,N} =
128
+ getindex (A:: LayoutVector , kr:: AbstractVector ) = layout_getindex (A, kr)
129
+
130
+ _copyto! (_, _, dest:: AbstractArray{T,N} , src:: AbstractArray{V,N} ) where {T,V,N} =
129
131
Base. invoke (copyto!, Tuple{AbstractArray{T,N},AbstractArray{V,N}}, dest, src)
130
132
131
-
132
- copyto! (dest:: LayoutArray{<:Any,N} , src:: LayoutArray{<:Any,N} ) where N =
133
+
134
+ copyto! (dest:: LayoutArray{<:Any,N} , src:: LayoutArray{<:Any,N} ) where N =
133
135
_copyto! (MemoryLayout (dest), MemoryLayout (src), dest, src)
134
- copyto! (dest:: AbstractArray{<:Any,N} , src:: LayoutArray{<:Any,N} ) where N =
136
+ copyto! (dest:: AbstractArray{<:Any,N} , src:: LayoutArray{<:Any,N} ) where N =
135
137
_copyto! (MemoryLayout (dest), MemoryLayout (src), dest, src)
136
- copyto! (dest:: LayoutArray{<:Any,N} , src:: AbstractArray{<:Any,N} ) where N =
138
+ copyto! (dest:: LayoutArray{<:Any,N} , src:: AbstractArray{<:Any,N} ) where N =
137
139
_copyto! (MemoryLayout (dest), MemoryLayout (src), dest, src)
138
140
139
- copyto! (dest:: SubArray{<:Any,N,<:LayoutArray} , src:: SubArray{<:Any,N,<:LayoutArray} ) where N =
141
+ copyto! (dest:: SubArray{<:Any,N,<:LayoutArray} , src:: SubArray{<:Any,N,<:LayoutArray} ) where N =
140
142
_copyto! (MemoryLayout (dest), MemoryLayout (src), dest, src)
141
- copyto! (dest:: SubArray{<:Any,N,<:LayoutArray} , src:: LayoutArray{<:Any,N} ) where N =
143
+ copyto! (dest:: SubArray{<:Any,N,<:LayoutArray} , src:: LayoutArray{<:Any,N} ) where N =
142
144
_copyto! (MemoryLayout (dest), MemoryLayout (src), dest, src)
143
- copyto! (dest:: LayoutArray{<:Any,N} , src:: SubArray{<:Any,N,<:LayoutArray} ) where N =
145
+ copyto! (dest:: LayoutArray{<:Any,N} , src:: SubArray{<:Any,N,<:LayoutArray} ) where N =
144
146
_copyto! (MemoryLayout (dest), MemoryLayout (src), dest, src)
145
- copyto! (dest:: SubArray{<:Any,N,<:LayoutArray} , src:: AbstractArray{<:Any,N} ) where N =
147
+ copyto! (dest:: SubArray{<:Any,N,<:LayoutArray} , src:: AbstractArray{<:Any,N} ) where N =
148
+ _copyto! (MemoryLayout (dest), MemoryLayout (src), dest, src)
149
+ copyto! (dest:: AbstractArray{<:Any,N} , src:: SubArray{<:Any,N,<:LayoutArray} ) where N =
146
150
_copyto! (MemoryLayout (dest), MemoryLayout (src), dest, src)
147
- copyto! (dest:: AbstractArray{<:Any,N} , src:: SubArray{<:Any,N,<:LayoutArray} ) where N =
148
- _copyto! (MemoryLayout (dest), MemoryLayout (src), dest, src)
149
151
150
152
151
153
152
154
zero! (A:: AbstractArray{T} ) where T = fill! (A,zero (T))
153
- function zero! (A:: AbstractArray{<:AbstractArray} )
155
+ function zero! (A:: AbstractArray{<:AbstractArray} )
154
156
for a in A
155
157
zero! (a)
156
158
end
213
215
return A
214
216
end
215
217
218
+ # ##
219
+ # printing
220
+ # ##
221
+
222
+ layout_replace_in_print_matrix (_, A, i, j, s) =
223
+ i in colsupport (A,j) ? s : Base. replace_with_centered_mark (s)
224
+
225
+ Base. replace_in_print_matrix (A:: Union {LayoutMatrix,
226
+ UpperTriangular{<: Any ,<: LayoutMatrix },
227
+ UnitUpperTriangular{<: Any ,<: LayoutMatrix },
228
+ LowerTriangular{<: Any ,<: LayoutMatrix },
229
+ UnitLowerTriangular{<: Any ,<: LayoutMatrix },
230
+ AdjOrTrans{<: Any ,<: LayoutMatrix },
231
+ HermOrSym{<: Any ,<: LayoutMatrix },
232
+ SubArray{<: Any ,2 ,<: LayoutMatrix }}, i:: Integer , j:: Integer , s:: AbstractString ) =
233
+ layout_replace_in_print_matrix (MemoryLayout (A), A, i, j, s)
234
+
235
+ Base. print_matrix_row (io:: IO ,
236
+ X:: Union {LayoutMatrix,
237
+ LayoutVector,
238
+ AbstractTriangular{<: Any ,<: LayoutMatrix },
239
+ AdjOrTrans{<: Any ,<: LayoutMatrix },
240
+ HermOrSym{<: Any ,<: LayoutMatrix },
241
+ SubArray{<: Any ,2 ,<: LayoutMatrix },
242
+ Diagonal{<: Any ,<: LayoutVector }}, A:: Vector ,
243
+ i:: Integer , cols:: AbstractVector , sep:: AbstractString ) =
244
+ axes_print_matrix_row (axes (X), io, X, A, i, cols, sep)
245
+
246
+
247
+
248
+
216
249
end
0 commit comments