[Numpy-discussion] What's the most numpythonic way to support multiple types in a C extension?
Wed Jun 27 15:10:13 CDT 2012
Thanks nathaniel, that does tricky...
On Wed, Jun 27, 2012 at 9:25 AM, Nathaniel Smith <email@example.com> wrote:
> On Tue, Jun 26, 2012 at 10:53 PM, John Salvatier
> <firstname.lastname@example.org> wrote:
> > I want to support multiple types in the index_increment function that
> > written here:
> > I need to check that the first argument's type can support addition, cast
> > the dataptr to the appropriate type and do the addition operation for
> > type. It looks like some of the numpy code uses .c.src files to do
> > templating. Is that what I want to do here? Is the syntax described
> > somewhere?
> The proper way would be use the ufunc machinery, which already knows
> how to perform addition on arbitrary numpy dtypes... unfortunately
> this may be more complicated than you are hoping :-/.
> Since there's nothing about this operation that is specific to the
> addition operation or to the double type, I guess the ideal API would
> actually be something like, an extra method added to binary ufuncs
> np.add.inplace_indexed(a, idx, b)
> which would be equivalent to
> a[idx] += b
> except that duplicate indices would be handled properly, and it would
> avoid making a copy in the case of fancy indexing. You could look at
> the implementation of ufunc.reduceat
> (numpy/core/src/umath/ufunc_object.c:PyUFunc_Reduceat) for an idea of
> how such fancy ufunc methods can be done.
> (An even more ideal API would find some way to make this work
> naturally with where=, but it's not obvious to me how that would
> NumPy-Discussion mailing list
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the NumPy-Discussion