-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
broadcast makes sparse matrix full #11474
Comments
@mauro3 Which version of Julia? |
Sorry, both 0.3 and 0.4. (edit: oddly broadcasting |
This is because of the Line 236 in 6b35206
You should be able to do either |
So, should it be a And the |
Well, |
I am pretty sure the dense output is due to a generic fallback. |
Perhaps if one of the inputs is sparse, we should dispatch to the sparse version.
|
Not unless we know a-priori that the function is zero-preserving? On second thought, maybe that would make sense, but the behavior of the function on zeros would have to be checked for that case. |
With only one sparse input, I think it doesn't make sense to produce a |
This seems like it should be an easy thing to test. The unfortunate thing is that we will end up with a type unstable solution. I doubt that will be a problem, but still worth keeping in mind. |
I don't think we can add a whole lot of cleverness to broadcast on sparse matrices in time for 0.5. There are sparse-specialized internal methods but you have to look for them and your operation needs to satisfy the invariants. |
The existing machinery should only kick in if all arguments are |
Consensus seems in favor of returning an |
where's that? for concatenation we promote combinations of dense and sparse to sparse. the potential benefit here for operations like multiplication to promote results to sparse is large. dense in sparse format is not a terrible fallback when the operation acts more like addition, and you could use broadcast! if you really wanted a dense format output |
We really need a common and generic mechanism to choose the return type for |
Vague impression from reading comments in the week prior to that post, but that vague impression could well have been the product of my then sleep-deprivation-addled mind :).
Good point!
Yes, given still more sophisticated generic sparse broadcast, though not presently. Best! |
Agreed. |
Yes, maybe, in which case it could be renamed to something more general. You understand these issues better than I do. |
Doubtful :). Near term (i.e. for 0.6), when |
Shouldn't the type of the result depend on whether the operation is zero-preserving? It wouldn't be great to have |
That wouldn't be type stable though, since we can't dispatch on zero-preserving-ness from the type of a function alone. |
Memory of a dense sparse matrix is only ~2x a dense matrix. User can always convert it to a full matrix. |
or use |
OK, sorry, I haven't followed the discussions regarding this closely enough. But Sacha didn't believe me... |
The example from the original post now works (#20009): julia> sp = sprand(3,3,0.1)
3×3 sparse matrix with 2 Float64 stored entries:
[1, 1] = 0.930125
[3, 2] = 0.781933
julia> broadcast(*, [1,1,1], sp)
3×3 sparse matrix with 2 Float64 stored entries:
[1, 1] = 0.930125
[3, 2] = 0.781933 Best! |
The text was updated successfully, but these errors were encountered: