diff --git a/stdlib/SparseArrays/test/higherorderfns.jl b/stdlib/SparseArrays/test/higherorderfns.jl index 5b1423582f0d54..5d353f431cb382 100644 --- a/stdlib/SparseArrays/test/higherorderfns.jl +++ b/stdlib/SparseArrays/test/higherorderfns.jl @@ -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 diff --git a/stdlib/SparseArrays/test/sparse.jl b/stdlib/SparseArrays/test/sparse.jl index a37034a9137379..e28ca1085cb37d 100644 --- a/stdlib/SparseArrays/test/sparse.jl +++ b/stdlib/SparseArrays/test/sparse.jl @@ -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 @@ -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)