APyFloatArray

class apytypes.APyFloatArray

Class for multidimensional arrays with configurable floating-point formats.

APyFloatArray is a class for multidimensional arrays with configurable floating-point formats. The interface is much like the one of NumPy, and direct plotting is supported by most functions in Matplotlib. APyFloatArray should always be preferred, if possible, when working with arrays as it allows for better performance, and integration with other features of APyTypes.

For information about the workings of floating-point numbers, see its scalar equivalent APyFloat.

Attributes:
T

The transposition of the array.

bias

Exponent bias.

bits

Total number of bits.

exp_bits

Number of exponent bits.

man_bits

Number of mantissa bits.

ndim

Number of dimensions in the array.

shape

The shape of the array.

Methods

broadcast_to

Broadcast array to new shape.

cast

Change format of the floating-point number.

cast_to_bfloat16

Cast to bfloat16 format.

cast_to_double

Cast to IEEE 754 binary64 (double-precision) format.

cast_to_half

Cast to IEEE 754 binary16 (half-precision) format.

cast_to_single

Cast to IEEE 754 binary32 (single-precision) format.

convolve

Return the discrete linear convolution with another one-dimensional array.

cumprod

Return the cumulative product of the elements along a given axes.

cumsum

Return the cumulative sum of the elements along a given axis.

eye

flatten

Return a copy of the array collapsed into one dimension.

from_array

from_bits

from_float

full

identity

is_identical

Test if two APyFloatArray objects are identical.

max

Return the maximum value from an array or the maximum values along an axis.

min

Return the minimum value from an array or the minimum values along an axis.

nancumprod

Return the cumulative product of the elements along a given axis treating NaN as 0.

nancumsum

Return the cumulative sum of the elements along a given axis treating NaN as 0.

nanmax

Return the maximum value from an array or the maximum values along an axis, ignoring NaN.

nanmin

Return the minimum value from an array or the minimum values along an axis, ignoring NaN.

nanprod

Return the product of the elements along a given axis treating NaN as 0.

nansum

Return the sum of the elements along specified axis/axes treating NaN as 0.

ones

prod

Return the product of the elements along specified axis/axes.

ravel

Return a copy of the array collapsed into one dimension.

reshape

Reshape the APyFloatArray to the specified shape without changing its data.

squeeze

Remove axes of size one at the specified axis/axes, if no axís is given removes all dimensions with size one.

sum

Return the sum of the elements along specified axis/axes.

swapaxes

Interchange two axes of an array.

to_bits

Return the underlying bit representations.

to_numpy

Return array as a numpy.ndarray of numpy.float64.

transpose

Return copy of array with axes transposed.

zeros

Constructor

__init__(self, signs: Sequence, exps: Sequence, mans: Sequence, exp_bits: int, man_bits: int, bias: int | None = None) None

Create an APyFloat object.

Parameters:
signssequence of bools or ints

The sign of the float. False/0 means positive. True/non-zero means negative.

expssequence of ints

Exponents of the floats as stored, i.e., actual value + bias.

manssequence of ints

Mantissas of the floats as stored, i.e., without a hidden one.

exp_bitsint

Number of exponent bits.

man_bitsint

Number of mantissa bits.

biasint, optional

Exponent bias. If not provided, bias is 2**exp_bits - 1.

Returns:
APyFloatArray

Conversion to other types

to_numpy(self) numpy.ndarray[dtype=float64]

Return array as a numpy.ndarray of numpy.float64.

The returned array has the same shape and values as self. This method rounds away from infinity on ties.

Returns:
numpy.ndarray
to_bits(self, numpy: bool = False) list | numpy.ndarray[dtype=uint64] | numpy.ndarray[dtype=uint32] | numpy.ndarray[dtype=uint16] | numpy.ndarray[dtype=uint8]

Return the underlying bit representations.

When numpy is true, the bit representations are returned in a numpy.ndarray. Otherwise, they are returned in a list.

