Skip to content

Commit dfc6e8e

Browse files
authored
Add a few benchmarks (#116)
1 parent 177152b commit dfc6e8e

File tree

4 files changed

+25
-7
lines changed

4 files changed

+25
-7
lines changed

test/functionmap.jl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ using Test, LinearMaps, LinearAlgebra, BenchmarkTools
6262
@test_throws ErrorException mul!(similar(v), CS!', v)
6363
@test_throws ErrorException mul!(similar(v), transpose(CS!), v)
6464
CS! = LinearMap{ComplexF64}(cumsum!, (y, x) -> (copyto!(y, x); reverse!(y); cumsum!(y, y); reverse!(y)), 10; ismutating=true)
65+
M = Matrix(CS!)
6566
@inferred adjoint(CS!)
6667
@test @inferred LinearMaps.ismutating(CS!)
6768
@test @inferred CS! * v == cv
@@ -75,6 +76,19 @@ using Test, LinearMaps, LinearAlgebra, BenchmarkTools
7576
@test run(b, samples=3).allocs == 0
7677
b = @benchmarkable mul!($u, $(3*CS!'), $v)
7778
@test run(b, samples=3).allocs == 0
79+
u = rand(ComplexF64, 10)
80+
v = rand(ComplexF64, 10)
81+
for α in (false, true, rand(ComplexF64)), β in (false, true, rand(ComplexF64))
82+
for transform in (identity, adjoint, transpose)
83+
@test mul!(copy(v), transform(CS!), u, α, β) transform(M)*u*α + v*β
84+
@test mul!(copy(v), transform(LinearMap(CS!)), u, α, β) transform(M)*u*α + v*β
85+
@test mul!(copy(v), LinearMap(transform(CS!)), u, α, β) transform(M)*u*α + v*β
86+
if transform != transpose
87+
bm = @benchmarkable mul!($(copy(v)), $(transform(CS!)), $u, $α, $β)
88+
@test run(bm, samples=3).allocs <= 1
89+
end
90+
end
91+
end
7892

7993
# Test fallback methods:
8094
L = @inferred LinearMap(x -> x, x -> x, 10)

test/linearcombination.jl

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1-
using Test, LinearMaps, LinearAlgebra, BenchmarkTools
1+
using Test, LinearMaps, LinearAlgebra, SparseArrays, BenchmarkTools
22

33
@testset "linear combinations" begin
44
CS! = LinearMap{ComplexF64}(cumsum!,
5-
(y, x) -> (copyto!(y, x); reverse!(y); cumsum!(y, y)), 10;
5+
(y, x) -> (copyto!(y, x); reverse!(cumsum!(y, reverse!(y)))), 10;
66
ismutating=true)
77
v = rand(ComplexF64, 10)
88
u = similar(v)
99
b = @benchmarkable mul!($u, $CS!, $v)
1010
@test run(b, samples=3).allocs == 0
1111
n = 10
1212
L = sum(fill(CS!, n))
13+
M = Matrix(L)
14+
@test M == LowerTriangular(fill(n, size(L)))
1315
@test_throws AssertionError LinearMaps.LinearCombination{Float64}((CS!, CS!))
1416
@test occursin("10×10 LinearMaps.LinearCombination{$(eltype(L))}", sprint((t, s) -> show(t, "text/plain", s), L))
1517
@test occursin("10×10 LinearMaps.LinearCombination{$(eltype(L))}", sprint((t, s) -> show(t, "text/plain", s), L+CS!))
@@ -18,7 +20,9 @@ using Test, LinearMaps, LinearAlgebra, BenchmarkTools
1820
b = @benchmarkable mul!($u, $L, $v, 2, 2)
1921
@test run(b, samples=5).allocs <= 1
2022
for α in (false, true, rand(ComplexF64)), β in (false, true, rand(ComplexF64))
21-
@test mul!(copy(u), L, v, α, β) Matrix(L)*v*α + u*β
23+
for transform in (identity, adjoint, transpose)
24+
@test mul!(copy(u), transform(L), v, α, β) transform(M)*v*α + u*β
25+
end
2226
end
2327
V = rand(ComplexF64, 10, 3)
2428
U = similar(V)

test/runtests.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import LinearMaps: FiveArg, ThreeArg
33

44
const matrixstyle = VERSION v"1.3.0-alpha.115" ? FiveArg() : ThreeArg()
55

6-
const testallocs = true
6+
const testallocs = VERSION v"1.4-"
77

88
include("linearmaps.jl")
99

test/uniformscalingmap.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ using Test, LinearMaps, LinearAlgebra, BenchmarkTools
2727
@test (3 * I - 2 * M') * v == -2 * A'v + 3v
2828
@test transpose(LinearMap(2 * M' + 3 * I)) * v transpose(2 * A' + 3 * I) * v
2929
@test LinearMap(2 * M' + 0I)' * v (2 * A')' * v
30-
for λ in (0, 1, rand()), α in (0, 1, rand()), β in (0, 1, rand())
30+
for λ in (0, 1, rand()), α in (0, 1, rand()), β in (0, 1, rand()), sz in (10, (10,5))
3131
Λ = @inferred LinearMap*I, 10)
32-
x = rand(10)
33-
y = rand(10)
32+
x = rand(Float64, sz)
33+
y = rand(Float64, sz)
3434
if testallocs
3535
b = @benchmarkable mul!($y, $Λ, $x, $α, $β)
3636
@test run(b, samples=3).allocs == 0

0 commit comments

Comments
 (0)