-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Fix sparse matrix nits, and make sparse matrix construction fail if zero(Tv) not defined #11408
Conversation
A = zeros(Tv, S.m, S.n) | ||
# Handle cases where zero(Tv) is not defined but the array is dense. | ||
# (Should we really worry about this?) | ||
A = length(S) == nnz(S) ? Array(Tv, S.m, S.n) : zeros(Tv, S.m, S.n) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was one of the issues reported in #9917 so I "fixed" it, but I'm not sure we should even allow creating a SparseMatrix of a type without zero
defined.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That seems reasonable.
Added an error in the SparseMatrixCSC constructor if the value type has no defined |
Related PR, that I closed without merging: #9325 |
97a0a32
to
c590f00
Compare
@lindahua Could you give some examples? It would seem that it should be straightforward to provide a http://www.mit.edu/~kepner/pubs/JuliaSemiring_HPEC2013_Paper.pdf It could very well be that if you care about having some of these things working, you should provide |
I have sparse matrices with |
Has anybody thought about making this more general? Instead of looking for |
This is actually about a more fundamental problem than just the It is about the concept of sparse array (or sparse matrix). We have two options:
Implementing this concept is very simple -- just have
The only method that I can conceive that may be made to work for such arrays is function full(A::SparseMatrixCSC{T}, emptyval::T)
# ...
end
full{T<:Number}(A::SparseMatrixCSC{T}) = full(A, zero(T)); You don't need to define I guess @ViralBShah might be interested in using a sparse matrix as a graph. In those cases, we don't need to have for s in vertices(g)
# ...
for t in neighbors(g, s)
end
end For such type of algorithms, what you really need is just a way to quickly give you the list of nonzeros of a certain column (or row), and you don't need to bother with those that are not stored. (With the CSC format, this can be efficiently done). |
It is very important to note that the primary purpose of sparse storage is to make it possible to have algorithms with complexity The only method that needs to scan all elements is |
For non-numerical applications, I'd think the primary purpose of sparse storage is to save memory, accepting O(log n) (n = num not null) time instead of O(1) to find a particular field in a row... |
Would you not want to use a hash table in such cases? |
Indexing and traversal of the stored values works fine too. There are several contexts where I'm putting objects in a sparse matrix that are numberlike containers but not |
So it sounds like we don't want to restrict SparseMatrixCSC to types with |
2fedc27 looks fine and non-controversial |
c590f00
to
2fedc27
Compare
Fix sparse matrix nits, and make sparse matrix construction fail if zero(Tv) not defined
backported in c8804e8 |
No description provided.