Skip to content

Commit

Permalink
More tests in test_mul.jl
Browse files Browse the repository at this point in the history
  • Loading branch information
tkf committed Nov 7, 2019
1 parent 5b54fe6 commit bb16aea
Showing 1 changed file with 40 additions and 13 deletions.
53 changes: 40 additions & 13 deletions test/test_mul.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module TestMul

include("preamble.jl")
using StaticArrays: SMatrix

@testset begin
@test mul!!(0, 1, 2) === 2
Expand All @@ -15,24 +16,50 @@ include("preamble.jl")
@test_inferred mul!!(C, A, B)

C = zeros(Int, size(A * B))
@test mul!!(C, A, B) :: Matrix{Float64} == A * B
@test mul!!(C, A, B)::Matrix{Float64} == A * B
@test_inferred mul!!(C, A, B)
end

if VERSION >= v"1.3"
@testset "mul!(C, A, B, α, β)" begin
C = zeros(2, 2)
A = reshape(1:4, 2, 2)
B = ones(2, 2)

desired = A * B * 3 + C * 4
@test mul!!(C, A, B, 3, 4) === C
@test C == desired
@test_inferred mul!!(C, A, B, 3, 4)

desired = A * B * 3 + C * 4
@test mul!!(C, A, B, 3, 4) :: Matrix{Float64} == desired
@test_inferred mul!!(C, A, B, 3, 4)
@testset "$label" for (label, isinplace, C, A, B) in [
(
label = "C :: Matrix{Float64} (eltype compatible)",
isinplace = true,
C = zeros(2, 2),
A = reshape(1:4, 2, 2),
B = ones(2, 2),
),
(
label = "C :: Matrix{Int} (eltype compatible)",
isinplace = true,
C = zeros(Int, 2, 2),
A = reshape(1:4, 2, 2),
B = ones(Int, 2, 2),
),
(
label = "C :: Matrix{Int} (eltype incompatible)",
isinplace = false,
C = zeros(Int, 2, 2),
A = reshape(1:4, 2, 2),
B = ones(2, 2),
),
(
label = "C :: SMatrix",
isinplace = false,
C = SMatrix{2,2}(0, 0, 0, 0),
A = SMatrix{2,2}(1, 2, 3, 4),
B = SMatrix{2,2}(5, 6, 7, 8),
),
]
desired = A * B * 3 + C * 4
actual = mul!!(C, A, B, 3, 4)
@test actual == desired
if isinplace
@test C === actual
end
@test_inferred mul!!(C, A, B, 3, 4)
end
end
end

Expand Down

0 comments on commit bb16aea

Please sign in to comment.