[Numpy-discussion] masked ufuncs in C: on github

Charles R Harris charlesr.harris at gmail.com
Fri May 15 23:06:31 EDT 2009


On Fri, May 15, 2009 at 7:48 PM, Eric Firing <efiring at hawaii.edu> wrote:

>
> http://www.mail-archive.com/numpy-discussion@scipy.org/msg17595.html
>
> Prompted by the thread above, I decided to see what it would take to
> implement ufuncs with masking in C.  I described the result here:
>
> http://www.mail-archive.com/numpy-discussion@scipy.org/msg17698.html
>
> Now I am starting a new thread. The present state of the work is now in
> github:  http://github.com/efiring/numpy-work/tree/cfastma
>
> I don't want to do any more until I have gotten some feedback from core
> developers.  (And I would be delighted if someone wants to help with
> this, or take it over.)
>

Here the if ... continue needs to follow the declaration:

        if (*mp1) continue;
        float in1 = *(float *)ip1;
        float in2 = *(float *)ip2;
        *(float *)op1 = f(in1, in2);

I think this would be better as

        if (!(*mp1)) {
            float in1 = *(float *)ip1;
            float in2 = *(float *)ip2;
            *(float *)op1 = f(in1, in2);
        }


But since this is actually a ternary function, you could define new
functions, something like

double npy_add_m(double a, double b, double mask)
{
    if (!mask) {
        return a + b;
    else {
        return a;
    }
}

And use the currently existing loops. Well, you would have to add one for
ternary functions.

Question, what about reduce? I don't think it is defined defined for ternary
functions. Apart from reduce, why not just add, you already have the mask to
tell you which results are invalid.

Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20090515/64250623/attachment.html>


More information about the NumPy-Discussion mailing list