Circshift of a SparseMatrix

Right now, circshift falls back to the generic AbstractMatrix implementation when called with a SparseMatrix (being very slow and adding unnecessary structural zeros values in the output).

Adding something simple like the following seems to do the job. So… what is the best way to get it added?

function circshift!(O::SparseMatrixCSC, X::SparseMatrixCSC, (r,c)::Tuple{T,T}) where T<:Int
    I,J,V = findnz(X)
    O .= sparse(map(i->mod1(i + r, X.n), I), map(j->mod1(j + c, X.m), J), V, X.n, X.m)

Submit a pull request:

You’d add the function to one of the files in

You should also add tests to


Thanks, will try to do so!

1 Like

Cool, thanks! Post a link to your PR here.

1 Like

Here it is


More obscure but more efficient version in this PR