Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NArray overflow warning #16

Open
maasha opened this issue Mar 7, 2012 · 4 comments
Open

NArray overflow warning #16

maasha opened this issue Mar 7, 2012 · 4 comments

Comments

@maasha
Copy link

maasha commented Mar 7, 2012

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?

@masa16
Copy link
Owner

masa16 commented Mar 7, 2012

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.

@maasha
Copy link
Author

maasha commented Nov 19, 2014

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.

@masa16
Copy link
Owner

masa16 commented Nov 20, 2014

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

@maasha
Copy link
Author

maasha commented Nov 20, 2014

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants