Skip to content
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

Rotation functions for sparse matrices #9599

Merged
merged 3 commits into from
Jan 4, 2015

Conversation

kshyatt
Copy link
Contributor

@kshyatt kshyatt commented Jan 4, 2015

Although rot180(A::AbstractArray, k::Int), rotr90(A::AbstractArray, k::Int), and rotl90(A::AbstractArray, k::Int) are supposed to accept AbstractArrays, if you actually tried to use them with sparse matrices they'd fail because the matrix-argument-only versions only supported StridedMatrix objects. I added rotations for SparseMatrixCSC matrices as well as some tests.

@tkelman tkelman added the domain:arrays:sparse Sparse arrays label Jan 4, 2015
I,J,V = findnz(A)
m,n = size(A)
#old col inds are new row inds
newJ = similar(J)
Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't this still be called I? (It would avoid an allocation.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will test it out (probably, yes, and then I can do the same in rotl90). It works! Pushed and hopefully ci completes soon.

@timholy
Copy link
Sponsor Member

timholy commented Jan 4, 2015

When writing new tests discovers missing methods, and then those methods get implemented, Progress Is Being Made 😄.

@tkelman
Copy link
Contributor

tkelman commented Jan 4, 2015

Indeed. I believe @kshyatt was also intending to add some docs for the not-yet-documented rotation methods that take an integer second argument. Also it would be interesting to compare the performance of this to a method that uses the colptr and rowval fields of the CSC format directly, as opposed to converting to-then-from coordinate format with findnz and sparse. That's a performance optimization and can be pursued as a future enhancement though.

@timholy
Copy link
Sponsor Member

timholy commented Jan 4, 2015

This passed on travis; since the earlier incarnation also passed AV, I'm merging.

timholy added a commit that referenced this pull request Jan 4, 2015
Rotation functions for sparse matrices
@timholy timholy merged commit 278d9a0 into JuliaLang:master Jan 4, 2015
@kshyatt kshyatt deleted the sparserotations branch January 4, 2015 17:37
@ViralBShah
Copy link
Member

👍

@ViralBShah
Copy link
Member

If we have something like mapnz, we can do it for all the math operations without replicating the code again for sparse matrices (#7010). Right now, they are all going to be really slow.

@tkelman
Copy link
Contributor

tkelman commented Jan 5, 2015

I'm not sure whether map is exactly the interface you want here. Something more like enumerate, probably.

@ViralBShah
Copy link
Member

Backported to 0.3 in 8d6a61b

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants