[Numpy-discussion] Proposal for adding bit_count
Sebastian Berg
sebastian at sipsolutions.net
Tue Aug 3 11:47:59 EDT 2021
On Mon, 2021-08-02 at 13:10 -0700, Stefan van der Walt wrote:
> On Mon, Aug 2, 2021, at 10:50, Sebastian Berg wrote:
> > * Should `np.ndarray.bit_count()` exist? I tend against this;
> > but we should have it on (integer) scalars to mirror the
> > Python `int`.
>
> Should `np.bit_count` exist? Having it on the int* types may be
> sufficient.
Right, we could add it only to the integer scalars mostly for Python
compatibility. The PR suggests to create a ufunc to make the feature
available to typical NumPy code (allow using it with arrays).
>
> > * The return value is currently the same type as the input. That
> > means that: `np.bit_count(uint8)` returns the count as `uint8`
> > while `np.bit_count(int32)` returns it as `int32`, etc.
>
> What is the max value of the count? 64? If so it can go in a uint8.
Yes, uint8 would even work for 128 bit integers. I was a bit unsure
about this, since we rarely create non-default integer arrays unless
prompted, but it is a good option as well.
Cheers,
Sebastian
>
> Stéfan
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at python.org
> https://mail.python.org/mailman/listinfo/numpy-discussion
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: This is a digitally signed message part
URL: <https://mail.python.org/pipermail/numpy-discussion/attachments/20210803/fbe63383/attachment.sig>
More information about the NumPy-Discussion
mailing list