Skip to content

Commit cc683be

Browse files
authored
Reduce allocations in tests (#179)
* Reduce allocations in tests * Reduce allocations further
1 parent f42003e commit cc683be

File tree

5 files changed

+27
-27
lines changed

5 files changed

+27
-27
lines changed

test/test_bandedblockbanded.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ import ArrayLayouts: RangeCumsum
256256
@test_throws BandError V[3,1] = 5
257257

258258
view(V, band(0)) .= -3
259-
@test all(A[Block(3,4)][band(0)] .== -3)
259+
@test all(==(-3), A[Block(3,4)][band(0)])
260260

261261
@test BandedMatrix(V) isa BandedMatrix{Int,Matrix{Int}}
262262
@test BandedMatrix{Float64}(V) isa BandedMatrix{Float64,Matrix{Float64}}
@@ -321,7 +321,7 @@ import ArrayLayouts: RangeCumsum
321321

322322
x = randn(size(B,2))
323323
y = similar(x, size(B,1))
324-
@test all((similar(y) .= MulAdd(B, x)) .=== (similar(y) .= MulAdd(V,x)))
324+
@test (similar(y) .= MulAdd(B, x)) == (similar(y) .= MulAdd(V,x))
325325
end
326326

327327
@testset "BLAS arithmetic" begin

test/test_blockbanded.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ import BlockBandedMatrices: MemoryLayout, ColumnMajor, BroadcastStyle,
138138

139139
x = randn(size(B,2))
140140
y = similar(x, size(B,1))
141-
@test all((similar(y) .= MulAdd(B, x)) .=== (similar(y) .= MulAdd(V,x)))
141+
@test (similar(y) .= MulAdd(B, x)) == (similar(y) .= MulAdd(V,x))
142142
end
143143

144144
@testset "BlockBandedMatrix indexing" begin
@@ -195,7 +195,7 @@ import BlockBandedMatrices: MemoryLayout, ColumnMajor, BroadcastStyle,
195195
@test sum(A) == 20
196196
@test sum(B) == 20
197197
C = BlockBandedMatrix{Float64}(undef, [2,2], [2,2,2], (0,3))
198-
@test all(mul!(C,A,B) .=== ArrayLayouts.materialize!(MulAdd(1.0,A,B,0.0,similar(C))) .=== A*B)
198+
@test mul!(C,A,B) == ArrayLayouts.materialize!(MulAdd(1.0,A,B,0.0,similar(C))) == A*B
199199
AB = A*B
200200
@test AB isa BlockBandedMatrix
201201
@test Matrix(AB) Matrix(A)*Matrix(B)

test/test_blockskyline.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,8 @@ Random.seed!(0)
132132
expu = max.(u, bs.u)
133133

134134
Cbs = C.block_sizes
135-
@test all(Cbs.l .== expl)
136-
@test all(Cbs.u .== expu)
135+
@test Cbs.l == expl
136+
@test Cbs.u == expu
137137
end
138138

139139
for (l,u) = [([0,0,0,0],[0,0,0,0]),

test/test_linalg.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ end
8888

8989
C = BandedMatrix{Float64}(undef, size(V), 2 .*bandwidths(V))
9090
C .= MulAdd(V,V)
91-
@test all(C .=== BandedMatrix(V)*BandedMatrix(V))
92-
@test all(muladd!(2.0, V,V, 1.0, copy(C)) .=== BandedMatrices.gbmm!('N', 'N', 2.0, V, V, 1.0, deepcopy(C)))
91+
@test C == BandedMatrix(V)*BandedMatrix(V)
92+
@test muladd!(2.0, V,V, 1.0, copy(C)) == BandedMatrices.gbmm!('N', 'N', 2.0, V, V, 1.0, deepcopy(C))
9393

9494
C = BandedBlockBandedMatrix{Float64}(undef, rows,cols, (2l,2u), (2λ,2μ))
9595
C .= MulAdd(A,A)

test/test_triblockbanded.jl

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,29 +21,29 @@ import BlockArrays: BlockedUnitRange, blockisequal
2121
@test MemoryLayout(typeof(U)) == TriangularLayout{'U','N',BandedBlockBandedColumnMajor}()
2222
b = randn(size(U,1))
2323
@test U*b isa Vector{Float64}
24-
@test all(lmul(U,b) .=== U*b)
24+
@test lmul(U,b) == U*b
2525
@test U*b Matrix(U)*b
2626

2727
U = UnitUpperTriangular(A)
2828
@test MemoryLayout(typeof(U)) == TriangularLayout{'U','U',BandedBlockBandedColumnMajor}()
2929
b = randn(size(U,1))
3030
@test U*b isa Vector{Float64}
31-
@test all(lmul(U,b) .=== U*b)
31+
@test lmul(U,b) == U*b
3232
@test U*b Matrix(U)*b
3333

3434
L = LowerTriangular(A)
3535
@test MemoryLayout(typeof(L)) == TriangularLayout{'L','N',BandedBlockBandedColumnMajor}()
3636
b = randn(size(U,1))
3737
@test L*b isa Vector{Float64}
38-
@test all(lmul(L,b) .=== L*b)
38+
@test lmul(L,b) == L*b
3939
@test L*b Matrix(L)*b
4040

4141

4242
L = UnitLowerTriangular(A)
4343
@test MemoryLayout(typeof(L)) == TriangularLayout{'L','U',BandedBlockBandedColumnMajor}()
4444
b = randn(size(L,1))
4545
@test L*b isa Vector{Float64}
46-
@test all(lmul(L,b) .=== L*b)
46+
@test lmul(L,b) == L*b
4747
@test L*b Matrix(L)*b
4848
end
4949

@@ -80,17 +80,17 @@ import BlockArrays: BlockedUnitRange, blockisequal
8080
U = UpperTriangular(A)
8181
b = randn(size(U,1))
8282
@test copyto!(similar(b), Ldiv(U,b)) Matrix(U) \ b
83-
@test all((similar(b) .= Ldiv(U, b)) .=== copyto!(similar(b), Ldiv(U,b)))
83+
@test (similar(b) .= Ldiv(U, b)) == copyto!(similar(b), Ldiv(U,b))
8484

8585
U = UnitUpperTriangular(A)
8686
b = randn(size(U,1))
8787
@test copyto!(similar(b), Ldiv(U,b)) (Matrix(U) \ b)
88-
@test all((similar(b) .= Ldiv(U, b)) .=== copyto!(similar(b), Ldiv(U,b)))
88+
@test (similar(b) .= Ldiv(U, b)) == copyto!(similar(b), Ldiv(U,b))
8989

9090
L = LowerTriangular(A)
9191
b = randn(size(L,1))
9292
@test copyto!(similar(b), Ldiv(L,b)) (Matrix(L) \ b)
93-
@test all((similar(b) .= Ldiv(L, b)) .=== copyto!(similar(b), Ldiv(L,b)))
93+
@test (similar(b) .= Ldiv(L, b)) == copyto!(similar(b), Ldiv(L,b))
9494
end
9595

9696
@testset "Rectangular blocks BlockBandedMatrix linear algebra" begin
@@ -105,7 +105,7 @@ import BlockArrays: BlockedUnitRange, blockisequal
105105

106106
V = view(A, Block.(1:3), Block.(1:4))
107107
@test blockisequal(axes(V), axes(A))
108-
@test all(Matrix(V) .=== Matrix(A))
108+
@test Matrix(V) == Matrix(A)
109109
@test view(V, Block(2)[1:2], Block(3)) view(A, Block(2)[1:2], Block(3))
110110

111111
@test similar(Ldiv(UpperTriangular(A), b)) isa PseudoBlockVector
@@ -145,7 +145,7 @@ import BlockArrays: BlockedUnitRange, blockisequal
145145
r = UpperTriangular(Matrix(V)) \ b
146146
@test_broken BlockBandedMatrices.blockbanded_squareblocks_trtrs!(V, copy(b)) r
147147

148-
@test_broken all(ldiv!(UpperTriangular(V), copy(b)) .=== BlockBandedMatrices.blockbanded_squareblocks_trtrs!(V, copy(b)))
148+
@test_broken ldiv!(UpperTriangular(V), copy(b)) == BlockBandedMatrices.blockbanded_squareblocks_trtrs!(V, copy(b))
149149

150150
V = view(A, Block.(2:3), Block(3))
151151
@test unsafe_load(pointer(V)) == A[2,4]
@@ -155,8 +155,8 @@ import BlockArrays: BlockedUnitRange, blockisequal
155155
@test size(V) == (5,3)
156156
b = randn(size(V,2))
157157

158-
@test all((similar(b,size(V,1)) .= MulAdd(V,b)) .=== Matrix(V)*b .===
159-
BLAS.gemv!('N', 1.0, V, b, 0.0, Vector{Float64}(undef, size(V,1))))
158+
@test (similar(b,size(V,1)) .= MulAdd(V,b)) == Matrix(V)*b ==
159+
BLAS.gemv!('N', 1.0, V, b, 0.0, Vector{Float64}(undef, size(V,1)))
160160

161161
V = view(A, Block.(1:3), Block(3)[2:3])
162162
@test_throws ArgumentError pointer(V)
@@ -172,8 +172,8 @@ import BlockArrays: BlockedUnitRange, blockisequal
172172

173173
@test size(V) == (5,2)
174174
b = randn(size(V,2))
175-
@test all((similar(b,size(V,1)) .= MulAdd(V,b)) .=== Matrix(V)*b .===
176-
BLAS.gemv!('N', 1.0, V, b, 0.0, Vector{Float64}(undef, size(V,1))))
175+
@test (similar(b,size(V,1)) .= MulAdd(V,b)) == Matrix(V)*b ==
176+
BLAS.gemv!('N', 1.0, V, b, 0.0, Vector{Float64}(undef, size(V,1)))
177177

178178
V = view(A, Block.(1:3), Block(3)[2:3])
179179
@test_throws ArgumentError pointer(V)
@@ -190,18 +190,18 @@ import BlockArrays: BlockedUnitRange, blockisequal
190190
@test unsafe_load(pointer(V_22)) == V_22[1,1] == V[1,1]
191191
@test strides(V_22) == strides(V) == (1,9)
192192
b = randn(N)
193-
@test all(copyto!(similar(b) , MulAdd(V,b)) .=== copyto!(similar(b) , MulAdd(V_22,b)) .===
194-
Matrix(V)*b .===
195-
BLAS.gemv!('N', 1.0, V, b, 0.0, Vector{Float64}(undef, size(V,1))))
193+
@test copyto!(similar(b) , MulAdd(V,b)) == copyto!(similar(b) , MulAdd(V_22,b)) ==
194+
Matrix(V)*b ==
195+
BLAS.gemv!('N', 1.0, V, b, 0.0, Vector{Float64}(undef, size(V,1)))
196196

197-
@test_skip all(UpperTriangular(V_22) \ b .=== ldiv!(UpperTriangular(V_22) , copy(b)) .=== ldiv!(UpperTriangular(V) , copy(b)) .===
198-
ldiv!(UpperTriangular(Matrix(V_22)) , copy(b)))
197+
@test_skip UpperTriangular(V_22) \ b == ldiv!(UpperTriangular(V_22) , copy(b)) == ldiv!(UpperTriangular(V) , copy(b)) ==
198+
ldiv!(UpperTriangular(Matrix(V_22)) , copy(b))
199199

200200
V = view(A, Block.(rows), Block.(cols))
201201
V2 = view(A, 1:size(A,1), 1:size(A,2))
202202
b = randn(size(V,1))
203203

204-
@test all(Matrix(V) .=== Matrix(V2))
204+
@test Matrix(V) == Matrix(V2)
205205
@test UpperTriangular(V2) \ b UpperTriangular(V) \ b
206206
end
207207
end

0 commit comments

Comments
 (0)