Thanks to visit codestin.com
Credit goes to github.com

Skip to content

ENH: 4,5,6 bit ints #17574

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
IchiruTake opened this issue Oct 15, 2020 · 2 comments
Closed

ENH: 4,5,6 bit ints #17574

IchiruTake opened this issue Oct 15, 2020 · 2 comments

Comments

@IchiruTake
Copy link

Feature

Can numpy create a new data type using 4 bits, 5 bits or 6 bits such as np.int4, np.int5, np.int6, np.uint4, np.uint5, np.uint6.
Thank you.

@mattip
Copy link
Member

mattip commented Oct 15, 2020

Realistically, NumPy is not likely to support this internally but a third-party package could use the hooks in NumPy to supply this. I would be curious how they deal with the performance problems with non-byte aligned arrays: either they would need to "waste" memory and throw away the other bits to align these on byte borders, or use some bit twiddling in __getitem__ and __setitem__. See also gh-14753, gh-12888

@mattip mattip changed the title New data type recommendation ENH: 4,5,6 bit ints Oct 15, 2020
@seberg
Copy link
Member

seberg commented Nov 6, 2021

Closing, this is not going to happen in NumPy. An extension (not within NumPy itself) may decide to do this, and I think certain bit-sizes are actually fairly common in certain fields!
Truly bit-sized datatypes are problematic though, since they don't match NumPy's byte-strided memory model.

(I have some hope we could extend support for this for bit sized DTypes. But NumPy itself would have to always use them padded to full bytes for the foreseeable future.)

In any case, it seems far enough of a "Wish List" item, that I am going to close it.

@seberg seberg closed this as completed Nov 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants