https://github.com/34j/numpy-flint-arb
Arbitrary precision floating / ball arithmetic (interval arithmetic) dtype in NumPy / array API
https://github.com/34j/numpy-flint-arb
acb arb arbitrary-precision array-api flint interval-arithmetic mpmath numpy
Last synced: 2 days ago
JSON representation
Arbitrary precision floating / ball arithmetic (interval arithmetic) dtype in NumPy / array API
- Host: GitHub
- URL: https://github.com/34j/numpy-flint-arb
- Owner: 34j
- License: mit
- Created: 2025-12-11T06:24:04.000Z (3 months ago)
- Default Branch: main
- Last Pushed: 2026-02-28T11:23:02.000Z (12 days ago)
- Last Synced: 2026-02-28T15:07:16.805Z (12 days ago)
- Topics: acb, arb, arbitrary-precision, array-api, flint, interval-arithmetic, mpmath, numpy
- Language: Python
- Homepage:
- Size: 216 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Code of conduct: .github/CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# numpy-flint-arb
---
**Documentation**: https://numpy-flint-arb.readthedocs.io
**Source Code**: https://github.com/34j/numpy-flint-arb
---
Arbitrary precision ball arithmetic (interval arithmetic) dtype in NumPy
## Installation
Install this via pip (or your favourite package manager):
```shell
pip install numpy-flint-arb
```
## Usage
Import `numpy_flint_arb.np` instead of `numpy`:
```python
A = np.random.normal(size=(2, 2))
b = np.random.normal(size=(2,))
x = np.linalg.solve(A, b)
b_approx = A @ x
assert np.all(np.contains(b_approx, b))
```
## What it does
- This package adds a `flarray` which [subclasses `ndarray`](https://numpy.org/doc/stable/user/basics.subclassing.html) in order to
- Override `__array_namespace__` to `numpy_flint_arb.np`
- Override `dtype` to return newly added `_fl_dtype` private attribute, since the actual internal dtype `object` cannot be overridden.
- Override `__array_finalize__` as recommended by the NumPy docs to return `flarray` with proper `_fl_dtype` instead of `ndarray` after Numpy operations.
- Partially supports `linalg` and `(scipy.)special` functions.
- Adds `tomat()` and `frommat()` to treat `flarray` as array of `arb_mat` / `acb_mat`, so that we can perform matrix operations like `np.linalg.solve` on `flarray`.
- Does not perform any parallelization to avoid complexity and to fully utilize the great `python-flint` library
- Using `arb_series` and `acb_series` may be faster for additions but this is too hacky.
- Defining custom `dtype` is way too complicated
- Writing C extension would be theoretically also possible but is still too complicated.
- Does not support `in` operator since it tries to convert the return value to bool. Use newly added `np.contains(x, y)` and `np.overlaps(x, y)` instead.
## Contributors ✨
Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!
## Credits
[](https://github.com/copier-org/copier)
This package was created with
[Copier](https://copier.readthedocs.io/) and the
[browniebroke/pypackage-template](https://github.com/browniebroke/pypackage-template)
project template.