Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions lib/mkl/interfaces.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
26 changes: 26 additions & 0 deletions test/onemkl.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
Loading