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

Column slices of sparse matrices should be sparse vectors #6479

Closed
alsam opened this issue Apr 9, 2014 · 11 comments
Closed

Column slices of sparse matrices should be sparse vectors #6479

alsam opened this issue Apr 9, 2014 · 11 comments
Labels
sparse Sparse arrays

Comments

@alsam
Copy link

alsam commented Apr 9, 2014

Dear developers,

For the matrix created with

julia> x = sprandn(7,7,0.3)
7x7 sparse matrix with 14 Float64 entries:
    [1, 1]  =  1.31604
    [3, 1]  =  -0.879252
    [1, 2]  =  -0.23831
    [4, 2]  =  -0.904064
    [3, 3]  =  0.721235
    [4, 3]  =  -0.317153
    [6, 3]  =  1.80547
    [4, 4]  =  0.560326
    [2, 5]  =  0.68588
    [4, 5]  =  0.0368284
    [5, 5]  =  -0.360748
    [2, 6]  =  -0.52084
    [2, 7]  =  0.891165
    [3, 7]  =  -1.13065

The output for the slice operations are:

julia> x[2,:]
1x7 sparse matrix with 3 Float64 entries:
    [1, 5]  =  0.68588
    [1, 6]  =  -0.52084
    [1, 7]  =  0.891165

and

julia> x[:,2]
7x1 sparse matrix with 2 Float64 entries:
    [1, 1]  =  -0.23831
    [4, 1]  =  -0.904064

I.e. it prints 1 instead of 2.

Thanks

@jiahao
Copy link
Member

jiahao commented Apr 9, 2014

?

@alsam alsam changed the title slightly incorrecty slightly incorrect output for sparse matrix Apr 9, 2014
@alsam alsam changed the title slightly incorrect output for sparse matrix slightly incorrect output for sparse matrices when using slices Apr 9, 2014
@alsam
Copy link
Author

alsam commented Apr 9, 2014

Hello Jiahao,

Accidentally my finger slipped when I was in the process of typing, sorry
for it.

I fixed the issue description.

Thanks,
Alexander

On Wed, Apr 9, 2014 at 5:03 PM, Jiahao Chen notifications@github.comwrote:

?

Reply to this email directly or view it on GitHubhttps://github.com//issues/6479#issuecomment-39960790
.

@mschauer
Copy link
Contributor

mschauer commented Apr 9, 2014

What you see is correct, the slice of the sparse 7x7 matrix is a sparse 1x7 respective 7x1 matrix and all the elements in the slice are by definition in its first row respective column.

@mschauer
Copy link
Contributor

mschauer commented Apr 9, 2014

There is a small inconsistency though that column slices of sparse matrices are column matrices and column slices of matrices are vectors.

@nalimilan
Copy link
Member

Maybe that's another argument for not dropping dimensions by default...

@alsam
Copy link
Author

alsam commented Apr 10, 2014

There is a small inconsistency though that column slices of sparse matrices are column matrices
and column slices of matrices are vectors.

Exactly, besides that sum for the slice of sparse matrices returns 1-element Array, but for the slice of dense matrices returns a scalar value.

see the
#6480

@jiahao
Copy link
Member

jiahao commented Apr 22, 2014

There is a small inconsistency though that column slices of sparse matrices are column matrices and column slices of matrices are vectors.

The problem is that Julia currently doesn't support sparse vectors. (sparsevec produces Nx1 SparseMatrixCSCs also.) Ref: #6213.

@jiahao jiahao changed the title slightly incorrect output for sparse matrices when using slices Column slices of sparse matrices should be sparse vectors Apr 22, 2014
@ViralBShah
Copy link
Member

We can support sparse vectors for consistency with the rest of the codebase. So far, I have just been lazy about it - especially since it would be a fair amount of work to make the slightly different data structure work seamlessly all operators and such.

Much less attention has been paid to the consistency of sparse operations. I am going to dive into this again. Perhaps we should have a sparse issue tag.

@ViralBShah
Copy link
Member

That said, we certainly do not have N-d sparse objects, although we probably should, with sorted N-tuple indices and values. I am sure there is an old issue for this somewhere.

@jiahao
Copy link
Member

jiahao commented Apr 23, 2014

we certainly do not have N-d sparse objects, although we probably should, with sorted N-tuple indices and values

The coordinate representation is probably the easiest thing to support beyond rank 2, but we'd have to also support transformations between that and the CSC representation. I do think it's high time we tracked all the sparse array stuff.

@tkelman
Copy link
Contributor

tkelman commented Oct 14, 2015

closed by #13440

@tkelman tkelman closed this as completed Oct 14, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sparse Sparse arrays
Projects
None yet
Development

No branches or pull requests

6 participants