[Numpy-tickets] [NumPy] #299: Downcast unsafe when using array protocol?
NumPy
numpy-tickets at scipy.net
Thu Sep 28 11:40:17 CDT 2006
#299: Downcast unsafe when using array protocol?
------------------------+---------------------------------------------------
Reporter: faltet | Owner: somebody
Type: defect | Status: new
Priority: normal | Milestone: 1.0 Release
Component: numpy.core | Version: devel
Severity: minor | Keywords:
------------------------+---------------------------------------------------
In numpy it seems that downcasting is possible:
{{{
>>> i1 = numpy.array([0,1], dtype='Int8')
>>> i1[...] = numpy.array([8,9], dtype='Int32')
>>> i1
array([8, 9], dtype=int8)
}}}
even if an overflow does occur:
{{{
>>> i1[...] = numpy.array([800,900], dtype='Int32')
>>> i1
array([ 32, -124], dtype=int8)
}}}
However, you cannot do the same with other objects compliant with the
array protocol:
{{{
>>> i1 = numpy.array([0,1], dtype='Int8')
>>> i1[...] = numarray.array([8,9], dtype='Int8')
>>> i1
array([8, 9], dtype=int8) # Good. But...
>>> i1[...] = numarray.array([8,9], dtype='Int16')
Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: array cannot be safely cast to required type
>>> i1[...] = numarray.array([8,9], dtype='Int32')
Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: array cannot be safely cast to required type
}}}
The same happens with Numeric objects and for all kind of downcastings.
It would be nice if numpy could support this feature.
--
Ticket URL: <http://projects.scipy.org/scipy/numpy/ticket/299>
NumPy <http://projects.scipy.org/scipy/numpy>
The fundamental package needed for scientific computing with Python.
More information about the Numpy-tickets
mailing list