[Numpy-discussion] Should non ufunc numpy functions behave like ufunc regarding casting to output argument ?

Charles R Harris charlesr.harris at gmail.com
Mon Jan 15 21:17:31 CST 2007


On 1/15/07, A. M. Archibald <peridot.faceted at gmail.com> wrote:
>
> On 15/01/07, David Cournapeau <david at ar.media.kyoto-u.ac.jp> wrote:
> > Hi,
> >
> >     I am trying to add support for out argument to one C function using
> > numpy API (still the clip function). I was wondering about the expected
> > behaviour when out does not have the "expected" type.
> >     For example, using again the clip function (but the question is not
> > specific to this function)
> >
> > In [1]: import numpy
> >
> > In [2]: a = numpy.linspace(0, 10, 101)
> >
> > In [3]: b = numpy.zeros(a.shape, dtype = numpy.int32)
> >
> > In [4]: print a.dtype
> > float64
> >
> > In [5]: a.clip(0.1, 0.5, b)
> >
> >     Should this be equivalent to b = a.clip(0.1, 0.5); b =
> > b.astype(numpy.int32) (ie, the casting is done at the end, similar to an
> > ufunc) ?
>
> 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.

Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/numpy-discussion/attachments/20070115/ee0c6987/attachment.html 


More information about the Numpy-discussion mailing list