An open API service indexing awesome lists of open source software.

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

Awesome Lists containing this project

README

          

# numpy-flint-arb



CI Status


Documentation Status


Test coverage percentage




uv


Ruff


pre-commit




PyPI Version

Supported Python versions
License

---

**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)):



34j
34j

💻 🤔 📖

This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!

## Credits

[![Copier](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/copier-org/copier/master/img/badge/badge-grayscale-inverted-border-orange.json)](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.