micropython-ulab
micropython-ulab copied to clipboard
[FEATURE REQUEST] Implement `unpackbits()`
Are there plans to implement unpackbits()?
And what are good practices for getting the same result fast while unpackbits() is not implemented?
I'd like to use the resulting bits as Boolean indices into a constant integer array X or do np.nditer(np.nonzero(X)) or whatever is fastest for achieving the same effect.
Here is unpack_bits() in numpy/numpy/_core/src/multiarray/compiled_base.c
Ha! I actually thought of this a while ago, but then I didn't see any immediate use, so I didn't pursue the idea. If you think it's useful, we could definitely add this.
It would be useful.
Maybe we can even forgo the overhead of the parameter checks that NumPy does, or at least do "memoization" so that those checks are performed only once instead of in each call?
Maybe we can even forgo the overhead of the parameter checks that NumPy does, or at least do "memoization" so that those checks are performed only once instead of in each call?
That would break numpy-compatibility. If you're concerned about the keyword arguments, then we should do this in utils and not as a standard numpy function. We could simply define a class, and then unpack_bits could be a method of that class. That would save the time of the parameter checks.
That would break
numpy-compatibility. If you're concerned about the keyword arguments, then we should do this inutilsand not as a standardnumpyfunction.
That would save the time of the parameter checks.
Sounds good. Such "lean" versions of functions are particularly welcome in ulab for several reasons:
- arrays are on average smaller in ulab than in NumPy, so parameter checks occupy a larger percentage of runtime,
- parameter checks are on average slower on microprocessors, so forgoing them saves quite some time,
- many other operations are also slower on microprocessors, so reducing the runtime makes the overall runtime more acceptable.
unpackbits isn't urgent for me at the moment.