[Numpy-discussion] Should non ufunc numpy functions behave like ufunc regarding casting to output argument ?
A. M. Archibald
peridot.faceted at gmail.com
Mon Jan 15 22:27:59 EST 2007
On 15/01/07, Charles R Harris <charlesr.harris at gmail.com> wrote:
> > Since the point of output arguments is to avoid allocating new
> > storage,
>
>
> If we take that seriously, then an error should be raised on a shape, or
> type mismatch.
In fact:
In [10]: a = zeros(3)
In [11]: b = zeros(4,dtype=uint8)
In [12]: add(a,a,b)
---------------------------------------------------------------------------
exceptions.ValueError Traceback (most
recent call last)
/home/peridot/<ipython console>
ValueError: invalid return array shape
In [13]: add(a,a,b[:3])
Out[13]: array([0, 0, 0], dtype=uint8)
In [14]: add(b,b,b.reshape((2,2)))
---------------------------------------------------------------------------
exceptions.ValueError Traceback (most
recent call last)
/home/peridot/<ipython console>
ValueError: invalid return array shape
We do raise an error on shape mismatch; type mismatches are used to
forcibly cast the result - which is useful! So I'd say we take it
seriously. It's one of the ways to make your code run faster.
A. M. Archibald
More information about the NumPy-Discussion
mailing list