Kim Hansen-5 wrote:
How about making
S = sparse (I, J, SV, M, N, NZMAX)
work for multi dimensional I, J and SV ?
The workaround sparse(I(:), J(:), SV(:)) is easy, but I would like
sparse() to check that the dimensions of I, J, and SV were the same
and then create the sparse matrix also for 3+-dimensional input
matrices.
I'm no sure I understand what you mean. If the size of the matrix is determined by the size of I and J, and I and J are either dense with elements that won't be include in the final matrix and so occupy already much more memory than the final matrix, or they are sparse and you already have the structure of the matrix coded as a sparse matrix and a call to spfun would make more sense
If you are taking the dimensions from the size of I, J and SV, then M and N are useless as well.
I can implement the change, I just want to hear if it is a bad idea before I start coding.
I think taking the dimension of the matrix form I and J is a bad idea, N-dimensional sparse matrices however isn't a bad idea, but I suspect its a lot more work than you realize. Look in liboctave/Sparse.cc at the assign and index methods and realize that you'll basically have to duplicate that or fix it for multidimensional matrices while getting all the corner cases of N-dimensional indexing/assignment correct. So yes I think N-dimensional sparse matrices might be useful, but perhaps not at the cost it would take to do it especially as we can get most of the benefits of N-dimensional sparse matrices with a cell array of sparse matrices and using cellfun.
Regards
David