narray icon indicating copy to clipboard operation
narray copied to clipboard

NArray overflow warning

Open maasha opened this issue 13 years ago • 4 comments

I just wasted a lot of time tracking down a mistake I made: overflowing a byte NArray. Narray overflows without raising any errors - a typical C thing. Can we have an overflow warning? If this impairs performance, perhaps we can invoke some debug pragma?

maasha avatar Mar 07 '12 09:03 maasha

The current release version of NArray does not support error/warning handling in the course of calculation, because it requires an amount of new design and development. How do we switch behaviours? Where is the error information recorded? How do we treat partially calculated array? The future version of NArray may support such features.

masa16 avatar Mar 07 '12 10:03 masa16

I am struggling with this issue again (I think):

irb(main):001:0> require 'narray'
=> true
irb(main):002:0> (NArray.int(300).indgen! > 0).sum
=> 43

Please explain to me why this is not returning 299 as expected?

PS

If I am indeed overflowing some 256 char value, I would expect that it could be fixed by converting to an integer array:

irb(main):003:0> (NArray.int(300).indgen! > 0).to_i.sum
=> 43

alas, same wrong result. It seems that byte NArray cannot be converted to int NArray? (no warning no nothing):

irb(main):005:0> NArray.byte(10).to_i
=> NArray.byte(10):
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
irb(main):006:0> NArray.float(10).to_i
=> NArray.int(10):
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]

PPS

There are probably a number of different ways to solve the problem like:

irb(main):004:0> (NArray.int(300).indgen!.where > 0).size
=> 299

But I feel that this is actually arriving at the result indirectly.

maasha avatar Nov 19 '14 09:11 maasha

irb(main):002:0> (NArray.int(300).indgen! > 0).count_true
=> 299

masa16 avatar Nov 20 '14 20:11 masa16

Neat, however, I am still puzzled about NArray's behaviour in the above circumstances.

maasha avatar Nov 20 '14 20:11 maasha