[Numpy-discussion] Fix to #789 maybe not right.

David Cournapeau david@ar.media.kyoto-u.ac...
Wed May 21 21:56:35 CDT 2008


Charles R Harris wrote:
> David,
>
> I'm not sure that fix is completely correct. The out keyword is funny 
> and I'm not what the specs are supposed to be, but generally the 
> output is cast rather than an error raised. 

I think the out argument is one of this thing which is rather a mess 
right now in numpy. The functions which accept it do not always mention 
it, and as you say, there are various different behaviour.

What are the uses of the out argument ? The obvious one is saving 
memory, but are there others ? Automatic casting would break the memory 
saving.

> We need an official spec here because the documentation of this 
> feature is essentially random. Note that the shapes don't really have 
> to match, either.
>
> In [1]: x = ones(5)
>
> In [2]: out = ones(5, dtype=int8)
>
> In [3]: cumsum(x, out=out)
> Out[3]: array([1, 2, 3, 4, 5], dtype=int8)

I don't feel like this should work (because of the dtype).

>
> In [4]: out = empty((5,1))
>
> In [5]: cumsum(x, out=out)
> Out[5]:
> array([[ 1.],
>        [ 2.],
>        [ 3.],
>        [ 4.],
>        [ 5.]])
>
> OTOH, out = empty((1,5)) doesn't work but doesn't raise an error. 

Not working and no error is obviously wrong. Note that after playing a 
bit with this, I got segfaults when exciting python (I am working on 
reproducint it).

cheers,

David


More information about the Numpy-discussion mailing list