Skip to main content

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

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

asarray() and 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)

Note that allow_input() does not affect for arf(), arb(), acb() constructors, but only for np.asarray() and flarray().

str input

One can input str to asarray(). If dtype is not specified, it will be automatically detected as arb. However, specifying dtype explicitly is recommended.

asarray(dtype=acb)

asarray() does not support separated input for real and imaginary parts.

Do the following instead, as acb(1j) is exact.

from flint import arb, acb
from numpy_flint_arb import np

with pytest.raises(Exception):
    # python-flint does not support single argument str input for acb
    np.asarray("[0.5 +/- 0.001] + [0.5 +/- 0.001]j", dtype=acb)
with pytest.raises(Exception):
    # This is inexact and raises an error without allow_input()
    np.asarray(0.5 + 0.5j, dtype=acb)
with pytest.raises(Exception):
    # Mixing complex and arb is not supported by python-flint
    np.asarray("0.5 +/- 0.001", dtype=arb) + 1j * np.asarray("0.5 +/- 0.001", dtype=arb)
>>> # This is possible but not recommended
>>> np.asarray("0.5 +/- 0.001", dtype=arb) + 1j * np.asarray("0.5 +/- 0.001", dtype=acb)
flarray([0.50 +/- 1.01e-3] + [0.50 +/- 1.01e-3]j,
        dtype=<class 'flint.types.acb.acb'>)
>>> # Recommended
>>> np.asarray("0.5 +/- 0.001", dtype=arb) + acb(1j) * np.asarray("0.5 +/- 0.001", dtype=arb)
flarray([0.50 +/- 1.01e-3] + [0.50 +/- 1.01e-3]j,
        dtype=<class 'flint.types.acb.acb'>)

fft submodule

Some fft functions are implemented.

>>> np.fft.fft(np.arange(1, stop=4))
flarray([6.00000000000000,
         -1.50000000000000 + [0.86602540378444 +/- 1.96e-15]j,
         -1.50000000000000 + [-0.86602540378444 +/- 1.96e-15]j],
        dtype=<class 'flint.types.acb.acb'>)

linalg submodule

Some linalg functions are implemented.

>>> A = np.asarray([[1, 2], [3, 4]], dtype=arb)
>>> np.linalg.inv(A)
flarray([[[-2.00000000000000 +/- 1.63e-15],
          [1.00000000000000 +/- 7.41e-16]],
         [[1.50000000000000 +/- 9.44e-16],
          [-0.500000000000000 +/- 4.17e-16]]],
        dtype=<class 'flint.types.arb.arb'>)

Internally 2 functions tomat() and frommat() are added to treat flarray as array of arb_mat / acb_mat, so that we can perform matrix operations like np.linalg.solve on flarray.

random submodule

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.

special submodule

Some scipy.special functions are implemented.

>>> np.special.jv(np.arange(2), arb(1))
flarray([[0.765197686557966 +/- 6.11e-16],
         [0.440050585744933 +/- 5.55e-16]],
        dtype=<class 'flint.types.acb.acb'>)

What it does

  • This package adds a flarray which subclasses ndarray 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.

  • 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.

  • Currently dtype of resulting flarray is inferred from type(output.flat[0]). If the output array is empty or its element type is inconsistent, the result will be inaccurate.

    >>> (np.asarray([0], dtype=arb) * acb(1j)).dtype
    <class 'flint.types.acb.acb'>
    >>> (np.asarray([], dtype=arb) * acb(1j)).dtype
    <class 'flint.types.arb.arb'>
    

Contributors ✨

Thanks goes to these wonderful people (emoji key):

34j
34j

💻 🤔 📖

This project follows the all-contributors specification. Contributions of any kind welcome!

Credits

Copier

This package was created with Copier and the browniebroke/pypackage-template project template.

Metadata

Release files for numpy-flint-arb 1.5.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for numpy-flint-arb 1.5.3
File Size Uploaded
numpy_flint_arb-1.5.3.tar.gz 18.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for numpy-flint-arb 1.5.3
File Interpreter ABI Platform
numpy_flint_arb-1.5.3-py3-none-any.whl Python 3 none any Details

Total release size: 31.4 kB

Release files / numpy_flint_arb-1.5.3.tar.gz

Download URL numpy_flint_arb-1.5.3.tar.gz
Size 18.3 kB
Tags Source
SHA-256 checksum
How to use checksums
23537085bbacd932286fe19ef475e5346ac2ef1439ed1c9f1274af94a069b70e
BLAKE2b-256 checksum
How to use checksums
943930be3d6bb7430f651f8675bab9de469838699c3ea09cee5c4ffaac18bc4e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 26, 2026.

Transparency log

Release files / numpy_flint_arb-1.5.3-py3-none-any.whl

Download URL numpy_flint_arb-1.5.3-py3-none-any.whl
Size 13.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
30485c4911cfa9ff2164f72d1f65f8ea626bfd32be4449ec08eccfff89447e10
BLAKE2b-256 checksum
How to use checksums
6c6f32a5ccdfc7a68db6b214c1fe387fe5c86a4cf32d288f3d2c65599a006164
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 26, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

1.5.3 This release

2 release files

1.5.2

2 release files

1.5.1

2 release files

1.5.0

2 release files

1.4.1

2 release files

1.4.0

2 release files

1.3.0

2 release files

1.2.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page