@@ -2,7 +2,7 @@ module ArrayLayouts
22using Base, Base. Broadcast, LinearAlgebra, FillArrays
33import LinearAlgebra. BLAS
44
5- import Base: AbstractArray, AbstractMatrix, AbstractVector,
5+ import Base: AbstractArray, AbstractMatrix, AbstractVector,
66 ReinterpretArray, ReshapedArray, AbstractCartesianIndex, Slice,
77 RangeIndex, BroadcastStyle, copyto!, length, broadcastable, axes,
88 getindex, eltype, tail, IndexStyle, IndexLinear, getproperty,
@@ -33,33 +33,33 @@ import Base.Broadcast: BroadcastStyle, AbstractArrayStyle, Broadcasted, broadcas
3333 combine_eltypes, DefaultArrayStyle, instantiate, materialize,
3434 materialize!, eltypes
3535
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
3838
3939import LinearAlgebra. BLAS: BlasFloat, BlasReal, BlasComplex
4040
41- import FillArrays: AbstractFill, getindex_value
41+ import FillArrays: AbstractFill, getindex_value, axes_print_matrix_row
4242
4343if VERSION < v " 1.2-"
4444 import Base: has_offset_axes
4545 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" ))
4646else
47- import Base: require_one_based_indexing
48- end
47+ import Base: require_one_based_indexing
48+ end
4949
5050export materialize, materialize!, MulAdd, muladd!, Ldiv, Rdiv, Lmul, Rmul, lmul, rmul, ldiv, rdiv, mul, MemoryLayout, AbstractStridedLayout,
5151 DenseColumnMajor, ColumnMajor, ZerosLayout, FillLayout, AbstractColumnMajor, RowMajor, AbstractRowMajor, UnitStride,
52- DiagonalLayout, ScalarLayout, SymTridiagonalLayout, HermitianLayout, SymmetricLayout, TriangularLayout,
52+ DiagonalLayout, ScalarLayout, SymTridiagonalLayout, HermitianLayout, SymmetricLayout, TriangularLayout,
5353 UnknownLayout, AbstractBandedLayout, ApplyBroadcastStyle, ConjLayout, AbstractFillLayout,
5454 colsupport, rowsupport, layout_getindex, QLayout, LayoutArray, LayoutMatrix, LayoutVector
5555
5656struct ApplyBroadcastStyle <: BroadcastStyle end
57- @inline function copyto! (dest:: AbstractArray , bc:: Broadcasted{ApplyBroadcastStyle} )
57+ @inline function copyto! (dest:: AbstractArray , bc:: Broadcasted{ApplyBroadcastStyle} )
5858 @assert length (bc. args) == 1
5959 copyto! (dest, first (bc. args))
6060end
6161
62- # Subtypes of LayoutArray default to
62+ # Subtypes of LayoutArray default to
6363# ArrayLayouts routines
6464abstract type LayoutArray{T,N} <: AbstractArray{T,N} end
6565const LayoutMatrix{T} = LayoutArray{T,2 }
@@ -76,15 +76,15 @@ strides(A::Transpose) = _transpose_strides(strides(parent(A))...)
7676
7777represents that the entry is the complex-conjugate of the pointed to entry.
7878"""
79- struct ConjPtr{T}
79+ struct ConjPtr{T}
8080 ptr:: Ptr{T}
8181end
8282
8383unsafe_convert (:: Type{Ptr{T}} , A:: Adjoint{<:Real} ) where T<: Real = unsafe_convert (Ptr{T}, parent (A))
8484unsafe_convert (:: Type{Ptr{T}} , A:: Transpose ) where T = unsafe_convert (Ptr{T}, parent (A))
8585# work-around issue with complex conjugation of pointer
8686unsafe_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))
8888function unsafe_convert (:: Type{ConjPtr{T}} , V:: SubArray{T,2} ) where {T,N,P}
8989 kr, jr = parentindices (V)
9090 unsafe_convert (Ptr{T}, view (parent (V)' , jr, kr))
@@ -125,32 +125,34 @@ end
125125
126126@layoutmatrix LayoutMatrix
127127
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} =
129131 Base. invoke (copyto!, Tuple{AbstractArray{T,N},AbstractArray{V,N}}, dest, src)
130132
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 =
133135 _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 =
135137 _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 =
137139 _copyto! (MemoryLayout (dest), MemoryLayout (src), dest, src)
138140
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 =
140142 _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 =
142144 _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 =
144146 _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 =
146150 _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)
149151
150152
151153
152154zero! (A:: AbstractArray{T} ) where T = fill! (A,zero (T))
153- function zero! (A:: AbstractArray{<:AbstractArray} )
155+ function zero! (A:: AbstractArray{<:AbstractArray} )
154156 for a in A
155157 zero! (a)
156158 end
213215 return A
214216end
215217
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+
216249end
0 commit comments