Wed Jun 3 08:40:38 CDT 2009
On Wed, Jun 3, 2009 at 2:17 AM, Pierre GM <email@example.com> wrote:
> On Jun 3, 2009, at 1:09 AM, firstname.lastname@example.org wrote:
>> Given my experience with views, I would prefer to limit them to very
>> local usage, e.g. views on transposed arrays don't work,
> >>> m = np.matrix([1,2,3])
> >>> m.T
> >>> m.T.view(np.ndarray)
> What case did you have in mind ?
there was a thread started by Pauli that inplace operations work on
the base and not the view.
I fell over this case and similar cases:
array([[(1.0, 1.0, 1.0), (1.0, 1.0, 1.0), (1.0, 1.0, 1.0), (1.0, 1.0, 1.0),
(1.0, 1.0, 1.0)]],
dtype=[('f0', '<f8'), ('f1', '<f8'), ('f2', '<f8')])
Traceback (most recent call last):
ValueError: new type not compatible with array.
array([[ 1., 1., 1., 1., 1.],
[ 1., 1., 1., 1., 1.],
[ 1., 1., 1., 1., 1.]])
So until I figure out what can safely be done with views, I avoid time
>>>> And what is the best way to check whether an array is a plain
>>>> and not a subclass instance?
>>> Er, why do you want to do that ?
>> To get fast track for users that deliver already directly usable data,
>> without special type handling. This will be more relevant for
>> stats.models to handle recarrays and masked arrays, and ?
> Mmh. We'll see.
>> If someone gives me this decorator, I will use it, but I don't know
>> how to write a decorator that works for all input and output cases,
>> and doesn't screw up our documentation system.
> Try that.
> def keepthetype(func):
> def wrapped(*args, **kwargs):
> first = args
> if isinstance(first, np.ndarray):
> output_type = type(first)
> output_type = np.ndarray
> output = func(*args, **kwargs)
> if isinstance(output, np.ndarray):
> return output.view(output_type)
> return output
> wrapped.__name__ = func.__name__
> wrapped.__dict__ = func.__dict__
> wrapped.__doc__ = func.__doc__
> return wrapped
Is there a reason that you prefer view(output_type)
which from the help and reading the numpy source seems to be the
Some function have multiple data input (e.g. f_oneway), some functions
have tuple output where some or all tuple elements need to be wrapped
(e.g. np.linalg.svd or stats.describe)
So, a general decorator looks quite complicated, especially if we want
to preserve autocomplete (Paulis comment) and not special case all
different kinds of inputs and outputs, and might need to contain a lot
More information about the Scipy-dev