Arbitrary precision ball arithmetic (interval arithmetic) dtype in NumPy
Project description
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):
pip install numpy-flint-arb
Usage
Import numpy_flint_arb.np instead of numpy:
from numpy_flint_arb import np
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))
Input Check
To avoid mixing ordinary floats like float or np.float, flarray for arb, acb only accepts integers, arb or acb and flarray for arf only accepts integers and arf, arb.
To relax this, allow_input() may be used:
import pytest
from numpy_flint_arb import allow_input
from flint import arb, arf
# arb array
with pytest.raises(Exception):
np.asarray(0.5, dtype=arb)
with pytest.raises(Exception):
with allow_input(float=True):
np.asarray(0.5, dtype=arb)
with allow_input(interval=True, float=True):
np.asarray(0.5, dtype=arb)
# arf array
with pytest.raises(Exception):
np.asarray(0.5, dtype=arf)
with allow_input(float=True):
np.asarray(0.5, dtype=arf)
with allow_input(interval=True, float=True):
np.asarray(0.5, dtype=arf)
Randomness
Since python-flint does not support random number generation, the random module just uses np.random.
Therefore, the return values may not be random up to the precision of arb, acb.
What it does
- This package adds a
flarraywhich subclassesndarrayin order to- Override
__array_namespace__tonumpy_flint_arb.np - Override
dtypeto return newly added_fl_dtypeprivate attribute, since the actual internal dtypeobjectcannot be overridden. - Override
__array_finalize__as recommended by the NumPy docs to returnflarraywith proper_fl_dtypeinstead ofndarrayafter Numpy operations.
- Override
- Partially supports
linalgand(scipy.)specialfunctions. - Adds
tomat()andfrommat()to treatflarrayas array ofarb_mat/acb_mat, so that we can perform matrix operations likenp.linalg.solveonflarray. - Does not perform any parallelization to avoid complexity and to fully utilize the great
python-flintlibrary- Using
arb_seriesandacb_seriesmay be faster for additions but this is too hacky. - Defining custom
dtypeis way too complicated - Writing C extension would be theoretically also possible but is still too complicated.
- Using
- Does not support
inoperator since it tries to convert the return value to bool. Use newly addednp.contains(x, y)andnp.overlaps(x, y)instead.
Contributors ✨
Thanks goes to these wonderful people (emoji key):
34j 💻 🤔 📖 |
This project follows the all-contributors specification. Contributions of any kind welcome!
Credits
This package was created with Copier and the browniebroke/pypackage-template project template.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file numpy_flint_arb-1.3.0.tar.gz.
File metadata
- Download URL: numpy_flint_arb-1.3.0.tar.gz
- Upload date:
- Size: 14.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cc2f67f80df4b1af4a5518e8916326023b21013711d7e1832ed0c387ea3008ff
|
|
| MD5 |
4034468cb9191a3a64ae479c13473c6c
|
|
| BLAKE2b-256 |
35584f596fdd8156a447780764b208198fea7da7fbd77f711d2c1744d66e88df
|
Provenance
The following attestation bundles were made for numpy_flint_arb-1.3.0.tar.gz:
Publisher:
ci.yml on 34j/numpy-flint-arb
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
numpy_flint_arb-1.3.0.tar.gz -
Subject digest:
cc2f67f80df4b1af4a5518e8916326023b21013711d7e1832ed0c387ea3008ff - Sigstore transparency entry: 1078650709
- Sigstore integration time:
-
Permalink:
34j/numpy-flint-arb@b36855fded1fcadd6eea65751a89a8ed811a4370 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/34j
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@b36855fded1fcadd6eea65751a89a8ed811a4370 -
Trigger Event:
push
-
Statement type:
File details
Details for the file numpy_flint_arb-1.3.0-py3-none-any.whl.
File metadata
- Download URL: numpy_flint_arb-1.3.0-py3-none-any.whl
- Upload date:
- Size: 11.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
19b5c0fd4832401aecb24e3a6b092d6046f8187242134cbcfbe419c588ec0a17
|
|
| MD5 |
7023a6a6e9c8c3a540af63f1de6ab1ce
|
|
| BLAKE2b-256 |
1568274164cbaff6c4518493ca360307c2d642bb1188c2f6ef2c1c697a36a998
|
Provenance
The following attestation bundles were made for numpy_flint_arb-1.3.0-py3-none-any.whl:
Publisher:
ci.yml on 34j/numpy-flint-arb
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
numpy_flint_arb-1.3.0-py3-none-any.whl -
Subject digest:
19b5c0fd4832401aecb24e3a6b092d6046f8187242134cbcfbe419c588ec0a17 - Sigstore transparency entry: 1078650732
- Sigstore integration time:
-
Permalink:
34j/numpy-flint-arb@b36855fded1fcadd6eea65751a89a8ed811a4370 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/34j
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@b36855fded1fcadd6eea65751a89a8ed811a4370 -
Trigger Event:
push
-
Statement type: