diff --git a/lib/mkl/interfaces.jl b/lib/mkl/interfaces.jl index a7f43da4..a18f74ea 100644 --- a/lib/mkl/interfaces.jl +++ b/lib/mkl/interfaces.jl @@ -17,8 +17,9 @@ function LinearAlgebra.generic_matvecmul!(C::oneVector{T}, tA::AbstractChar, A:: return sparse_gemv!(tA, alpha, A, B, beta, C) end -function LinearAlgebra.generic_matvecmul!(C::oneVector{T}, tA::AbstractChar, A::oneSparseMatrixCSC{T}, B::oneVector{T}, alpha::Number, beta::Number) where {T <: BlasReal} - tA = tA in ('S', 's', 'H', 'h') ? 'T' : flip_trans(tA) +function LinearAlgebra.generic_matvecmul!(C::oneVector{T}, tA::AbstractChar, A::oneSparseMatrixCSC{T}, B::oneVector{T}, alpha::Number, beta::Number) where {T <: BlasFloat} + # sparse_gemv! already maps op(A) onto the transposed CSR handle, so tA is passed through + tA = tA in ('S', 's', 'H', 'h') ? 'N' : tA return sparse_gemv!(tA, alpha, A, B, beta, C) end @@ -28,8 +29,9 @@ function LinearAlgebra.generic_matmatmul!(C::oneMatrix{T}, tA, tB, A::oneSparseM return sparse_gemm!(tA, tB, alpha, A, B, beta, C) end -function LinearAlgebra.generic_matmatmul!(C::oneMatrix{T}, tA, tB, A::oneSparseMatrixCSC{T}, B::oneMatrix{T}, alpha::Number, beta::Number) where {T <: BlasReal} - tA = tA in ('S', 's', 'H', 'h') ? 'T' : flip_trans(tA) +function LinearAlgebra.generic_matmatmul!(C::oneMatrix{T}, tA, tB, A::oneSparseMatrixCSC{T}, B::oneMatrix{T}, alpha::Number, beta::Number) where {T <: BlasFloat} + # sparse_gemm! already maps op(A) onto the transposed CSR handle, so tA is passed through + tA = tA in ('S', 's', 'H', 'h') ? 'N' : tA tB = tB in ('S', 's', 'H', 'h') ? 'N' : tB return sparse_gemm!(tA, tB, alpha, A, B, beta, C) end diff --git a/test/onemkl.jl b/test/onemkl.jl index 31cd7b5f..f0383962 100644 --- a/test/onemkl.jl +++ b/test/onemkl.jl @@ -1175,6 +1175,32 @@ end end end + # `*` and `mul!` reach oneMKL through generic_matvecmul!/generic_matmatmul!, which is + # a separate mapping from the sparse_gemv!/sparse_gemm! calls exercised above + @testset "sparse LinearAlgebra mul" begin + @testset "$SparseMatrix" for SparseMatrix in csr_csc_matrices + A = sprand(T, 10, 10, 0.5) + x = rand(T, 10) + y = rand(T, 10) + B = rand(T, 10, 2) + C = rand(T, 10, 2) + + dA = SparseMatrix(A) + dx = oneVector{T}(x) + dB = oneMatrix{T}(B) + + @testset "opa = $(nameof(opa))" for opa in (identity, transpose, adjoint) + @test opa(A) * x ≈ collect(opa(dA) * dx) + @test opa(A) * B ≈ collect(opa(dA) * dB) + end + + alpha = rand(T) + beta = rand(T) + @test alpha * A * x + beta * y ≈ collect(mul!(oneVector{T}(y), dA, dx, alpha, beta)) + @test alpha * A * B + beta * C ≈ collect(mul!(oneMatrix{T}(C), dA, dB, alpha, beta)) + end + end + @testset "sparse symv" begin @testset "$SparseMatrix" for SparseMatrix in csr_csc_matrices @testset "uplo = $uplo" for uplo in ('L', 'U')