Returns:
list or numpy.ndarray

Creation from other types

from_array(ndarray: ndarray[order='C'], exp_bits: int, man_bits: int, bias: int | None = None) APyFloatArray

Create an APyFloatArray object from an ndarray.

Parameters:
ndarrayndarray

Values to initialize from. The tensor shape will be taken from the ndarray shape.

exp_bitsint

Number of exponent bits in the created floating-point tensor

man_bitsint

Number of mantissa bits in the created floating-point tensor

biasint, optional

Bias in the created floating-point tensor

Returns:
APyFloatArray

Examples

>>> from apytypes import APyFloatArray
>>> import numpy as np

Array a, initialized from NumPy ndarray

>>> a = APyFloatArray.from_array(
...     np.array([
...         [1.0, 2.0, 3.0],
...         [4.0, 5.0, 6.0],
...     ]),
...     man_bits=10,
...     exp_bits=10
... )
from_float(number_sequence: Sequence, exp_bits: int, man_bits: int, bias: int | None = None) APyFloatArray

Create an APyFloatArray object from a sequence of int, float, APyFixed, or APyFloat.

Parameters:
number_sequencesequence of numbers

Floating point values to initialize from. The tensor shape will be taken from the sequence shape.

exp_bitsint

Number of exponent bits in the created floating-point tensor

man_bitsint

Number of mantissa bits in the created floating-point tensor

biasint, optional

Bias in the created floating-point tensor

Returns:
APyFloatArray

Examples

>>> from apytypes import APyFloatArray

Array a, initialized from floating-point values.

>>> a = APyFloatArray.from_float([1.0, 1.25, 1.49], exp_bits=10, man_bits=15)

Array lhs (2 x 3 matrix), initialized from floating-point values.

>>> lhs = APyFloatArray.from_float(
...     [
...         [1.0, 2.0, 3.0],
...         [4.0, 5.0, 6.0],
...     ],
...     exp_bits=5,
...     man_bits=2
... )

Other creation functions

zeros(shape: tuple, exp_bits: int, man_bits: int, bias: int | None = None) APyFloatArray

Initializes an array with zeros.

Parameters:
shapetuple

Shape of the array.

exp_bitsint

Number of exponent bits.

man_bitsint

Number of mantissa bits.

biasoptional

Exponent bias. If not provided, bias is 2**exp_bits - 1.

Returns:
APyFloatArray

An array filled with zeros.

ones(shape: tuple, exp_bits: int, man_bits: int, bias: int | None = None) APyFloatArray

Initializes an array with ones.

Parameters:
shapetuple

Shape of the array.

exp_bitsint

Number of exponent bits.

man_bitsint

Number of mantissa bits.

biasoptional

Exponent bias. If not provided, bias is 2**exp_bits - 1.

Returns:
APyFloatArray

An array filled with ones.

eye(n: int, exp_bits: int, man_bits: int, m: int | None = None, bias: int | None = None) APyFloatArray

Initializes an array with ones on the diagonal.

Parameters:
nint

Number of rows (and columns) in the n x n output.

exp_bitsint

Number of exponent bits.

man_bitsint

Number of mantissa bits.

mint, optional

Number of columns. Default is None, which results in an n x n output.

biasoptional

Exponent bias. If not provided, bias is 2**exp_bits - 1.

Returns:
APyFloatArray

An array with the specified value on the diagonal.

identity(n: int, exp_bits: int, man_bits: int, bias: int | None = None) APyFloatArray

Initializes an identity matrix with ones on the diagonal.

Parameters:
nint

Number of rows (and columns) in the n x n output.

exp_bitsint

Number of exponent bits.

man_bitsint

Number of mantissa bits.

biasoptional

Exponent bias. If not provided, bias is 2**exp_bits - 1.

Returns:
APyFloatArray

An identity matrix with ones on the diagonal.

full(shape: tuple, fill_value: APyFloat) APyFloatArray

Initializes an array filled with the specified value.

Parameters:
shapetuple

Shape of the array.

fill_valueAPyFloat

Value to fill the array.

Returns:
APyFloatArray

An array filled with the specified value.

Change word length

cast(self, exp_bits: int | None = None, man_bits: int | None = None, bias: int | None = None, quantization: QuantizationMode | None = None) APyFloatArray

Change format of the floating-point number.

This is the primary method for performing quantization when dealing with APyTypes floating-point numbers.

Parameters:
exp_bitsint, optional

Number of exponent bits in the result.

man_bitsint, optional

Number of mantissa bits in the result.

biasint, optional

Bias used in the result.

quantizationQuantizationMode, optional.

Quantization mode to use in this cast. If None, use the global quantization mode.

Returns:
APyFloat

Comparison

is_identical(self, other: APyFloatArray) bool

Test if two APyFloatArray objects are identical.

Two APyFloatArray objects are considered identical if, and only if:
  • They represent exactly the same tensor shape

  • They store the exact same floating-ppint values in all tensor elements

  • They have the exact same bit format (exp_bits, man_bits, and bias)

Returns:
bool

Convolution

convolve(self, other: APyFloatArray, mode: str = 'full') APyFloatArray

Return the discrete linear convolution with another one-dimensional array.

Requires that ndim = 1 for both self and other.

Parameters:
otherAPyFloatArray

The one-dimensional array of length N to convolve with.

mode{‘full’, ‘same’, ‘valid’}, default: ‘full’
‘full’:

Return the full convolution for each point of overlap. The resulting single-dimensional shape will have length N + M - 1. Boundary effects occurs for points where the a and v do not overlap completely.

‘same’:

Return a convolution of length max(M, N). Boundary effects still occur around the edges of the result.

‘valid’:

Return the convolution for each point of full overlap. The resulting single-dimensional shape will have length max(M, N) - min(M, N) + 1

Returns:
convolvedAPyFloatArray

The convolved array.

Transposition

transpose(self, axes: tuple | None = None) APyFloatArray

Return copy of array with axes transposed.

For a 1-D array, this return the same array. For a 2-D array, this is the standard matrix transpose. For an n-D array, if axes are given, their order indicates how the axes are permuted (see Examples). If axes are not provided, then a.transpose(a).shape == a.shape[::-1].

Parameters:
axestuple of int, optional

If specified, it must be a tuple or list which contains a permutation of [0,1,…,N-1] where N is the number of axes of a. The i’th axis of the returned array will correspond to the axis numbered axes[i] of the input. If not specified, defaults to range(a.ndim)[::-1], which reverses the order of the axes.

Returns:
APyFloatArray

a with its axes permuted.

Examples

>>> from apytypes import APyFloatArray
>>> a = APyFloatArray.from_float([[1.0, 2.0, 3.0], [-4.0, -5.0, -6.0]], exp_bits=5, man_bits=2)
>>> a.to_numpy()
array([[ 1.,  2.,  3.],
       [-4., -5., -6.]])
>>> a = a.transpose()
>>> a.to_numpy()
array([[ 1., -4.],
       [ 2., -5.],
       [ 3., -6.]])
>>> a = APyFloatArray.from_float([1.0] * 6, exp_bits=5, man_bits=2).reshape((1, 2, 3))
>>> a.transpose((1, 0, 2)).shape
(2, 1, 3)
>>> a.transpose((-2, -3, -1)).shape
(2, 1, 3)

Array shape manipulation

flatten(self) APyFloatArray

Return a copy of the array collapsed into one dimension.

Returns:
APyFloatArray

Examples

>>> from apytypes import APyFloatArray
>>> signs = [[0, 0], [1, 1]]
>>> exps = [[127, 128], [128, 129]]
>>> mans = [[0, 0], [4194304, 0]]
>>> arr = APyFloatArray(signs=signs, exps=exps, mans=mans, exp_bits=8, man_bits=23)
>>> arr.to_numpy()
array([[ 1.,  2.],
       [-3., -4.]])
>>> arr.flatten().to_numpy()
array([ 1.,  2., -3., -4.])
ravel(self) APyFloatArray

Return a copy of the array collapsed into one dimension. Same as flatten with current memory-copy model.

Returns:
APyFloatArray

Examples

>>> from apytypes import APyFloatArray
>>> signs = [[0, 0], [1, 1]]
>>> exps = [[127, 128], [128, 129]]
>>> mans = [[0, 0], [4194304, 0]]
>>> arr = APyFloatArray(signs=signs, exps=exps, mans=mans, exp_bits=8, man_bits=23)
>>> arr.to_numpy()
array([[ 1.,  2.],
       [-3., -4.]])
>>> arr.ravel().to_numpy()
array([ 1.,  2., -3., -4.])
reshape(self, number_sequence: tuple) APyFloatArray

Reshape the APyFloatArray to the specified shape without changing its data.

Parameters:
new_shapetuple

The new shape should be compatible with the original shape. If a dimension is -1, its value will be inferred from the length of the array and remaining dimensions. Only one dimension can be -1.

Returns:
APyFloatArray
Raises:
ValueError

If negative dimensions less than -1 are provided, if the total size of the new array is not unchanged and divisible by the known dimensions, or if the total number of elements does not match the original array.

Examples

>>> from apytypes import APyFloatArray
>>> signs = [0, 0, 1, 1]
>>> exps = [127, 128, 128, 129]
>>> mans = [0, 0, 4194304, 0]
>>> arr = APyFloatArray(signs=signs, exps=exps, mans=mans, exp_bits=8, man_bits=23)
>>> arr.to_numpy()
array([ 1.,  2., -3., -4.])
>>> arr.reshape((2, 2)).to_numpy()
array([[ 1.,  2.],
       [-3., -4.]])
>>> arr.reshape((4,)).to_numpy()
array([ 1.,  2., -3., -4.])
>>> arr.reshape((2, -1)).to_numpy()
array([[ 1.,  2.],
       [-3., -4.]])
squeeze(self, axis: int | tuple | None = None) APyFloatArray

Remove axes of size one at the specified axis/axes, if no axís is given removes all dimensions with size one.

Parameters:
axistuple of int or int, optional

The axis/axes to squeeze, a given axis with a size other than one will result in an error. No given axes will be remove all dimensions of size 1.

Returns:
APyFloatArray
Raises:
ValueError

If given an axis of a size other than one, a ValueError will be thrown.

IndexError

If a specified axis is outside of the existing number of dimensions for the array.

swapaxes(self, axis1: int, axis2: int) APyFloatArray

Interchange two axes of an array.

Parameters:
axis1int

First axis.

axis2int

Second axis.

Returns:
a_swappedAPyFloatArray

Copy of a with axes swapped

Examples

>>> from apytypes import APyFloatArray
>>> x = APyFloatArray.from_float([[1 ,2, 3]], exp_bits=5, man_bits=2)
>>> x.swapaxes(0,1).to_numpy()
array([[1.],
       [2.],
       [3.]])
>>> x = APyFloatArray.from_float([[[0, 1], [2, 3]], [[4, 5], [6, 7]]], exp_bits=5, man_bits=5)
>>> x.to_numpy()
array([[[0., 1.],
        [2., 3.]],

       [[4., 5.],
        [6., 7.]]])
>>> x.swapaxes(0,2).to_numpy()
array([[[0., 4.],
        [2., 6.]],

       [[1., 5.],
        [3., 7.]]])

Mathematical functions

sum(self, axis: tuple | int | None = None) APyFloatArray | APyFloat

Return the sum of the elements along specified axis/axes.

Parameters:
axistuple of int or int, optional

The axis/axes to summate across. Will summate the whole array if no int or tuple is specified.

Returns:
APyFloatArray or APyFloat
Raises:
IndexError

If a specified axis is outside of the existing number of dimensions for the array.

Examples

>>> from apytypes import APyFloatArray
>>> a = APyFloatArray.from_float(
...     [1,2,3,4,5,6],
...     exp_bits=10,
...     man_bits=10
... )
>>> a.sum()
APyFloat(sign=0, exp=515, man=320, exp_bits=10, man_bits=10)

prod(self, axis: tuple | int | None = None) APyFloatArray | APyFloat

Return the product of the elements along specified axis/axes.

Parameters:
axistuple, int, optional

The axis/axes to calculate the product across. If not given an axis it will return the product of the flattened array.

Returns:
APyFloatArray or APyFloat
Raises:
IndexError

If a specified axis is outside of the existing number of dimensions for the array.

Examples

>>> from apytypes import APyFloatArray
>>> a = APyFloatArray.from_float(
...     [1,2,3,4,5,6],
...     exp_bits=10,
...     man_bits=10
... )
>>> a.prod()
APyFloat(sign=0, exp=520, man=416, exp_bits=10, man_bits=10)

nansum(self, axis: tuple | int | None = None) APyFloatArray | APyFloat

Return the sum of the elements along specified axis/axes treating NaN as 0.

Parameters:
axistuple of int or int, optional

The axis/axes to summate across. Will summate the whole array if no int or tuple is specified.

Returns:
APyFloatArray or APyFloat
Raises:
IndexError

If a specified axis is outside of the existing number of dimensions for the array.

Examples

>>> from apytypes import APyFloatArray
>>> nan = float("nan")
>>> a = APyFloatArray.from_float(
...     [1,2,3,4,5,nan],
...     exp_bits=10,
...     man_bits=10
... )
>>> a.nansum()
APyFloat(sign=0, exp=514, man=896, exp_bits=10, man_bits=10)

nanprod(self, axis: tuple | int | None = None) APyFloatArray | APyFloat

Return the product of the elements along a given axis treating NaN as 0.

Parameters:
axisint, optional

The axis to calculate the product across. If not given an axis it will return the product of the flattened array.

Returns:
APyFloatArray or APyFloat
Raises:
IndexError

If a specified axis is outside of the existing number of dimensions for the array.

cumsum(self, axis: int | None = None) APyFloatArray

Return the cumulative sum of the elements along a given axis.

Parameters:
axisint, optional

The axis to summate across. If not given an axis it will return the cumulative sum of the flattened array.

Returns:
APyFloatArray
Raises:
IndexError

If a specified axis is outside of the existing number of dimensions for the array.

Examples

>>> from apytypes import APyFloatArray
>>> a = APyFloatArray.from_float(
...     [[1,2,3],[4,5,6]],
...     exp_bits=10,
...     man_bits=10
... )
>>> a.cumsum()
APyFloatArray([0, 0, 0, 0, 0, 0], [511, 512, 513, 514, 514, 515], [0, 512, 512, 256, 896, 320], shape=(6,), exp_bits=10, man_bits=10, bias=511)
>>> a.cumsum(0)
APyFloatArray([0, 0, 0, 0, 0, 0], [511, 512, 512, 513, 513, 514], [0, 0, 512, 256, 768, 128], shape=(2, 3), exp_bits=10, man_bits=10, bias=511)
>>> a.cumsum(1)
APyFloatArray([0, 0, 0, 0, 0, 0], [511, 512, 513, 513, 514, 514], [0, 512, 512, 0, 128, 896], shape=(2, 3), exp_bits=10, man_bits=10, bias=511)

cumprod(self, axis: int | None = None) APyFloatArray

Return the cumulative product of the elements along a given axes.

Parameters:
axisint, optional

The axes to calculate the product across. If not given an axis it will return the cumulative product of the flattened array.

Returns:
APyFloatArray
Raises:
IndexError

If a specified axis is outside of the existing number of dimensions for the array.

Examples

>>> from apytypes import APyFloatArray
>>> a = APyFloatArray.from_float(
...     [[1,2,3],[4,5,6]],
...     exp_bits=10,
...     man_bits=10
... )
>>> a.cumprod()
APyFloatArray([0, 0, 0, 0, 0, 0], [511, 512, 513, 515, 517, 520], [0, 0, 512, 512, 896, 416], shape=(6,), exp_bits=10, man_bits=10, bias=511)
>>> a.cumprod(0)
APyFloatArray([0, 0, 0, 0, 0, 0], [511, 512, 512, 513, 514, 515], [0, 0, 512, 0, 256, 128], shape=(2, 3), exp_bits=10, man_bits=10, bias=511)
>>> a.cumprod(1)
APyFloatArray([0, 0, 0, 0, 0, 0], [511, 512, 513, 513, 515, 517], [0, 0, 512, 0, 256, 896], shape=(2, 3), exp_bits=10, man_bits=10, bias=511)

nancumsum(self, axis: int | None = None) APyFloatArray

Return the cumulative sum of the elements along a given axis treating NaN as 0.

Parameters:
axisint, optional

The axis to summate across. If not given an axis it will return the cumulative sum of the flattened array.

Returns:
APyFloatArray
Raises:
IndexError

If a specified axis is outside of the existing number of dimensions for the array.

Examples

>>> from apytypes import APyFloatArray
>>> nan = float("nan")
>>> a = APyFloatArray.from_float(
...     [[1,2,3],[4,5,6]],
...     exp_bits=10,
...     man_bits=10
... )
>>> a.nancumsum()
APyFloatArray([0, 0, 0, 0, 0, 0], [511, 512, 513, 514, 514, 515], [0, 512, 512, 256, 896, 320], shape=(6,), exp_bits=10, man_bits=10, bias=511)
>>> a.nancumsum(0)
APyFloatArray([0, 0, 0, 0, 0, 0], [511, 512, 512, 513, 513, 514], [0, 0, 512, 256, 768, 128], shape=(2, 3), exp_bits=10, man_bits=10, bias=511)
>>> a.nancumsum(1)
APyFloatArray([0, 0, 0, 0, 0, 0], [511, 512, 513, 513, 514, 514], [0, 512, 512, 0, 128, 896], shape=(2, 3), exp_bits=10, man_bits=10, bias=511)

nancumprod(self, axis: int | None = None) APyFloatArray

Return the cumulative product of the elements along a given axis treating NaN as 0.

Parameters:
axisint, optional

The axis to calculate the product across. If not given an axis it will return the cumulative product of the flattened array.

Returns:
APyFloatArray
Raises:
IndexError

If a specified axis is outside of the existing number of dimensions for the array.

max(self, axis: tuple | int | None = None) APyFloatArray | APyFloat

Return the maximum value from an array or the maximum values along an axis.

Parameters:
axistuple of int or int, optional

The axis to get the maximum along.

Returns:
APyFloatArray or APyFloat
Raises:
IndexError

If a specified axis is outside of the existing number of dimensions for the array.

Examples
>>> from apytypes import APyFloatArray
    ..
Array a, array to get the maximum along.
>>> a = APyFloatArray.from_float(
    ..
… [[1, 2, 3], [4, 5, 6]],
… exp_bits=10,
… man_bits=10
… )
>>> a.max()
    ..
APyFloat(sign=0, exp=513, man=512, exp_bits=10, man_bits=10)
>>> a.max(0)
    ..
APyFloatArray([0, 0, 0], [513, 513, 513], [0, 256, 512], shape=(3,), exp_bits=10, man_bits=10, bias=511)
>>> a.max(1)
    ..
APyFloatArray([0, 0], [512, 513], [512, 512], shape=(2,), exp_bits=10, man_bits=10, bias=511)
min(self, axis: tuple | int | None = None) APyFloatArray | APyFloat

Return the minimum value from an array or the minimum values along an axis.

Parameters:
axistuple of int or int, optional

The axis to get the minimum along.

Returns:
APyFloatArray or APyFloat
Raises:
IndexError

If a specified axis is outside of the existing number of dimensions for the array.

Examples
>>> from apytypes import APyFloatArray
    ..
Array a, array to get the minimum along.
>>> a = APyFloatArray.from_float(
    ..
… [[1, 2, 3], [4, 5, 6]],
… exp_bits=10,
… man_bits=10
… )
>>> a.min()
    ..
APyFloat(sign=0, exp=511, man=0, exp_bits=10, man_bits=10)
>>> a.min(0)
    ..
APyFloatArray([0, 0, 0], [511, 512, 512], [0, 0, 512], shape=(3,), exp_bits=10, man_bits=10, bias=511)
>>> a.min(1)
    ..
APyFloatArray([0, 0], [511, 513], [0, 0], shape=(2,), exp_bits=10, man_bits=10, bias=511)
nanmax(self, axis: tuple | int | None = None) APyFloatArray | APyFloat

Return the maximum value from an array or the maximum values along an axis, ignoring NaN.

Issues a warning when encountering an all-nan slice or axis.

Parameters:
axistuple of int or int, optional

The axis to get the maximum along.

Returns:
APyFloatArray or APyFloat
Raises:
IndexError

If a specified axis is outside of the existing number of dimensions for the array.

nanmin(self, axis: tuple | int | None = None) APyFloatArray | APyFloat

Return the minimum value from an array or the minimum values along an axis, ignoring NaN.

Issues a warning when encountering an all-nan slice or axis.

Parameters:
axistuple of int or int, optional

The axis to get the minimum along.

Returns:
APyFloatArray or APyFloat
Raises:
IndexError

If a specified axis is outside of the existing number of dimensions for the array.

Broadcasting

broadcast_to(self, shape: tuple | int) APyFloatArray

Broadcast array to new shape.

Added in version 0.2.

Parameters:
shapetuple of int or int

The shape to broadcast to. A single integer i is interpreted as (i,).

Returns:
APyFloatArray

Convenience casting methods

cast_to_bfloat16(self, quantization: QuantizationMode | None = None) APyFloatArray

Cast to bfloat16 format.

Convenience method corresponding to

f.cast(exp_bits=8, man_bits=7)
Parameters:
quantizationQuantizationMode, optional

Quantization mode to use. If not provided, the global mode, see get_float_quantization_mode(), is used.

cast_to_double(self, quantization: QuantizationMode | None = None) APyFloatArray

Cast to IEEE 754 binary64 (double-precision) format.

Convenience method corresponding to

f.cast(exp_bits=11, man_bits=52)
Parameters:
quantizationQuantizationMode, optional

Quantization mode to use. If not provided, the global mode, see get_float_quantization_mode(), is used.

cast_to_half(self, quantization: QuantizationMode | None = None) APyFloatArray

Cast to IEEE 754 binary16 (half-precision) format.

Convenience method corresponding to

f.cast(exp_bits=5, man_bits=10)
Parameters:
quantizationQuantizationMode, optional

Quantization mode to use. If not provided, the global mode, see get_float_quantization_mode(), is used.

cast_to_single(self, quantization: QuantizationMode | None = None) APyFloatArray

Cast to IEEE 754 binary32 (single-precision) format.

Convenience method corresponding to

f.cast(exp_bits=8, man_bits=23)
Parameters:
quantizationQuantizationMode, optional

Quantization mode to use. If not provided, the global mode, see get_float_quantization_mode(), is used.

Properties

Word length

property bits

Total number of bits.

Returns:
int
property exp_bits

Number of exponent bits.

Returns:
int
property man_bits

Number of mantissa bits.

Returns:
int
property bias

Exponent bias.

Returns:
int

Array properties

property ndim

Number of dimensions in the array.

Returns:
int
property shape

The shape of the array.

Returns:
tuple of int

Transposition

property T

The transposition of the array.

Equivalent to calling APyFloatArray.transpose().

Returns:
APyFloatArray