mixle.engines.highprec module

Arbitrary-precision tail of the spectrum: fp128, fp256, fp512, fp1024, … fp(any bits).

The pure-numpy error-free-transform path (mixle.engines.extended) tops out near double-double (fp128) / quad-double (fp256); beyond that the renormalization cost explodes and MPFR is the compute (per the design review). This module is the correct backend for that tail, on gmpy2 (C-backed MPFR) with an mpmath fallback. It is honest about cost: gmpy2 is per-object, so array ops are an O(N) Python loop – correct but not fast. The fast version is a Cython batch wrapper that amortizes the per-object crossing (the designed follow-up); for fp <= 256 prefer the vectorized extended path.

So: spectrum coverage is complete (fp1..fp1024+), with the fast pure-numpy backends below fp256 and the correct MPFR backend above it.

available()[source]

True if an arbitrary-precision backend (gmpy2 or mpmath) is importable.

Return type:

bool

hp_array(x, bits)[source]

Convert a float array to an object array of bits-bit arbitrary-precision numbers.

Parameters:
Return type:

ndarray

hp_to_float(obj)[source]

Round an arbitrary-precision object array back to float64.

Parameters:

obj (Any)

Return type:

ndarray

hp_sum(x, bits)[source]

Sum a float array at bits mantissa precision (correct beyond what float64 / double-double give).

O(N) per-object MPFR adds – correct but not vectorized; for large N below fp256 prefer mixle.engines.extended.dd_sum(). Returns the float64-rounded result.

Parameters:
Return type:

float

class HighPrecisionFormat(bits)[source]

Bases: object

An arbitrary bits-mantissa float (fp128, fp256, fp512, fp1024, …) – MPFR-backed codec.

Round-trips a float64 array losslessly (its 52 bits fit), and represents more than float64 when fed exact/high-precision values. max_rel_error == 2**-bits.

Parameters:

bits (int)

property max_rel_error: float
quantize(x)[source]
Parameters:

x (Any)

Return type:

ndarray

dequantize(q)[source]
Parameters:

q (Any)

Return type:

ndarray

round_trip(x)[source]
Parameters:

x (Any)

Return type:

ndarray