DoubleDouble#

Experimental DoubleDouble precision arithmetic in JAX.

class jorbit.utils.doubledouble.DoubleDouble(hi, lo=None)[source]#

Bases: object

An experimental class for ‘DoubleDouble’ precision arthmetic.

This creates a Jax pytree object that stores two jnp.ndarrays, hi and lo, which are the high and low parts of a double-double precision array. Basic arithmetic operations are overloaded to use functions that respect the double-double precision rules. This is not compensated summation, but summation at “DoubleDouble” precision.

Parameters:
  • hi (jnp.ndarray)

  • lo (jnp.ndarray | None)

hi#

High part.

Type:

jnp.ndarray

lo#

(jnp.ndarray): Low part.

classmethod from_string(s)[source]#

Create a DoubleDouble number from a string, similar to mpmath.mpf.

Parameters:

s (str) – String representation of a number.

Returns:

The DoubleDouble representation.

Return type:

DoubleDouble

classmethod tree_unflatten(aux_data, children)[source]#

Implementation for JAX pytree.

Return type:

DoubleDouble

Parameters:
  • aux_data (None)

  • children (tuple)

tree_flatten()[source]#

Implementation for JAX pytree.

Return type:

tuple

property shape: tuple[int, ...]#

Shape of the DoubleDouble array.

jorbit.utils.doubledouble.dd_max(x, axis=None)[source]#

Sort-of implements jnp.max on a DoubleDouble array.

Parameters:
  • x (DoubleDouble) – DoubleDouble array

  • axis (int | None) – Axis to reduce over

Returns:

The maximum value

Return type:

DoubleDouble

jorbit.utils.doubledouble.dd_norm(x, axis=None)[source]#

Sort-of implements jnp.linalg.norm on a DoubleDouble array.

Uses dd_sum and dd_sqrt.

Parameters:
  • x (DoubleDouble) – The DoubleDouble array to take the norm of.

  • axis (int | None) – The axis to take the norm over. If None, the array is flattened.

Returns:

The norm of the array.

Return type:

DoubleDouble

jorbit.utils.doubledouble.dd_sqrt(x)[source]#

Sort-of implements jnp.sqrt on a DoubleDouble array.

Uses sqrt2 from Dekker 1971.

Parameters:

x (DoubleDouble) – The DoubleDouble array to take the square root of.

Returns:

The square root of the array.

Return type:

DoubleDouble

jorbit.utils.doubledouble.dd_sum(x, axis=None)[source]#

Sort-of implements jnp.sum on a DoubleDouble array.

Parameters:
  • x (DoubleDouble) – The DoubleDouble array to sum.

  • axis (int | None) – The axis to sum over. If None, the array is flattened.

Returns:

The sum of the array along the given axis.

Return type:

DoubleDouble