Closed GoogleCodeExporter closed 9 years ago
In fact even 1/a where a is an array will display the issue:
import numexpr
a = [-1, 0, 1]
numexpr.evaluate('1/a')
Original comment by tom.denn...@gmail.com
on 15 Nov 2010 at 3:22
I had the same problem, so I fixed the issue with this small patch. It
introduces the same behavior than numpy for those situations, that is: x/0
gives 0 (when x is an integer). Ideally this should be configurable, but
getting 0 is already much better than a crash.
Original comment by gdemen...@gmail.com
on 16 Nov 2010 at 9:26
Attachments:
Interesting. I see the issue only happens with ints. I didn't realize that
before. My version of numpy, however, seems to give different results. It
seems to give a large negative number for 1/0 which i guess is some attempt at
replicating the "1/0 = inf" that you get for floats.
I agree that anything would be better than a segfault though. I would,
however, prefer to match numpy if possible.
Thanks so much for you're patch. I really appreciate the help,
Tom
In [10]: a = numpy.array([1, 0, 1])
In [11]: a**(-1)
Out[11]: array([ 1, -9223372036854775808,
1])
Original comment by tom.denn...@gmail.com
on 16 Nov 2010 at 3:01
Fixed in r260.
Thanks!
Original comment by fal...@gmail.com
on 16 Nov 2010 at 4:43
Tom, I don't have python/numpy installed on this machine but both numpy docs
and my recalling of the tests I did a few weeks ago (using straight divisions)
go in the same direction...
http://docs.scipy.org/doc/numpy/reference/generated/numpy.divide.html#numpy.divi
de
The difference probably comes from the optimization that numexpr does IIRC:
a**(-1) -> 1 / a while numpy might use another algorithm. There is an argument
you can pass to evaluate to turn off "optimization", you might want to try that.
Original comment by gdemen...@gmail.com
on 16 Nov 2010 at 7:53
Not clear to me why my install has behavior that doesn't match the docs but any
behavior that isn't a segfault is fine with me. Looks like your patch has
already been included, so i will try it.
Thanks again,
Tom
Original comment by tom.denn...@gmail.com
on 17 Nov 2010 at 3:13
Original issue reported on code.google.com by
tom.denn...@gmail.com
on 15 Nov 2010 at 3:18