-
Notifications
You must be signed in to change notification settings - Fork 190
Better integration with numpy #753
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
Comments
Technically, it's not that difficult to make mpmath aligned better with numpy, IMO. The question is the goal and the perspective of the package: whether numpy compatibility will be considered in the future releases. If so, I'm happy to make contributions. At beginning, it is not necessary to integrate every feature of numpy. Upgrading the existing functionalities does not look like too much work. It just needs to make the matrix class a subclass of numpy array, and refactor the relevant linalg and calculas functions following the numpy array APIs. |
mpmath does not depend on numpy so it is not possible to subclass numpy's ndarray. Adding an array API compatible module as an interface within mpmath could be reasonable though. |
It may not be necessary to sublcass numpy array or install numpy. At some point, this NEP https://numpy.org/neps/nep-0041-improved-dtype-support.html#fixed-high-precision-math will be available in numpy. Then the numpy array can provide the functionalities of mp.matrix . In mpmath, functions in the linalg module just need to follow the numpy API conventions. This will allow mpmath linalg functions supporting numpy arrays automatically. For example, one of the simplest change would be to replace the |
That does make sense. Just keep in mind, that linalg functions and the matrix class are part of the mpmath's public API. We should support old attributes for some time, add deprecation warnings, etc. |
The functionalities of mpmath matrix class has overlap with the numpy ndarray class. But matrix class and numpy array class are not compatible. Currently, linalg functions such as
qr
,lu
,norm
can only work with mpmath matrix. It seems not difficult to change the code base to make these functions support numpy arrays.It would be convenient if mpmath matrix and the relevant functions are compatible with numpy arrays. This allows users to use numpy array to manage mpmath.mpf objects, as numpy array has so many functionalities to manipulate array and matrix objects that mpmath matrix does not have.
Will the integration with numpy be considered in the future?
The text was updated successfully, but these errors were encountered: