[Numpy-discussion] Dot in C extension

Charles R Harris charlesr.harris@gmail....
Sun May 25 01:12:55 CDT 2008


On Sat, May 24, 2008 at 11:29 PM, <jordan@math.ucsb.edu> wrote:

> Hi all,
>
> I'm trying to write a Gauss-Seidel function in C++. The function works
> however it is too slow because I'm not using any acceleration for the
> vector multiplication. I'm not really sure how to access the dot function
> in my extension, nor what all the arguments are for.
>
> Is this the right function to use (found in ndarrayobject.h):
>
> typedef void (PyArray_DotFunc)(void *, npy_intp, void *, npy_intp, void *,
>                               npy_intp, void *);
>
> I guess the voids are array objects, the two to be dotted and the output.
> What's the fourth?
>

It's ignored, so 0 (C++) should do.

static void
@name@_dot(char *ip1, intp is1, char *ip2, intp is2, char *op, intp n,
           void *ignore)
{
    register @out@ tmp=(@out@)0;
    register intp i;
    for(i=0;i<n;i++,ip1+=is1,ip2+=is2) {
        tmp += (@out@)(*((@type@ *)ip1)) * \
               (@out@)(*((@type@ *)ip2));
    }
    *((@type@ *)op) = (@type@) tmp;
}

Note that the function may call BLAS in practice, but you can figure the use
of the arguments from the above. Ignore the @type@ sort of stuff, it's
replaced by real types by the code generator.

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


More information about the Numpy-discussion mailing list