QuadDtype Wishlist
Opened this issue · 14 comments
This is my personal list of patches around numpy-quaddtype that I currently have in my own project that I'd like to fix upstream - I will work on most of them myself and will reach out if I need help with some:
Constants
- expose precision: could just be hardcoded to 33, the precision of np.float128 on a platform with native float128 support #132
Ufuncs
- sign ufunc: implemented in #122
- sinh, cosh, tanh, asinh, acosh, atanh ufuncs: implemented in #128
- fix mod ufunc: fixed in #125
- isnan, isinf, isfinite ufuncs: implemented in #121
- nextafter and spacing ufuncs: implemented in #190 and #191
Dtype
- support
np.issubdtype(dtype, np.floating): implemented in #165 - finfo support: implemented in #165
- nan_to_num ufunc: depends on finfo support
- custom dtype kind character, not
'\0', tracked in #110, not yet possible
Binary
- cast to an equal-sized unsigned integer type
It'd also be nice to have proper API docs for the Python API generated by e.g. Sphinx. We should also make sure there are docstrings (preferably doctested in CI) on the full public Python API.
Once we get to writing documentation, we should also document the guaranteed rounding error in ULPs for each operation - thankfully SLEEF documents it fully - since people who need float128, myself included, then likely also care about rounding errors
@ngoldbaum @SwayamInSync Would it be possible to implement np.issubdtype(dtype, np.floating) support by making QuadPrecision a subclass of np.floating? While something like finfo would still be blocked on other issues, it would still be an improvement
It is possible and we did that back when it is in early development, and it leads to some issues like np.finfo got populated with the float64 properties, which later leads to some precision issues in tests
I encourage you both to not think of NumPy as a static thing that can't be changed or fixed. We should definitely make finfo play nicer with user dtypes, it'll just take some work inside NumPy to get that going. Happy to mentor on contributing to NumPy.
it'll just take some work inside NumPy to get that going. Happy to mentor on contributing to NumPy.
Yes after fixing the packaging and setting things up on conda-forge, I'll be studying the DType API more on extending to these ideas. AFAIK JAX team also got these issues and they are using monkey patching for this. We can do that too but it'll be ugly
@SwayamInSync Could we add a test for np.nan_to_num now working (since you added finfo support)?
@SwayamInSync Is it still true that the dtype character will be '\0'?
@SwayamInSync Could we add a test for np.nan_to_num now working (since you added finfo support)?
It works but array printing is having some issues, the operation itself works. I'll keep this in mind and debug
@SwayamInSync Is it still true that the dtype character will be
'\0'?
the kind is '\x00'
@SwayamInSync Could we add a test for np.nan_to_num now working (since you added finfo support)?
It works but array printing is having some issues, the operation itself works. I'll keep this in mind and debug
It'll work but in the environment following this has to be set
np.set_printoptions(formatter={'float_kind': lambda x: str(x)})Otherwise the operation will properly work, its just you can't be able to print it
having a numpy_quaddtype.__version__ would be nice
Are there any plans for implementing all and any yet? Because I noticed that calling QuadPrecision(1).{all,any}() raises a UFuncTypeError at the moment.
Are there any plans for implementing
allandanyyet? Because I noticed that callingQuadPrecision(1).{all,any}()raises aUFuncTypeErrorat the moment.
Because they underline call the logical_and and logical_or ufunc with <class 'numpy.dtypes.BoolDType'>, <class 'numpy_quaddtype.QuadPrecDType'>) -> <class 'numpy.dtypes.BoolDType'>
BUT currently those ufunc are only set to accept the arguments of type {&QuadPrecDType, &QuadPrecDType, &PyArray_BoolDType}
Thanks a lot for noticing this case, I'll fix it