[NumPy-Tickets] [NumPy] #1761: Inconsistency with type in scalar operations
NumPy Trac
numpy-tickets@scipy....
Tue Mar 8 03:50:46 CST 2011
#1761: Inconsistency with type in scalar operations
--------------------+-------------------------------------------------------
Reporter: faltet | Owner: somebody
Type: defect | Status: new
Priority: normal | Milestone: Unscheduled
Component: Other | Version: devel
Keywords: |
--------------------+-------------------------------------------------------
I'm getting different behaviour with type comparison in scalar operations
between 1.5.1 and 1.6. Here it is code that shows the issue:
{{{
import numpy as np
print "numpy-->", np.__version__
r1 = np.array(8L)
print "r1-->", `r1`, r1.dtype
r1 = r1[()]
print "r1(2)-->", `r1`, r1.dtype
f = long(3)
g = np.int16(2)
r2 = f+g # assertion fails only with 1.6
#r2 = g+f # assertion fails with 1.5.1 too
print "r2-->", `r2`, r2.dtype
print "types-->", type(r1), type(r2)
assert type(r1) is type(r2)
}}}
Output when using 1.5.1:
{{{
numpy--> 1.5.1
r1--> array(8L) int64
r1(2)--> 8 int64
r2--> 5 int64
types--> <type 'numpy.int64'> <type 'numpy.int64'>
}}}
When using 1.6 (master):
{{{
numpy--> 1.6.0.dev-c081ad7
r1--> array(8L) int64
r1(2)--> 8 int64
r2--> 5 int64
types--> <type 'numpy.int64'> <type 'numpy.int64'>
Traceback (most recent call last):
File "/tmp/scalar-types.py", line 17, in <module>
assert type(r1) is type(r2)
AssertionError
}}}
Interestingly, if we change the order of the operation:
{{{
r2 = g+f
}}}
the resulting type also differs with 1.5.1:
{{{
numpy--> 1.5.1
r1--> array(8L) int64
r1(2)--> 8 int64
r2--> 5 int64
types--> <type 'numpy.int64'> <type 'numpy.int64'>
Traceback (most recent call last):
File "/tmp/scalar-types.py", line 17, in <module>
assert type(r1) is type(r2)
AssertionError
}}}
--
Ticket URL: <http://projects.scipy.org/numpy/ticket/1761>
NumPy <http://projects.scipy.org/numpy>
My example project
More information about the NumPy-Tickets
mailing list