Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jmert committed Dec 26, 2018
1 parent 2a85cba commit 4912bec
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
15 changes: 15 additions & 0 deletions stdlib/SparseArrays/test/higherorderfns.jl
Original file line number Diff line number Diff line change
Expand Up @@ -656,4 +656,19 @@ using SparseArrays.HigherOrderFns: SparseVecStyle
@test occursin("no method matching _copy(::typeof(rand))", sprint(showerror, err))
end

@testset "Sparse outer product, for type $T and vector $op" for
op in (transpose, adjoint),
T in (Float64, ComplexF64)
m, n, p = 100, 250, 0.1
A = sprand(T, m, n, p)
a, b = view(A, :, 1), sprand(T, m, p)
av, bv = Vector(a), Vector(b)
v = @inferred a .* op(b)
w = @inferred b .* op(a)
@test issparse(v)
@test issparse(w)
@test v == av .* op(bv)
@test w == bv .* op(av)
end

end # module
6 changes: 6 additions & 0 deletions stdlib/SparseArrays/test/sparse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ end
for (m,n) in ((5,10), (13,8), (14,10))
a = sprand(m, 5, 0.4); a_d = Matrix(a)
b = sprand(n, 6, 0.3); b_d = Matrix(b)
v = view(a, :, 1); v_d = Vector(v)
x = sprand(m, 0.4); x_d = Vector(x)
y = sprand(n, 0.3); y_d = Vector(y)
# mat ⊗ mat
Expand All @@ -361,6 +362,11 @@ end
@test Array(kron(x, b)) == kron(x_d, b_d)
@test Array(kron(x_d, b)) == kron(x_d, b_d)
@test Array(kron(x, b_d)) == kron(x_d, b_d)
# vec ⊗ vec'
@test issparse(kron(v, y'))
@test issparse(kron(x, y'))
@test Array(kron(v, y')) == kron(v_d, y_d')
@test Array(kron(x, y')) == kron(x_d, y_d')
# test different types
z = convert(SparseVector{Float16, Int8}, y); z_d = Vector(z)
@test Vector(kron(x, z)) == kron(x_d, z_d)
Expand Down

0 comments on commit 4912bec

Please sign in to comment.