Exact semantics of ufunc.reduce

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Exact semantics of ufunc.reduce

einstein.edison
Hello!

I’m trying to investigate the exact way ufunc.reduce works when given a custom dtype. Does it cast before or after the operation, or somewhere in between? How does this differ from ufunc.reduceat, for example?

We ran into this issue in pydata/sparse#191 when trying to match the two where the only thing differing is the number of zeros for sum, which shouldn’t change the result.

Best Regards,
Hameer Abbasi


_______________________________________________
NumPy-Discussion mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/numpy-discussion
Reply | Threaded
Open this post in threaded view
|

Re: Exact semantics of ufunc.reduce

Sebastian Berg
On Fri, 2018-10-12 at 17:34 +0200, Hameer Abbasi wrote:
> Hello!
>
> I’m trying to investigate the exact way ufunc.reduce works when given
> a custom dtype. Does it cast before or after the operation, or
> somewhere in between? How does this differ from ufunc.reduceat, for
> example?
>

I am not 100% sure, but I think giving the dtype definitely casts the
output type. And since most ufunc loops are defined as "ff->f", etc.
that effectively casts the input as well. It might be it casts the
input specifically, but I doubt it.

The cast will occur within the buffering machinery, so the cast is only
done in small chunks. But the operation itself should be performed
using the given dtype.

- Sebastian


> We ran into this issue in pydata/sparse#191 when trying to match the
> two where the only thing differing is the number of zeros for sum,
> which shouldn’t change the result.
>
> Best Regards,
> Hameer Abbasi
>
>
> _______________________________________________
> NumPy-Discussion mailing list
> [hidden email]
> https://mail.python.org/mailman/listinfo/numpy-discussion

_______________________________________________
NumPy-Discussion mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/numpy-discussion

signature.asc (849 bytes) Download Attachment