NArray overflow warning
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?
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.
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.
irb(main):002:0> (NArray.int(300).indgen! > 0).count_true
=> 299
Neat, however, I am still puzzled about NArray's behaviour in the above circumstances.