Repository navigation
Conversation
|
Documentation changes are missing, will leave those out until we have fully defined what the behavior should be. |
This PR adds a bincount_dispatch function to arraytypes.c.src, that can perform a weighted bincount for most of the native types, and uses it in arr_bincount. This is notably different from the current behavior, that always casts weights to npy_double. The new behavior is: * The output is of the same type as weights (but in native byte order), but (unsigned) integer types and bools are promoted to at least a (unsigned) long, the same type promotion in np.su. * Works for complex arrays, probably the main use case. * Has no fallback for non-native types. Perhaps we should still attempt to cast the input to double if the first call fails? I have also added the possibility of broadcasting weights, i.e. if it is a scalar or a single item array, it will work with any size list. And contiguous arrays are no longer required, everything can work without a copy if the arrays are aligned and in native byte order.
63c069a to
941baf0
Compare
|
As per the mailing list discussion, I have now added integer type promotion to at least a C long. |
| npy_half_to_float(*w)); | ||
| #elif @iscomplex@ | ||
| o[0] += w[0]; | ||
| o[1] += w[1]; |
There was a problem hiding this comment.
Is this correct for npy_bool? Or should we be doing *o += (*w != 0)?
There was a problem hiding this comment.
I think it should be correct pretty much always, but most of the ufunc code guards it, so I would say guard it here as well. If you view an array as bool, I am not sure this might not break, if you astype it, I think it probably will but....
There was a problem hiding this comment.
Didn't read it really, but I would prefer some extra test with strided weights though not sure how settled the overall discussion was.
|
Maybe there could be a |
|
☔ The latest upstream changes (presumably #8109) made this pull request unmergeable. Please resolve the merge conflicts. |
|
Should be pretty easy to rebase. |
|
@jaimefrio, it appears that you have abandoned this pull request. I'm closing it now, but don't hesitate to reopen it if you resume working on it. |
This PR adds a bincount_dispatch function to arraytypes.c.src,
that can perform a weighted bincount for most of the native types,
and uses it in arr_bincount. This is notably different from the
current behavior, that always casts weights to npy_double. The new
behavior is:
byte order). There is no type promotion, like in np.sum, so
overflow in the output is very likely for small integer types.
overflow behaviors.
attempt to cast the input to double if the first call fails?
I have also added the possibility of broadcasting weights, i.e. if
it is a scalar or a single item array, it will work with any size
list.
And contiguous arrays are no longer required, everything can work
without a copy if the arrays are aligned and in native byte order.