@@ -6,235 +6,5 @@ Random.seed!(0)
66include (" test_layouts.jl" )
77include (" test_muladd.jl" )
88include (" test_ldiv.jl" )
9-
10- struct MyMatrix <: LayoutMatrix{Float64}
11- A:: Matrix{Float64}
12- end
13-
14- Base. getindex (A:: MyMatrix , k:: Int , j:: Int ) = A. A[k,j]
15- Base. setindex! (A:: MyMatrix , v, k:: Int , j:: Int ) = setindex! (A. A, v, k, j)
16- Base. size (A:: MyMatrix ) = size (A. A)
17- Base. strides (A:: MyMatrix ) = strides (A. A)
18- Base. unsafe_convert (:: Type{Ptr{T}} , A:: MyMatrix ) where T = Base. unsafe_convert (Ptr{T}, A. A)
19- MemoryLayout (:: Type{MyMatrix} ) = DenseColumnMajor ()
20-
21- struct MyVector <: LayoutVector{Float64}
22- A:: Vector{Float64}
23- end
24-
25- Base. getindex (A:: MyVector , k:: Int ) = A. A[k]
26- Base. setindex! (A:: MyVector , v, k:: Int ) = setindex! (A. A, v, k)
27- Base. size (A:: MyVector ) = size (A. A)
28- Base. strides (A:: MyVector ) = strides (A. A)
29- Base. unsafe_convert (:: Type{Ptr{T}} , A:: MyVector ) where T = Base. unsafe_convert (Ptr{T}, A. A)
30- MemoryLayout (:: Type{MyVector} ) = DenseColumnMajor ()
31-
32- # These need to test dispatch reduces to ArrayLayouts.mul, etc.
33- @testset " LayoutArray" begin
34- @testset " LayoutVector" begin
35- a = MyVector ([1. ,2 ,3 ])
36- B = randn (3 ,3 )
37- b = randn (3 )
38-
39- @test a == a. A == Vector (a)
40- @test a[1 : 3 ] == a. A[1 : 3 ]
41- @test a[:] == a
42- @test (a' )[1 ,:] == (a' )[1 ,1 : 3 ] == a
43- @test stringmime (" text/plain" , a) == " 3-element MyVector:\n 1.0\n 2.0\n 3.0"
44- @test B* a ≈ B* a. A
45- @test B' * a ≈ B' * a. A
46- @test transpose (B)* a ≈ transpose (B)* a. A
47- @test b' a ≈ transpose (b)a ≈ a' b ≈ transpose (a)b ≈ b' a. A
48- @test qr (B). Q* a ≈ qr (B). Q* a. A
49-
50- @test a' a == transpose (a)a == dot (a,a) == dot (a,a. A) == dot (a. A,a) == 14
51- v = view (a,1 : 3 )
52- @test dot (v,a) == dot (v,a. A) == dot (a,v) == dot (a. A,v) == dot (v,v) == 14
53-
54- s = SparseVector (3 , [1 ], [2 ])
55- @test a' s == s' a == dot (a,s) == dot (s,a) == dot (s,a. A)
56- end
57-
58- @testset " LayoutMatrix" begin
59- A = MyMatrix (randn (5 ,5 ))
60- for (kr,jr) in ((1 : 2 ,2 : 3 ), (:,:), (:,1 : 2 ), (2 : 3 ,:), ([1 ,2 ],3 : 4 ), (:,[1 ,2 ]), ([2 ,3 ],:),
61- (2 ,:), (:,2 ), (2 ,1 : 3 ), (1 : 3 ,2 ))
62- @test A[kr,jr] == A. A[kr,jr]
63- end
64- b = randn (5 )
65- for Tri in (UpperTriangular, UnitUpperTriangular, LowerTriangular, UnitLowerTriangular)
66- @test ldiv! (Tri (A), copy (b)) ≈ ldiv! (Tri (A. A), copy (b))
67- @test lmul! (Tri (A), copy (b)) ≈ lmul! (Tri (A. A), copy (b))
68- end
69-
70- @test copyto! (MyMatrix (Array {Float64} (undef,5 ,5 )), A) == A
71- @test copyto! (Array {Float64} (undef,5 ,5 ), A) == A
72- @test copyto! (MyMatrix (Array {Float64} (undef,5 ,5 )), A. A) == A
73- @test copyto! (view (MyMatrix (Array {Float64} (undef,5 ,5 )),1 : 3 ,1 : 3 ), view (A,1 : 3 ,1 : 3 )) == A[1 : 3 ,1 : 3 ]
74- @test copyto! (view (MyMatrix (Array {Float64} (undef,5 ,5 )),:,:), A) == A
75- @test copyto! (MyMatrix (Array {Float64} (undef,3 ,3 )), view (A,1 : 3 ,1 : 3 )) == A[1 : 3 ,1 : 3 ]
76- @test copyto! (view (MyMatrix (Array {Float64} (undef,5 ,5 )),:,:), A. A) == A
77- @test copyto! (Array {Float64} (undef,3 ,3 ), view (A,1 : 3 ,1 : 3 )) == A[1 : 3 ,1 : 3 ]
78- @test copyto! (MyMatrix (Array {Float64} (undef,5 ,5 )), A' ) == A'
79- @test copyto! (MyMatrix (Array {Float64} (undef,5 ,5 )), view (A' ,:,:)) == A'
80- @test copyto! (Array {Float64} (undef,5 ,5 ), A' ) == A'
81- @test copyto! (Array {Float64} (undef,5 ,5 ), view (A' ,:,:)) == A'
82- @test copyto! (view (MyMatrix (Array {Float64} (undef,5 ,5 )),:,:), A' ) == A'
83-
84- @test copyto! (view (MyMatrix (Array {Float64} (undef,5 ,5 )),:,:), view (A' ,:,:)) == A'
85-
86- @test qr (A). factors ≈ qr (A. A). factors
87- @test qr (A,Val (true )). factors ≈ qr (A. A,Val (true )). factors
88- @test lu (A). factors ≈ lu (A. A). factors
89- @test lu (A,Val (true )). factors ≈ lu (A. A,Val (true )). factors
90- @test_throws ErrorException qr! (A)
91- @test_throws ErrorException lu! (A)
92-
93- @test qr (A) isa LinearAlgebra. QRCompactWY
94- @test inv (A) ≈ inv (A. A)
95-
96- Bin = randn (5 ,5 )
97- B = MyMatrix (copy (Bin))
98- muladd! (1.0 , A, A, 2.0 , B)
99- @test all (B .=== A. A^ 2 + 2 Bin)
100-
101- @testset " tiled_blasmul!" begin
102- B = MyMatrix (copy (Bin))
103- muladd! (1.0 , Ones (5 ,5 ), A, 2.0 , B)
104- end
105-
106- @testset " generic_blasmul!" begin
107- A = BigFloat .(randn (5 ,5 ))
108- Bin = BigFloat .(randn (5 ,5 ))
109- B = copy (Bin)
110- muladd! (1.0 , Ones (5 ,5 ), A, 2.0 , B)
111- @test B == Ones (5 ,5 )* A + 2.0 Bin
112- end
113-
114- C = MyMatrix ([1 2 ; 3 4 ])
115- @test stringmime (" text/plain" , C) == " 2×2 MyMatrix:\n 1.0 2.0\n 3.0 4.0"
116-
117- @testset " layoutldiv" begin
118- A = MyMatrix (randn (5 ,5 ))
119- x = randn (5 )
120- X = randn (5 ,5 )
121- t = view (randn (10 ),[1 ,3 ,4 ,6 ,7 ])
122- T = view (randn (10 ,5 ),[1 ,3 ,4 ,6 ,7 ],:)
123- t̃ = copy (t)
124- T̃ = copy (T)
125- B = Bidiagonal (randn (5 ),randn (4 ),:U )
126- @test ldiv! (A, copy (x)) ≈ A\ x
127- @test A\ t ≈ A\ t̃
128- # QR is not general enough
129- @test_broken ldiv! (A, t) ≈ A\ t
130- @test ldiv! (A, copy (X)) ≈ A\ X
131- @test A\ T ≈ A\ T̃
132- @test_broken A/ T ≈ A/ T̃
133- @test_broken ldiv! (A, T) ≈ A\ T
134- @test B\ A ≈ B\ Matrix (A)
135- @test transpose (B)\ A ≈ transpose (B)\ Matrix (A) ≈ Transpose (B)\ A ≈ Adjoint (B)\ A
136- @test B' \ A ≈ B' \ Matrix (A)
137- @test A\ A ≈ I
138- @test_broken A/ A ≈ I
139- @test A\ MyVector (x) ≈ A\ x
140- @test A\ MyMatrix (X) ≈ A\ X
141- end
142-
143- @testset " dot" begin
144- A = MyMatrix (randn (5 ,5 ))
145- b = randn (5 )
146- @test dot (b, A, b) ≈ b' * (A* b) ≈ b' A* b
147- end
148-
149- @testset " dual vector * symmetric (#40)" begin
150- A = randn (3 ,3 )
151- x = rand (3 )
152- @test x' * Symmetric (MyMatrix (A)) ≈ x' Symmetric (A)
153- @test transpose (x) * Symmetric (MyMatrix (A)) ≈ transpose (x)Symmetric (A)
154- end
155-
156- @testset " map(copy, ::Diagonal)" begin
157- # this is needed in BlockArrays
158- D = Diagonal ([MyMatrix (randn (2 ,2 )), MyMatrix (randn (2 ,2 ))])
159- @test map (copy, D) == D
160- end
161- end
162-
163- @testset " l/rmul!" begin
164- b = MyVector (randn (5 ))
165- A = MyMatrix (randn (5 ,5 ))
166- @test lmul! (2 , deepcopy (b)) == rmul! (deepcopy (b), 2 ) == 2 b
167- @test lmul! (2 , deepcopy (A)) == rmul! (deepcopy (A), 2 ) == 2 A
168- @test lmul! (2 , deepcopy (A)' ) == rmul! (deepcopy (A)' , 2 ) == 2 A'
169- @test lmul! (2 , transpose (deepcopy (A))) == rmul! (transpose (deepcopy (A)), 2 ) == 2 transpose (A)
170- @test lmul! (2 , Symmetric (deepcopy (A))) == rmul! (Symmetric (deepcopy (A)), 2 ) == 2 Symmetric (A)
171- @test lmul! (2 , Hermitian (deepcopy (A))) == rmul! (Hermitian (deepcopy (A)), 2 ) == 2 Hermitian (A)
172-
173- C = randn (ComplexF64,5 ,5 )
174- @test ArrayLayouts. lmul! (2 , Hermitian (copy (C))) == ArrayLayouts. rmul! (Hermitian (copy (C)), 2 ) == 2 Hermitian (C)
175-
176- if VERSION ≥ v " 1.5"
177- @test ldiv! (2 , deepcopy (b)) == rdiv! (deepcopy (b), 2 ) == 2 \ b
178- @test ldiv! (2 , deepcopy (A)) == rdiv! (deepcopy (A), 2 ) == 2 \ A
179- @test ldiv! (2 , deepcopy (A)' ) == rdiv! (deepcopy (A)' , 2 ) == 2 \ A'
180- @test ldiv! (2 , transpose (deepcopy (A))) == rdiv! (transpose (deepcopy (A)), 2 ) == 2 \ transpose (A)
181- @test ldiv! (2 , Symmetric (deepcopy (A))) == rdiv! (Symmetric (deepcopy (A)), 2 ) == 2 \ Symmetric (A)
182- @test ldiv! (2 , Hermitian (deepcopy (A))) == rdiv! (Hermitian (deepcopy (A)), 2 ) == 2 \ Hermitian (A)
183- @test ArrayLayouts. ldiv! (2 , Hermitian (copy (C))) == ArrayLayouts. rdiv! (Hermitian (copy (C)), 2 ) == 2 \ Hermitian (C)
184- end
185- end
186-
187- @testset " pow/I" begin
188- A = randn (2 ,2 )
189- B = MyMatrix (A)
190- @test B^ 2 ≈ A^ 2
191- @test B^ 2.3 ≈ A^ 2.3
192- @test B^ (- 1 ) ≈ inv (A)
193- @test B + I ≈ I + B ≈ A + I
194- @test B - I ≈ A - I
195- @test I - B ≈ I - B
196- end
197- end
198-
199- struct MyUpperTriangular{T} <: AbstractMatrix{T}
200- A:: UpperTriangular{T,Matrix{T}}
201- end
202-
203- MyUpperTriangular {T} (:: UndefInitializer , n:: Int , m:: Int ) where T = MyUpperTriangular {T} (UpperTriangular (Array {T} (undef, n, m)))
204- MyUpperTriangular (A:: AbstractMatrix{T} ) where T = MyUpperTriangular {T} (UpperTriangular (Matrix {T} (A)))
205- Base. convert (:: Type{MyUpperTriangular{T}} , A:: MyUpperTriangular{T} ) where T = A
206- Base. convert (:: Type{MyUpperTriangular{T}} , A:: MyUpperTriangular ) where T = MyUpperTriangular (convert (AbstractArray{T}, A. A))
207- Base. convert (:: Type{MyUpperTriangular} , A:: MyUpperTriangular )= A
208- Base. convert (:: Type{AbstractArray{T}} , A:: MyUpperTriangular ) where T = MyUpperTriangular (convert (AbstractArray{T}, A. A))
209- Base. convert (:: Type{AbstractMatrix{T}} , A:: MyUpperTriangular ) where T = MyUpperTriangular (convert (AbstractArray{T}, A. A))
210- Base. convert (:: Type{MyUpperTriangular{T}} , A:: AbstractArray{T} ) where T = MyUpperTriangular {T} (A)
211- Base. convert (:: Type{MyUpperTriangular{T}} , A:: AbstractArray ) where T = MyUpperTriangular {T} (convert (AbstractArray{T}, A))
212- Base. convert (:: Type{MyUpperTriangular} , A:: AbstractArray{T} ) where T = MyUpperTriangular {T} (A)
213- Base. getindex (A:: MyUpperTriangular , kj... ) = A. A[kj... ]
214- Base. getindex (A:: MyUpperTriangular , :: Colon , j:: AbstractVector ) = MyUpperTriangular (A. A[:,j])
215- Base. setindex! (A:: MyUpperTriangular , v, kj... ) = setindex! (A. A, v, kj... )
216- Base. size (A:: MyUpperTriangular ) = size (A. A)
217- Base. similar (:: Type{MyUpperTriangular{T}} , m:: Int , n:: Int ) where T = MyUpperTriangular {T} (undef, m, n)
218- Base. similar (:: MyUpperTriangular{T} , m:: Int , n:: Int ) where T = MyUpperTriangular {T} (undef, m, n)
219- Base. similar (:: MyUpperTriangular , :: Type{T} , m:: Int , n:: Int ) where T = MyUpperTriangular {T} (undef, m, n)
220- LinearAlgebra. factorize (A:: MyUpperTriangular ) = factorize (A. A)
221-
222- MemoryLayout (:: Type{MyUpperTriangular{T}} ) where T = MemoryLayout (UpperTriangular{T,Matrix{T}})
223- triangulardata (A:: MyUpperTriangular ) = triangulardata (A. A)
224-
225- @_layoutlmul MyUpperTriangular
226-
227-
228- @testset " MyUpperTriangular" begin
229- A = randn (5 ,5 )
230- B = randn (5 ,5 )
231- x = randn (5 )
232- U = MyUpperTriangular (A)
233-
234- @test lmul! (U, copy (x)) ≈ U * x
235- @test lmul! (U, copy (B)) ≈ U * B
236-
237- @test_skip lmul! (U,view (copy (B),collect (1 : 5 ),1 : 5 )) ≈ U * B
238- end
239-
9+ include (" test_layoutarray.jl" )
24010include (" test_cumsum.jl" )
0 commit comments