[SciPy-dev] scipy.stats._chk_asarray

josef.pktd at gmail.com josef.pktd at gmail.com
Wed Jun 3 01:09:35 EDT 2009


On Wed, Jun 3, 2009 at 12:50 AM, Pierre GM <pgmdevlist at gmail.com> wrote:
>
> On Jun 2, 2009, at 11:09 PM, josef.pktd at gmail.com wrote:
>>> I tried to see if I can introduce a second version _check_asanyarray,
>> that doesn't convert to basic np.array, but I didn't get very far.
>> nanmedian, and nanstd are not easy to convert to work with matrices,
>> nanstd uses multiplication and nanmedian uses np.compress
>
> Well, what about that:
> * convert the inputs to ndarray w/ _chk_asarray
> * compute as usual
> * return a view of the result using the type of the input (using the
> type keyword of view)
> That should work w/ nanmedian. There might be some adjustment to make
> for nanstd (pb of dimensions?)

__array_wrap__  sound very simple, and flexible.
Given my experience with views, I would prefer to limit them to very
local usage, e.g. views on transposed arrays don't work, so I would
have to start to worry about memory layout.

>
>
>>
>> Doing a variation on it seems to work for matrices, see below. I
>> haven't tried it on other array types. This is just a trial balloon to
>> see whether this would make sense for some of the stats functions. It
>> would be relevant mostly for the descriptive statistics, the
>> statistical tests just return test statistics and pvalues, the plan
>> for models is that they get explicit array subclass handling.
>>
>> Is this a good idea to try to work this way?
>
> Have you checked the sources of numpy.ma ? Most of the functions are
> actually instances of some factory class that take  the mask and input
> class into account, something pretty close to your wrapit function.
> I'm just mentioning that because it'd be nice if the new functions
> worked on MaskedArray and its subclasses as well (or at least work in
> the general case, I wouldn't mind taking care of the corner cases)

I have to look again, and I still would like to merge a large number
of the masked, but in many cases it will require more work to see
whether the function makes sense with masked arrays without more
rewriting.
Skipper is looking at different array types and I hope he comes up
with a good solution that can be also used for the stats functions.

>
>
>> And what is the best way to check whether an array is a plain ndarray
>> 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 ?

>
> Oh, about array_priority: could you set it to something higher than 1
> but less than 15 (the current ma.MaskedArray._-array_priority__ ?)

>From the comment by Robert, I concluded that in the case of conflict
the output array type would be set by the input array type with
highest priority. So I wouldn't set the priority except for the choice
of which input type dominates.

Josef



More information about the SciPy-Dev mailing list