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

Added sparse concatenation functions #585

Merged
merged 4 commits into from
Mar 15, 2012

Conversation

carlobaldassi
Copy link
Member

I noticed that SparseMatrixCSC was lacking support for vcat and hcat and I added that.

@carlobaldassi
Copy link
Member Author

I realized there's a cleaner way to do the sparse hcat (see last commit attached to the pull request).
Also, I should probably implement hvcat as well, I'll look into that.

@StefanKarpinski
Copy link
Member

Nice. That is much cleaner.

@carlobaldassi
Copy link
Member Author

Ok I fixed some things:

  • generalized to general number of argument (i.e. more than two)
  • added support for sparse hvcat
  • added a no-op full(x)=x for dense arrays which allows to get the dense cat version as fallback (and which also makes sense imho)

The only drawback w.r.t. the previous version is that concatenation only works with matrices which have the same types (i.e. no more promotion). I'm still trying to find out a workaround for that.

@ViralBShah
Copy link
Member

Can you add a couple of tests as well?

ViralBShah added a commit that referenced this pull request Mar 15, 2012
Added sparse concatenation functions
@ViralBShah ViralBShah merged commit 0c79a2f into JuliaLang:master Mar 15, 2012
@carlobaldassi
Copy link
Member Author

I started writing tests but then I ran into a bug affecting the sparse ref. Here is an example instance:

julia> b = sparse([0.8 0 0; 0 0.3 0.4; 0 0 0])
3x3 sparse matrix with 3 nonzeros:
    [1, 1]  =  0.8
    [2, 2]  =  0.3
    [2, 3]  =  0.4


julia> b[2,3]
0.4

julia> b[2:2,3]
1x1 sparse matrix with 1 nonzeros:
    [1, 1]  =  0.4


julia> b[1:2,3]
2x1 sparse matrix with 0 nonzeros:


julia> #UH?

BTW I solved the promotion issue, it's in the latest commit on the sparse_cat branch in my fork. I'll try to find the bug and then file another pull request with the (hopefully) working tests.

@ViralBShah
Copy link
Member

I merged your stuff in, and added some very simple tests. I don't think that sparse ref has been tested at all. I think that with some focus we can get the sparse matrix stuff into good enough shape that it can be documented and people start using it.

Unless you are fixing this right away, do open an issue so that we don't lose it.

-viral

On 15-Mar-2012, at 10:22 AM, Carlo Baldassi wrote:

I started writing tests but then I ran into a bug affecting the sparse ref. Here is an example instance:

julia> b = sparse([0.8 0 0; 0 0.3 0.4; 0 0 0])
3x3 sparse matrix with 3 nonzeros:
  [1, 1]  =  0.8
  [2, 2]  =  0.3
  [2, 3]  =  0.4


julia> b[2,3]
0.4

julia> b[2:2,3]
1x1 sparse matrix with 1 nonzeros:
  [1, 1]  =  0.4


julia> b[1:2,3]
2x1 sparse matrix with 0 nonzeros:


julia> #UH?

BTW I solved the promotion issue, it's in the latest commit on the sparse_cat branch in my fork. I'll try to find the bug and then file another pull request with the (hopefully) working tests.


Reply to this email directly or view it on GitHub:
#585 (comment)

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

Successfully merging this pull request may close these issues.

3 participants