Slicing in sparse
John W. Eaton
jwe at bevo.che.wisc.edu
Tue Dec 4 09:46:15 CST 2007
On 4-Dec-2007, Søren Hauberg wrote:
| David Bateman skrev:
| > Kim Hansen wrote:
| >> I think it is dangerous to have different rules for sparse and full
| >> matrices combined with the auto conversion from sparse to full.
| >>
| > Is it better to be consistent with full matrices or with matlab? At this
| > point I think it might be better to be consistent with matlab.
| >
| I think this sounds kinda like a bug in matlab. It's a bit odd that
| sparse matrices behave differently then full ones. So, I'd prefer
| consistency with full matrices.
I agree that it seems like odd behavior for
x = ones ([2, 0]); x(1) = 1
to fail, but the idea seems to be that when an operation like
x(idx) = val
forces X to be resized and X starts out empty, Matlab always wants to
create a row vector, and that is only allowed to happen if all the
dimensions are zero, or if there are only two dimensions and the first
dimension is zero or one. You can avoid the error if you specify both
rows and columns in your index. For example,
x = ones ([2, 0]); x(1,) = 1
succeeds.
We have discussed this topic at least once before. Please see this
message:
http://www.nabble.com/unable-to-resize-A-tf4492119.html#a12811565
OTOH, it succeeds with sparse matrices, so maybe the behavior for full
matrices is not intentional. Or, maybe the behavior for sparse
matrices is not intentional. Who knows? If you want to avoid
problems, you could use two indices unless you know the indexed object
can't be empty.
jwe
More information about the Bug-octave
mailing list