-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
More sparse operations support #50
Conversation
@alyst Can you split the PR to add what is already working? |
@amontoison I will rebase it on top of the 2 PRs I have submitted today. I think all of the new operations should be working (I use them in my code), but I would need to fix/add the tests. |
Perfect, thanks @alyst 👍 |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #50 +/- ##
===========================================
+ Coverage 32.98% 44.39% +11.40%
===========================================
Files 7 8 +1
Lines 1258 1489 +231
===========================================
+ Hits 415 661 +246
+ Misses 843 828 -15 ☔ View full report in Codecov by Sentry. |
- use randn() instead of rand() to include negative values - variable sparsity rate for random sparse matrices
use + to generate symmetric matrix; the result of matrix multiplication may have different eltype
this is required to support checking dimensions for X*A*X^T
to distringuish from MKLSparseMatrix
copyto!(Matrix, CSR) that works with unordered colval
@amontoison Finally I was able to add the tests for this PR, so it should be ready for review. I've also added "Implementation Notes" section to the PR description to provide some context about what was implemented and what are the limitations. |
@alyst I will review that :) |
Thank you! I think v2025.0 is not required, any v2024 should work as well (v2025 is subject to the same restrictions I've mentioned in the implementation notes). |
LGTM, I merged and tagged a new release 👍 |
This PR adds support for more SparseMKL operations:
sp2md!()
)sp2m()
,sp2m!()
)syprd!()
)syrk!()
)Implementation Details
reusing the sparsity structure in principle, it only supports the sparsity structure allocated by Intel MKL.
It is therefore not possible to directly update the existing SparseMatrixCSC object, reusing the colptr, rowval and updating the nzval only.
Instead, each sp2m!() call has to recalculate the sparsity structure, so it is not efficient as it could have been.
syprd() routines only support the CSR format and only fill the upper triangular part of the matrix.
So, while MKLSparse.jl wrappers (syrkd!() and syprd!()) implement CSC support by treating it as a transpose/adjoint of the CSR matrix, it
does not work for complex numbers and operations like
C := a * A^H A + b * C
, because transposition trick messes with which half of the hermitianC
is used. So complex support for
syrkd!()
andsyprd!()
is disabledmul!()
calls like low rank dense BLAS counterparts.Also,
copytri!()
is actually very expensive for large matrices due to cache misses, so doing it by default may result in degraded performance.Potentially, MKLSparse.jl may support PDMats.jl via extension mechanism to implement
X_A_Xt!()
viasyprd!()
.syrk()
only returns the upper triangular part of the resulting sparse matrix. Since allocating and computing the lower triangular part in that case could be even more expensive thanfor the dense case,
syrk(..., copytri=true)
is not allowed.spmm()
andspmmd!()
wrappers were added, but as they are just more limited versions ofsp2m!()
andsp2md!()
, they were not tested