Tue 18 May 2010 04:10:31 PM UTC, original submission:
Hi,
'cumsum' function seems to give strange results IF the matrix resembles a binary (0/1) matrix AND the cumsum is done to second (2) dimension. It seems to be that cumsum decides to sue binary logic only to second dimension.
octave-3.2.4.exe:31> C = rand(10,12) > 0.4
C =
1 1 0 0 1 1 1 0 1 1 1 0
0 1 0 1 1 1 1 1 1 0 0 0
0 0 1 1 1 0 1 1 0 1 1 0
1 1 0 0 0 1 0 1 1 1 0 1
0 1 0 1 0 1 1 1 0 1 1 0
1 1 1 0 0 0 0 0 1 1 1 0
0 0 1 1 1 1 0 0 1 1 1 1
0 1 1 1 1 0 0 1 0 1 0 1
1 0 1 0 0 1 1 1 0 1 0 1
1 0 1 1 1 1 0 0 1 0 1 1
octave-3.2.4.exe:32> cumsum(C)
ans =
1 1 0 0 1 1 1 0 1 1 1 0
1 2 0 1 2 2 2 1 2 1 1 0
1 2 1 2 3 2 3 2 2 2 2 0
2 3 1 2 3 3 3 3 3 3 2 1
2 4 1 3 3 4 4 4 3 4 3 1
3 5 2 3 3 4 4 4 4 5 4 1
3 5 3 4 4 5 4 4 5 6 5 2
3 6 4 5 5 5 4 5 5 7 5 3
4 6 5 5 5 6 5 6 5 8 5 4
5 6 6 6 6 7 5 6 6 8 6 5
octave-3.2.4.exe:33> cumsum(C,2)
ans =
1 1 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
1 1 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
1 1 1 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
1 0 0 0 0 0 0 0 0 0 0 0
1 0 0 0 0 0 0 0 0 0 0 0
This can be "fixed" if the "binary matrix" is transformed to matrix containing doubles.
octave-3.2.4.exe:34> cumsum(double(C),2)
ans =
1 2 2 2 3 4 5 5 6 7 8 8
0 1 1 2 3 4 5 6 7 7 7 7
0 0 1 2 3 3 4 5 5 6 7 7
1 2 2 2 2 3 3 4 5 6 6 7
0 1 1 2 2 3 4 5 5 6 7 7
1 2 3 3 3 3 3 3 4 5 6 6
0 0 1 2 3 4 4 4 5 6 7 8
0 1 2 3 4 4 4 5 5 6 6 7
1 1 2 2 2 3 4 5 5 6 6 7
1 1 2 3 4 5 5 5 6 6 7 8
octave-3.2.4.exe:35>
Operating system Win 7, 32-bit, all patches installed 5/19/2010. I have rebooted the computer and restarted Octave and this bug is reproducible.
And yes. This might be a feature;-)
|