You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fast element-wise update to a sparse matrix without changing sparsity structure
Some algorithms (e.g.: least_squares()) require call a user-defined sparse matrix at every iteration. It happens that, for each iteration, although the matrix is different, its sparsity structure remains constant (i.e.: changing the values of the non-zero floats inside without touching the zeros).
Currently, unless I am mistaken, we're forced to re-instanciate the whole matrix at every iteration (which slows down the calling algorithm, like least_square(), which can have a lot of iterations).
A more efficient way would be to instanciate the matrix before calling the algorithm, and updating only the non-zero values inside at every iteration, like we could do with a dense numpy array.
Describe the solution you'd like
A set_items() method to allow for such element-wise changes with constant sparsity would be very welcome, and since the sparsity is constant, it should be possible to make it quite fast and efficient.
I guess this method would have to be sparse-format specific:
would allow for row-wise changes for csr_matrix
would allow for column-wise changes for csc_matrix
....
An optional indices array could be provided to specify which elements in the row / column would be changed (by defaut assume all non-zero elements are changed ?)
Describe alternatives you've considered
Alternatively, we could use a different sparse format better at assigning (e.g.: lil_matrix) and perform conversion to csr_matrix (because least_squares is best used with csr_matrix format). But it means there would be a sparse format conversion at every iteration, which would be an unnecessary cpu time usage.
The text was updated successfully, but these errors were encountered:
The current way that we allow users to make efficient sparsity-preserving updates is by allowing access to the .data member array. It's a power user feature that comes with some caveats, but it's very fast and very flexible.
I'm not so familiar with the least squares usage, but I suspect we could improve it using this technique.
Thanks @perimosocordiae, I didn't know I could access the data attribute, I'll try it and come back here if I see something constructive to propose in relation with least_square
Fast element-wise update to a sparse matrix without changing sparsity structure
least_squares())
require call a user-defined sparse matrix at every iteration. It happens that, for each iteration, although the matrix is different, its sparsity structure remains constant (i.e.: changing the values of the non-zero floats inside without touching the zeros).least_square()
, which can have a lot of iterations).Describe the solution you'd like
set_items()
method to allow for such element-wise changes with constant sparsity would be very welcome, and since the sparsity is constant, it should be possible to make it quite fast and efficient.csr_matrix
csc_matrix
Describe alternatives you've considered
lil_matrix
) and perform conversion tocsr_matrix
(becauseleast_squares
is best used withcsr_matrix
format). But it means there would be a sparse format conversion at every iteration, which would be an unnecessary cpu time usage.The text was updated successfully, but these errors were encountered: