quantax.utils.ScaleArray#
- class quantax.utils.ScaleArray#
Array representation with a scale: value = significand * exp(exponent), where exponent is a normalization factor.
The array is a PyTree with two leaves:
significandandexponent. To convert it to a dense JAX array, usearr.value()orjnp.asarray(arr).Note
The same value can be represented by different (significand, exponent) pairs. For example, (e, 0) and (1, 1) both represent the value e. We don’t enforce a canonical form for better performance.
Warning
JAX doesn’t have a full support for customized arrays, so one should be careful when using
ScaleArray. Here we list several possible problems.1. Manipulations like
jnp.fn(array)transform customized arrays toArray. To avoid it, callarray.fn()whenever possible.2. Computations like
jax_array * customized_arrayalways calljax_array.__mul__(customized_array), which returns aArray. To avoid it, usecustomized_array * jax_array.- __array__(dtype=None) NDArray#
Convert to a numpy array.
- __neg__() ScaleArray#
Negate the represented value.
- __abs__() ScaleArray#
Absolute value of the represented array.
- __mul__(other: ArrayLike) ScaleArray#
Element-wise multiplication.
- __rmul__(other: ArrayLike) ScaleArray#
Reversed element-wise multiplication.
- __truediv__(other: ArrayLike) ScaleArray#
Element-wise division.
- __rtruediv__(other: ArrayLike) ScaleArray#
Reversed element-wise division.
- __pow__(p: float | Array) ScaleArray#
Element-wise power.
- __add__(other: ArrayLike) ScaleArray#
Element-wise addition.
- __radd__(other: ArrayLike) ScaleArray#
Reversed element-wise addition.
- __sub__(other: ArrayLike) ScaleArray#
Element-wise subtraction.
- __rsub__(other: ArrayLike) ScaleArray#
Reversed element-wise subtraction.
- choose(*args, **kwargs) ScaleArray#
Apply
chooseto significand and exponent component-wise.
- compress(*args, **kwargs) ScaleArray#
Apply
compressto significand and exponent component-wise.
- copy(*args, **kwargs) ScaleArray#
Apply
copyto significand and exponent component-wise.
- diagonal(*args, **kwargs) ScaleArray#
Apply
diagonalto significand and exponent component-wise.
- flatten(*args, **kwargs) ScaleArray#
Apply
flattento significand and exponent component-wise.
- ravel(*args, **kwargs) ScaleArray#
Apply
ravelto significand and exponent component-wise.
- repeat(*args, **kwargs) ScaleArray#
Apply
repeatto significand and exponent component-wise.
- reshape(*args, **kwargs) ScaleArray#
Apply
reshapeto significand and exponent component-wise.
- squeeze(*args, **kwargs) ScaleArray#
Apply
squeezeto significand and exponent component-wise.
- swapaxes(*args, **kwargs) ScaleArray#
Apply
swapaxesto significand and exponent component-wise.
- take(*args, **kwargs) ScaleArray#
Apply
taketo significand and exponent component-wise.
- transpose(*args, **kwargs) ScaleArray#
Apply
transposeto significand and exponent component-wise.
- static from_value(x: ArrayLike) ScaleArray#
Create from a JAX array / Python scalar.
- property shape: tuple[int, ...]#
The shape of the represented array.
- property ndim: int#
The number of dimensions of the represented array.
- property size: int#
The total number of elements in the represented array.
- property nbytes: int#
The total number of bytes consumed by the represented array.
- property T: ScaleArray#
Transpose the represented array.
- property mT: ScaleArray#
Matrix transpose of the represented array.
- conj() ScaleArray#
Complex conjugate of the represented value.
- abs() ScaleArray#
Absolute value of the represented array.
- property real: ScaleArray#
Real part of the represented array.
- property imag: ScaleArray#
Imaginary part of the represented array.
- astype(dtype) ScaleArray#
Cast the represented array to given dtype.
- sum(axis: int | tuple[int, ...] | None = None, keepdims: bool = False) ScaleArray#
Sum of array elements over a given axis.
- mean(axis: int | tuple[int, ...] | None = None, keepdims: bool = False) ScaleArray#
Mean of array elements over a given axis.
- prod(axis: int | tuple[int, ...] | None = None, keepdims: bool = False) ScaleArray#
Product of array elements over a given axis.