Sat 16 Jan 2016 03:31:03 AM UTC, comment #7:
Rik had the right idea with pulling the division by new_nr in sooner. The attached patch does that. It keeps track of the quotient and remainder for i*old_nr divided by new_nr. Because much of this is done in the outer loop, it should be even faster than using the cute floating point code on Wikipedia, as well as being easier to understand (IMHO).
(Just to check my understanding, why was jj calculated as (tmp - ii) / nr? Isn't that equal to tmp/nr, since ii is by definition just the remainder? If not, don't trust my patch :)
I've tested it on 10000 reshapes, and the results appear to be the same as for a full reshape.
This doesn't explain why David Spies was able to do the reshape without a crash in the first place. Perhaps it was just pointing to some relatively safe wrong place initially. I did print out the matrix just to make sure I didn't get the broken pipe that he did.
(file #36055)
|
Wed 13 Aug 2014 05:33:27 PM UTC, comment #2:
I have been taking a look at the problem and the issue is located within the reshape method of Sparse<T> class. In Sparse.cc around line 845:
With an example similar to the David's one, a segfault is obtained just by the time is executed.
b = logical(speye(1000000));
c = reshape(b,200000,5000000);
The problem is the variable tmp, that can become negative due to integer overflowing. In the example old_nr = 1000000 and i take values up to old_nc=1000000. So their product can be greater than 2^30 = 1.0737e+09.
I don't really know how to fix this in a proper way without using 64 bits. Maybe other knows a quick fix.
|
Sat 26 Jul 2014 06:20:19 PM UTC, original submission:
octave:1> b = logical(speye(100000));
octave:2> c = reshape(b,200000,50000);
octave:3> c
c =
Compressed Column Sparse (rows = 200000, cols = 50000, nnz = 100000 [0.001%])
(-148694, 1) -> 1
(-48693, 1) -> 1
(51308, 1) -> 1
(151309, 1) -> 1
(51310, 2) -> 1
(151311, 2) -> 1
(51312, 3) -> 1
(151313, 3) -> 1
(51314, 4) -> 1
(151315, 4) -> 1
(51316, 5) -> 1
(151317, 5) -> 1
(51318, 6) -> 1
(151319, 6) -> 1
(51320, 7) -> 1
(151321, 7) -> 1
(51322, 8) -> 1
(151323, 8) -> 1
(51324, 9) -> 1
warning: broken pipe
octave:4> exit
attempting to save variables to 'octave-workspace'...
panic: Segmentation fault -- stopping myself...
attempting to save variables to 'octave-workspace'...
octave exited with signal 11
|