shunwang / numexpr

Automatically exported from code.google.com/p/numexpr
MIT License
0 stars 0 forks source link

float constant changes to integer in a**-1.0 #71

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
This issue is related to issue 59.

evaluate('a**-1.0') differs from numpy's a**-1.0

More generally, observe:

print 'NumPy:', np.__version__, 'NumExpr:', ne.__version__
a = np.array([2,4], dtype=np.int16)
for e in np.arange(-2.0, 5.0):
    s = 'a**{}'.format(e)
    print '{:9} {:34} {:20}'.format(s, repr(eval(s)), repr(ne.evaluate(s)))

The result is
NumPy: 1.6.0 NumExpr: 2.0.1
a**-2.0   array([ 0.25  ,  0.0625])          array([0, 0])       
a**-1.0   array([ 0.5 ,  0.25])              array([0, 0])       
a**0.0    array([ 1.,  1.])                  array([1, 1])       
a**1.0    array([ 2.,  4.])                  array([2, 4])       
a**2.0    array([ 4, 16], dtype=int16)       array([ 4, 16])     
a**3.0    array([  8.,  64.])                array([ 8, 64])     
a**4.0    array([  16.,  256.])              array([ 16, 256])

It seems that NumPy makes the result float, since one of the operands is float 
(with the exception of the exponent 2.0, which seems to be a bug).
NumExpr should be consistent with this.

Original issue reported on code.google.com by ka...@ucw.cz on 30 Jan 2012 at 3:37

GoogleCodeExporter commented 9 years ago
Let me add the the issue for a ** 2.0 is filed as 
http://projects.scipy.org/numpy/ticket/2033

Original comment by ka...@ucw.cz on 30 Jan 2012 at 4:16

GoogleCodeExporter commented 9 years ago
We'll see what we can do about it.

Original comment by gdemen...@gmail.com on 31 Jan 2012 at 9:08