-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Allow more general eltypes in sparse array multiplication #33205
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
Conversation
copy(::Adjoint/Transpose)+ simplesmatrix fixes added news fix promote_op for sparsevec mul! added + to SimpleSMatrix (required for matprod) trying to make mat * vec work :-( _At_or_Ac_mul_B! fix to accept target eltype more simplesmatrix fixes yet more fixes to simplesmatrix more stringent tests
|
(I see some whitespace fixes are needed... Can somebody briefly point out how to address that?) |
Remove trailing whitespaces. |
zero in sparse mul!|
Seems reasonable to me. @tkf any thoughts on this? Should we use Booleans here? |
|
I think you are right, booleans are in fact better. I somehow though I saw |
|
I don't think it matters too much here as we are not using |
|
Funny, there is a strange win32 failure that didn't get triggered before the last commit. I assume this is unrelated to this PR? |
|
A friendly bump looking for some volunteer to review if possible. Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice. Completely optional to get rid of more type parameters, this could basically be merged as is.
|
LGTM. I should allow someone else take a look, but if you don't hear soon let's merge. |
Co-Authored-By: Fredrik Ekre <[email protected]>
Co-Authored-By: Fredrik Ekre <[email protected]>
|
Many thanks to both for the review and approval! |
|
Could this be merged, perhaps? |
|
This seems like it broke the tests for JWAS.jl: |
|
First of all, my apologies, this was my first merged PR and I feel bad! |
Please don't! This happens all the time, this just either means that we lack some tests in Base or that the package does something "weird". Consider it a rite of passage ;) The reason for suspecting this PR is that it was bisected here: #34238 (comment). As you can see in that thread, we started with over 200 new breakages for 1.4 so breaking packages is definitely not a big deal. |
|
So the difference is in: julia> a = convert(SparseMatrixCSC{AbstractFloat, Int}, sparse(rand(Float32, 2,2)));
julia> b = sparse(rand(Float32, 2,2));
julia> typeof(a*b)
SparseMatrixCSC{Any,Int64}On 1.3, this returned a |
|
I made a PR to the package to fix it: reworkhow/JWAS.jl#59. Not sure if we need to change anything in Julia. |
|
I see! With this PR the target eltype of the product while in 1.3 we merely did Probably the correct solution within Julia is to make |
|
Uhm, that promote_op method goes into the |
|
Yeah, |
Fixes #33169
Replaces
one(T)by1in five-argumentmul!calls withSparseArraytypes, whereTwas before the target eltype. This allows eltypes that don't defineoneby relying on the fact that1is always a multiplicative identity forAbtractArraysas far as I can tell(even forEDIT: changedBooleltypes)1, 0totrue, false.With this we can in particular use
StaticArrays as eltypes ofSparseMatrixCSC. It does not allowArrayeltypes, since they don't definezero, which is used inmul!. Solving the issue also for eltypes that don't definezerois of much broader scope than the present PR due to the pervasive assumption throughout SparseArrays thatzero(eltype(A))forA::AbstractSparseArrayis defined.As a consequence of allowing general (e.g. matrix-like) eltypes in all product combinations involving a sparse vector or matrices (see tests) a range of changes throughout SparseArrays were needed, including in
copy(::AbstractSparseMatrix),halfperm!,spmatmuland_At_or_Ac_mul_B.This fix does not address a possible version of #33169 without any sparse factors (i.e. all changes here are strictly confined to the SparseArrays lib)
(This is my first PR to Julia stdlib. It might be a good idea to show this to Nanosoldier, and to have some careful review if possible)