Metadata-Version: 2.4
Name: numpy-flint-arb
Version: 1.2.1
Summary: Arbitrary precision ball arithmetic (interval arithmetic) dtype in NumPy
Author-email: 34j <34j.95a2p@simplelogin.com>
License-Expression: MIT
Project-URL: Bug Tracker, https://github.com/34j/numpy-flint-arb/issues
Project-URL: Changelog, https://github.com/34j/numpy-flint-arb/blob/main/CHANGELOG.md
Project-URL: documentation, https://numpy-flint-arb.readthedocs.io
Project-URL: repository, https://github.com/34j/numpy-flint-arb
Classifier: Development Status :: 2 - Pre-Alpha
Classifier: Intended Audience :: Developers
Classifier: Natural Language :: English
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Software Development :: Libraries
Requires-Python: >=3.12
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: cm-time>=0.1.2
Requires-Dist: numpy>=2.2.6
Requires-Dist: python-flint>=0.6
Requires-Dist: types-array-api>=1.2
Dynamic: license-file

# numpy-flint-arb

<p align="center">
  <a href="https://github.com/34j/numpy-flint-arb/actions/workflows/ci.yml?query=branch%3Amain">
    <img src="https://img.shields.io/github/actions/workflow/status/34j/numpy-flint-arb/ci.yml?branch=main&label=CI&logo=github&style=flat-square" alt="CI Status" >
  </a>
  <a href="https://numpy-flint-arb.readthedocs.io">
    <img src="https://img.shields.io/readthedocs/numpy-flint-arb.svg?logo=read-the-docs&logoColor=fff&style=flat-square" alt="Documentation Status">
  </a>
  <a href="https://codecov.io/gh/34j/numpy-flint-arb">
    <img src="https://img.shields.io/codecov/c/github/34j/numpy-flint-arb.svg?logo=codecov&logoColor=fff&style=flat-square" alt="Test coverage percentage">
  </a>
</p>
<p align="center">
  <a href="https://github.com/astral-sh/uv">
    <img src="https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/uv/main/assets/badge/v0.json" alt="uv">
  </a>
  <a href="https://github.com/astral-sh/ruff">
    <img src="https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json" alt="Ruff">
  </a>
  <a href="https://github.com/pre-commit/pre-commit">
    <img src="https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white&style=flat-square" alt="pre-commit">
  </a>
</p>
<p align="center">
  <a href="https://pypi.org/project/numpy-flint-arb/">
    <img src="https://img.shields.io/pypi/v/numpy-flint-arb.svg?logo=python&logoColor=fff&style=flat-square" alt="PyPI Version">
  </a>
  <img src="https://img.shields.io/pypi/pyversions/numpy-flint-arb.svg?style=flat-square&logo=python&amp;logoColor=fff" alt="Supported Python versions">
  <img src="https://img.shields.io/pypi/l/numpy-flint-arb.svg?style=flat-square" alt="License">
</p>

---

**Documentation**: <a href="https://numpy-flint-arb.readthedocs.io" target="_blank">https://numpy-flint-arb.readthedocs.io </a>

**Source Code**: <a href="https://github.com/34j/numpy-flint-arb" target="_blank">https://github.com/34j/numpy-flint-arb </a>

---

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

<!-- prettier-ignore-start -->
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
<!-- prettier-ignore-start -->
<!-- markdownlint-disable -->
<table>
  <tbody>
    <tr>
      <td align="center" valign="top" width="14.28%"><a href="https://github.com/34j"><img src="https://avatars.githubusercontent.com/u/55338215?v=4?s=80" width="80px;" alt="34j"/><br /><sub><b>34j</b></sub></a><br /><a href="https://github.com/34j/numpy-flint-arb/commits?author=34j" title="Code">💻</a> <a href="#ideas-34j" title="Ideas, Planning, & Feedback">🤔</a> <a href="https://github.com/34j/numpy-flint-arb/commits?author=34j" title="Documentation">📖</a></td>
    </tr>
  </tbody>
</table>

<!-- markdownlint-restore -->
<!-- prettier-ignore-end -->

<!-- ALL-CONTRIBUTORS-LIST:END -->
<!-- prettier-ignore-end -->

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.
