Array functions

Array creation functions

apytypes.zeros(shape: tuple[int, ...], *, int_bits: int, frac_bits: int, bits: None = None, exp_bits: None = None, man_bits: None = None, bias: None = None, force_complex: None = None) APyFixedArray
apytypes.zeros(shape: tuple[int, ...], *, bits: int, int_bits: int, frac_bits: None = None, exp_bits: None = None, man_bits: None = None, bias: None = None, force_complex: None = None) APyFixedArray
apytypes.zeros(shape: tuple[int, ...], *, bits: int, frac_bits: int, int_bits: None = None, exp_bits: None = None, man_bits: None = None, bias: None = None, force_complex: None = None) APyFixedArray
apytypes.zeros(shape: tuple[int, ...], *, exp_bits: int, man_bits: int, bias: int | None = None, int_bits: None = None, frac_bits: None = None, bits: None = None, force_complex: None = None) APyFloatArray
apytypes.zeros(shape: tuple[int, ...], *, int_bits: int | None = None, frac_bits: int | None = None, bits: int | None = None, exp_bits: int | None = None, man_bits: int | None = None, bias: int | None = None, force_complex: bool | None = None) APyFixedArray | APyCFixedArray | APyFloatArray | APyCFloatArray

Create an array of shape with all zeros.

Word lengths need to be specified and the return type is deduced from the bit specifiers. Either specify exactly two of three from int_bits, frac_bits, and bits, for APyFixedArray, or specify both exp_bits and man_bits for APyFloatArray. Specify force_complex to retrieve a complex-valued array type.

Parameters:
shapetuple of int

Shape of the array.

int_bitsint, optional

Number of fixed-point integer bits.

frac_bitsint, optional

Number of fixed-point fractional bits.

bitsint, optional

Number of fixed-point bits.

exp_bitsint, optional

Number of floating-point exponential bits.

man_bitsint, optional

Number of floating-point mantissa bits.

biasint, optional

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

force_complexbool, optional

Retrieve the complex-valued array type, APyCFixedArray for fixed-point and APyCFloatArray for floating-point.

Returns:
resultAPyFloatArray or APyFixedArray or APyCFixedArray

The initialized array with zeros.

apytypes.ones(shape: tuple[int, ...], *, int_bits: int, frac_bits: int, bits: None = None, exp_bits: None = None, man_bits: None = None, bias: None = None, force_complex: None = None) APyFixedArray
apytypes.ones(shape: tuple[int, ...], *, bits: int, int_bits: int, frac_bits: None = None, exp_bits: None = None, man_bits: None = None, bias: None = None, force_complex: None = None) APyFixedArray
apytypes.ones(shape: tuple[int, ...], *, bits: int, frac_bits: int, int_bits: None = None, exp_bits: None = None, man_bits: None = None, bias: None = None, force_complex: None = None) APyFixedArray
apytypes.ones(shape: tuple[int, ...], *, exp_bits: int, man_bits: int, bias: int | None = None, int_bits: None = None, frac_bits: None = None, bits: None = None, force_complex: None = None) APyFloatArray
apytypes.ones(shape: tuple[int, ...], *, int_bits: int | None = None, frac_bits: int | None = None, bits: int | None = None, exp_bits: int | None = None, man_bits: int | None = None, bias: int | None = None, force_complex: bool | None = None) APyFixedArray | APyCFixedArray | APyFloatArray | APyCFloatArray

Create an array of shape with all ones (stored value).

Word lengths need to be specified and the return type is deduced from the bit specifiers. Either specify exactly two of three from int_bits, frac_bits, and bits, for APyFixedArray, or specify both exp_bits and man_bits for APyFloatArray. Specify force_complex to retrieve a complex-valued array type.

Parameters:
shapetuple of int

Shape of the array.

int_bitsint, optional

Number of fixed-point integer bits.

frac_bitsint, optional

Number of fixed-point fractional bits.

bitsint, optional

Number of fixed-point bits.

exp_bitsint, optional

Number of floating-point exponential bits.

man_bitsint, optional

Number of floating-point mantissa bits.

biasint, optional

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

force_complexbool, optional

Retrieve the complex-valued array type, APyCFixedArray for fixed-point and APyCFloatArray for floating-point.

Returns:
resultAPyFloatArray or APyFixedArray or APyCFixedArray

The array initialized filled with ones.

apytypes.eye(n: int, m: int | None = None, *, int_bits: int, frac_bits: int, bits: None = None, exp_bits: None = None, man_bits: None = None, bias: None = None, force_complex: None = None) APyFixedArray
apytypes.eye(n: int, m: int | None = None, *, bits: int, int_bits: int, frac_bits: None = None, exp_bits: None = None, man_bits: None = None, bias: None = None, force_complex: None = None) APyFixedArray
apytypes.eye(n: int, m: int | None = None, *, bits: int, frac_bits: int, int_bits: None = None, exp_bits: None = None, man_bits: None = None, bias: None = None, force_complex: None = None) APyFixedArray
apytypes.eye(n: int, m: int | None = None, *, exp_bits: int, man_bits: int, bias: int | None = None, bits: None = None, frac_bits: None = None, int_bits: None = None, force_complex: None = None) APyFloatArray
apytypes.eye(n: int, m: int | None = None, *, int_bits: int | None = None, frac_bits: int | None = None, bits: int | None = None, exp_bits: int | None = None, man_bits: int | None = None, bias: int | None = None, force_complex: bool | None = None) APyFixedArray | APyCFixedArray | APyFloatArray | APyCFloatArray

Return a 2-D array with ones (stored value) on the main diagonal and zeros elsewhere.

Word lengths need to be specified and the return type is deduced from the bit specifiers. Either specify exactly two of three from int_bits, frac_bits, and bits, for APyFixedArray, or specify both exp_bits and man_bits for APyFloatArray. Specify force_complex to retrieve a complex-valued array type.

Parameters:
nint

Number of rows in the output.

mint, optional

Number of columns in the output. If None, defaults to n.

int_bitsint, optional

Number of fixed-point integer bits.

frac_bitsint, optional

Number of fixed-point fractional bits.

bitsint, optional

Number of fixed-point bits.

exp_bitsint, optional

Number of floating-point exponential bits.

man_bitsint, optional

Number of floating-point mantissa bits.

biasint, optional

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

force_complexbool, optional

Return the complex-valued array type, APyCFixedArray for fixed-point and APyCFloatArray for floating-point.

Returns:
resultAPyFloatArray, APyFixedArray or APyCFixedArray

An array where all elements are equal to zero, except for the k-th diagonal, whose values are equal to one.

apytypes.identity(n: int, *, int_bits: int, frac_bits: int, bits: None = None, exp_bits: None = None, man_bits: None = None, bias: None = None, force_complex: None = None) APyFixedArray
apytypes.identity(n: int, *, bits: int, int_bits: int, frac_bits: None = None, exp_bits: None = None, man_bits: None = None, bias: None = None, force_complex: None = None) APyFixedArray
apytypes.identity(n: int, *, bits: int, frac_bits: int, int_bits: None = None, exp_bits: None = None, man_bits: None = None, bias: None = None, force_complex: None = None) APyFixedArray
apytypes.identity(n: int, *, exp_bits: int, man_bits: int, bias: int | None = None, int_bits: None = None, bits: None = None, frac_bits: None = None, force_complex: None = None) APyFloatArray
apytypes.identity(n: int, *, int_bits: int | None = None, frac_bits: int | None = None, bits: int | None = None, exp_bits: int | None = None, man_bits: int | None = None, bias: int | None = None, force_complex: bool | None = None) APyFixedArray | APyCFixedArray | APyFloatArray | APyCFloatArray

Return the identity array.

Word lengths need to be specified and the return type is deduced from the bit specifiers. Either specify exactly two of three from int_bits, frac_bits, and bits, for APyFixedArray, or specify both exp_bits and man_bits for APyFloatArray. Specify force_complex to retrieve a complex-valued array type.

Parameters:
nint

Number of rows and columns in output.

int_bitsint, optional

Number of fixed-point integer bits.

frac_bitsint, optional

Number of fixed-point fractional bits.

bitsint, optional

Number of fixed-point bits.

exp_bitsint, optional

Number of floating-point exponential bits.

man_bitsint, optional

Number of floating-point mantissa bits.

biasint, optional

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

force_complexbool, optional

Return the complex-valued array type, APyCFixedArray for fixed-point and APyCFloatArray for floating-point.

Returns:
resultAPyFloatArray, APyFixedArray or APyCFixedArray

n x n array with ones (stored value) on the main diagonal and zeros elsewhere.

apytypes.full(shape: tuple[int, ...], fill_value: APyFixed | APyCFixed | APyFloat | APyCFloat | int | float, *, int_bits: int, frac_bits: int, bits: None = None, exp_bits: None = None, man_bits: None = None, bias: None = None) APyFixedArray
apytypes.full(shape: tuple[int, ...], fill_value: APyFixed | APyCFixed | APyFloat | APyCFloat | int | float, *, bits: int, int_bits: int, frac_bits: None = None, exp_bits: None = None, man_bits: None = None, bias: None = None) APyFixedArray
apytypes.full(shape: tuple[int, ...], fill_value: APyFixed | APyCFixed | APyFloat | APyCFloat | int | float, *, bits: int, frac_bits: int, int_bits: None = None, exp_bits: None = None, man_bits: None = None, bias: None = None) APyFixedArray
apytypes.full(shape: tuple[int, ...], fill_value: APyFixed | APyCFixed | APyFloat | APyCFloat | int | float, *, exp_bits: int, man_bits: int, bias: int | None = None, int_bits: None = None, frac_bits: None = None, bits: None = None) APyFloatArray
apytypes.full(shape: tuple[int, ...], fill_value: APyFixed, *, int_bits: None = None, frac_bits: None = None, bits: None = None, exp_bits: None = None, man_bits: None = None, bias: None = None) APyFixedArray
apytypes.full(shape: tuple[int, ...], fill_value: APyFloat, *, int_bits: None = None, frac_bits: None = None, bits: None = None, exp_bits: None = None, man_bits: None = None, bias: None = None) APyFloatArray
apytypes.full(shape: tuple[int, ...], fill_value: APyFixed | APyCFixed | APyFloat | APyCFloat | int | float, *, int_bits: int | None = None, frac_bits: int | None = None, bits: int | None = None, exp_bits: int | None = None, man_bits: int | None = None, bias: int | None = None) APyFixedArray | APyCFixedArray | APyFloatArray | APyCFloatArray

Return a new array of given shape and type, filled with fill_value.

If fill_value is of type int or float, you must specify the word lengths. Either specify exactly two of three from int_bits, frac_bits, and bits, for APyFixedArray, or specify both exp_bits and man_bits for APyFloatArray. If fill_value is of type APyFloat or APyFixed, the array will use the provided word lengths only if specified, otherwise the word lengths are inherited from fill_value.

Parameters:
shapetuple

Shape of the array.

fill_valueAPyFloat or APyFixed or int or :class`float`

Fill value.

int_bitsint, optional

Number of fixed-point integer bits.

frac_bitsint, optional

Number of fixed-point fractional bits.

bitsint, optional

Number of fixed-point bits.

exp_bitsint, optional

Number of floating-point exponential bits.

man_bitsint, optional

Number of floating-point mantissa bits.

biasint, optional

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

Returns:
resultAPyFloatArray or APyFixedArray

Array of all fill_value with the given shape.

apytypes.zeros_like(a: APyFixedArray, *, int_bits: int | None = None, frac_bits: int | None = None, bits: int | None = None, exp_bits: None = None, man_bits: None = None, bias: None = None) APyFixedArray
apytypes.zeros_like(a: APyCFixedArray, *, int_bits: int | None = None, frac_bits: int | None = None, bits: int | None = None, exp_bits: None = None, man_bits: None = None, bias: None = None) APyCFixedArray
apytypes.zeros_like(a: APyFloatArray, *, exp_bits: int | None = None, man_bits: int | None = None, bias: int | None = None, int_bits: None = None, frac_bits: None = None, bits: None = None) APyFloatArray
apytypes.zeros_like(a: APyCFloatArray, *, exp_bits: int | None = None, man_bits: int | None = None, bias: int | None = None, int_bits: None = None, frac_bits: None = None, bits: None = None) APyCFloatArray
apytypes.zeros_like(a: APyFixedArray | APyCFixedArray | APyFloatArray | APyCFloatArray, *, int_bits: int | None = None, frac_bits: int | None = None, bits: int | None = None, exp_bits: int | None = None, man_bits: int | None = None, bias: int | None = None) APyFixedArray | APyCFixedArray | APyFloatArray | APyCFloatArray

Return an array of all zeros with the same shape and type as a.

The type and bit-specifiers of the returned array can be overwritten through the bit-specifier arguments. To modify the type, either specify exactly two of three from int_bits, frac_bits, and bits, for APyFixedArray and APyCFixedArray, or specify both exp_bits and man_bits for APyFloatArray.

Parameters:
aAPyFixedArray, APyFloatArray, or APyCFixedArray

The shape and data-type of a define these same attributes of the returned array.

int_bitsint, optional

Number of fixed-point integer bits.

frac_bitsint, optional

Number of fixed-point fractional bits.

bitsint, optional

Number of fixed-point bits.

exp_bitsint, optional

Number of floating-point exponential bits.

man_bitsint, optional

Number of floating-point mantissa bits.

biasint, optional

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

Returns:
resultAPyFloatArray or APyFixedArray

The initialized array with all zeros.

apytypes.ones_like(a: APyFixedArray, *, int_bits: int | None = None, frac_bits: int | None = None, bits: int | None = None, exp_bits: None = None, man_bits: None = None, bias: None = None) APyFixedArray
apytypes.ones_like(a: APyCFixedArray, *, int_bits: int | None = None, frac_bits: int | None = None, bits: int | None = None, exp_bits: None = None, man_bits: None = None, bias: None = None) APyCFixedArray
apytypes.ones_like(a: APyFloatArray, *, exp_bits: int | None = None, man_bits: int | None = None, bias: int | None = None, int_bits: None = None, frac_bits: None = None, bits: None = None) APyFloatArray
apytypes.ones_like(a: APyCFloatArray, *, exp_bits: int | None = None, man_bits: int | None = None, int_bits: None = None, frac_bits: None = None, bits: None = None, bias: None = None) APyCFloatArray
apytypes.ones_like(a: APyFixedArray | APyCFixedArray | APyFloatArray | APyCFloatArray, *, int_bits: int | None = None, frac_bits: int | None = None, bits: int | None = None, exp_bits: int | None = None, man_bits: int | None = None, bias: int | None = None) APyFixedArray | APyCFixedArray | APyFloatArray | APyCFloatArray

Return an array of all ones (stored value) with the same shape and type as a.

The type and bit-specifiers of the returned array can be overwritten through the bit-specifier arguments. To modify the type, either specify exactly two of three from int_bits, frac_bits, and bits, for APyFixedArray, or specify both exp_bits and man_bits for APyFloatArray.

Parameters:
aAPyFixedArray, APyFloatArray, or APyCFixedArray

The shape and data-type of a define these same attributes of the returned array.

int_bitsint, optional

Number of fixed-point integer bits.

frac_bitsint, optional

Number of fixed-point fractional bits.

bitsint, optional

Number of fixed-point bits.

exp_bitsint, optional

Number of floating-point exponential bits.

man_bitsint, optional

Number of floating-point mantissa bits.

biasint, optional

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

Returns:
resultAPyFloatArray or APyFixedArray

The array initialized filled with all ones.

apytypes.full_like(a: APyFixedArray, fill_value: APyFixed | APyCFixed | APyFloat | APyCFloat | int | float, *, int_bits: int | None = None, frac_bits: int | None = None, bits: int | None = None, exp_bits: int | None = None, man_bits: int | None = None, bias: int | None = None) APyFixedArray
apytypes.full_like(a: APyFloatArray, fill_value: APyFixed | APyCFixed | APyFloat | APyCFloat | int | float, *, int_bits: int | None = None, frac_bits: int | None = None, bits: int | None = None, exp_bits: int | None = None, man_bits: int | None = None, bias: int | None = None) APyFloatArray
apytypes.full_like(a: APyCFixedArray, fill_value: APyFixed | APyCFixed | APyFloat | APyCFloat | int | float, *, int_bits: int | None = None, frac_bits: int | None = None, bits: int | None = None, exp_bits: int | None = None, man_bits: int | None = None, bias: int | None = None) APyCFixedArray
apytypes.full_like(a: APyCFloatArray, fill_value: APyFixed | APyCFixed | APyFloat | APyCFloat | int | float, *, int_bits: int | None = None, frac_bits: int | None = None, bits: int | None = None, exp_bits: int | None = None, man_bits: int | None = None, bias: int | None = None) APyCFloatArray
apytypes.full_like(a: APyFixedArray | APyCFixedArray | APyFloatArray | APyCFloatArray, fill_value: APyFixed | APyCFixed | APyFloat | APyCFloat | int | float, *, int_bits: int | None = None, frac_bits: int | None = None, bits: int | None = None, exp_bits: int | None = None, man_bits: int | None = None, bias: int | None = None) APyFixedArray | APyCFixedArray | APyFloatArray | APyCFloatArray

Return an array with all values initialized to fill_value, with the same shape and type as a.

The type and bit-specifiers of the returned array can be overwritten through the bit-specifier arguments. To overwrite the type, either specify exactly two of three from int_bits, frac_bits, and bits, for APyFixedArray, or specify both exp_bits and man_bits for APyFloatArray.

Parameters:
aAPyFloatArray or APyFixedArray

The shape and array type of the returned array.

fill_valueAPyFloat or APyFixed or int or float

The value to fill the array with.

int_bitsint, optional

Number of fixed-point integer bits.

frac_bitsint, optional

Number of fixed-point fractional bits.

bitsint, optional

Number of fixed-point bits.

exp_bitsint, optional

Number of floating-point exponential bits.

man_bitsint, optional

Number of floating-point mantissa bits.

biasint, optional

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

Returns:
resultAPyFloatArray or APyFixedArray

Array filled with fill_value, having the same shape and type as a.

apytypes.arange(start: APyFixed | APyCFixed | APyFloat | APyCFloat | int | float, stop: APyFixed | APyCFixed | APyFloat | APyCFloat | int | float | None = None, step: APyFixed | APyCFixed | APyFloat | APyCFloat | int | float = 1, *, int_bits: int, frac_bits: int | None = None, bits: int | None = None, exp_bits: None = None, man_bits: None = None, bias: None = None) APyFixedArray
apytypes.arange(start: APyFixed | APyCFixed | APyFloat | APyCFloat | int | float, stop: APyFixed | APyCFixed | APyFloat | APyCFloat | int | float | None = None, step: APyFixed | APyCFixed | APyFloat | APyCFloat | int | float = 1, *, bits: int, int_bits: int | None = None, frac_bits: int | None = None, exp_bits: None = None, man_bits: None = None, bias: None = None) APyFixedArray
apytypes.arange(start: APyFixed | APyCFixed | APyFloat | APyCFloat | int | float, stop: APyFixed | APyCFixed | APyFloat | APyCFloat | int | float | None = None, step: APyFixed | APyCFixed | APyFloat | APyCFloat | int | float = 1, *, frac_bits: int, bits: int | None = None, int_bits: int | None = None, exp_bits: None = None, man_bits: None = None, bias: None = None) APyFixedArray
apytypes.arange(start: APyFixed | APyCFixed | APyFloat | APyCFloat | int | float, stop: APyFixed | APyCFixed | APyFloat | APyCFloat | int | float | None = None, step: APyFixed | APyCFixed | APyFloat | APyCFloat | int | float = 1, *, exp_bits: int, man_bits: int | None = None, bias: int | None = None, int_bits: None = None, frac_bits: None = None, bits: None = None) APyFloatArray
apytypes.arange(start: APyFixed | APyCFixed | APyFloat | APyCFloat | int | float, stop: APyFixed | APyCFixed | APyFloat | APyCFloat | int | float | None = None, step: APyFixed | APyCFixed | APyFloat | APyCFloat | int | float = 1, *, man_bits: int, exp_bits: int | None = None, bias: int | None = None, int_bits: None = None, frac_bits: None = None, bits: None = None) APyFloatArray
apytypes.arange(start: APyFixed | APyCFixed | APyFloat | APyCFloat | int | float, stop: APyFixed | APyCFixed | APyFloat | APyCFloat | int | float | None = None, step: APyFixed | APyCFixed | APyFloat | APyCFloat | int | float = 1, *, bias: int, man_bits: int | None = None, exp_bits: int | None = None, int_bits: None = None, frac_bits: None = None, bits: None = None) APyFloatArray
apytypes.arange(start: APyFixed, stop: APyFixed | int | float | None = None, step: APyFixed | int | float = 1, *, int_bits: None = None, frac_bits: None = None, bits: None = None, exp_bits: None = None, man_bits: None = None, bias: None = None) APyFixedArray
apytypes.arange(start: APyFixed | int | float, stop: APyFixed, step: APyFixed | int | float = 1, *, int_bits: None = None, frac_bits: None = None, bits: None = None, exp_bits: None = None, man_bits: None = None, bias: None = None) APyFixedArray
apytypes.arange(start: APyFixed | int | float, stop: APyFixed | int | float, step: APyFixed, *, int_bits: None = None, frac_bits: None = None, bits: None = None, exp_bits: None = None, man_bits: None = None, bias: None = None) APyFixedArray
apytypes.arange(start: APyFloat, stop: APyFloat | int | float | None = None, step: APyFloat | int | float = 1, *, int_bits: None = None, frac_bits: None = None, bits: None = None, exp_bits: None = None, man_bits: None = None, bias: None = None) APyFloatArray
apytypes.arange(start: APyFloat | int | float, stop: APyFloat, step: APyFloat | int | float = 1, *, int_bits: None = None, frac_bits: None = None, bits: None = None, exp_bits: None = None, man_bits: None = None, bias: None = None) APyFloatArray
apytypes.arange(start: APyFloat | int | float, stop: APyFloat | int | float, step: APyFloat, *, int_bits: None = None, frac_bits: None = None, bits: None = None, exp_bits: None = None, man_bits: None = None, bias: None = None) APyFloatArray
apytypes.arange(start: APyFixed | APyCFixed | APyFloat | APyCFloat | int | float, stop: APyFixed | APyCFixed | APyFloat | APyCFloat | int | float | None = None, step: APyFixed | APyCFixed | APyFloat | APyCFloat | int | float = 1, *, int_bits: int | None = None, frac_bits: int | None = None, bits: int | None = None, exp_bits: int | None = None, man_bits: int | None = None, bias: int | None = None) APyFixedArray | APyCFixedArray | APyFloatArray | APyCFloatArray

Create an array with evenly spaced values within a given interval.

The function can be called with varying number of positional arguments:

  • arange(stop): Values are generated within the half-open interval [0, stop) (in other words, the interval including start but excluding stop).

  • arange(start, stop): Values are generated within the half-open interval [start, stop).

  • arange(start, stop, step): Values are generated within the half-open interval [start, stop), with spacing between values given by step.

If no bit-specifiers are given, the array type is deduced based on start, stop, and step. In this case, all APyTypes scalars must be of the same format.

Parameters:
startint, float, APyFloat, APyFixed

Start number.

stopint, float, APyFloat, APyFixed, optional

Stop number.

stepint, float, APyFloat, APyFixed, optional

Step size in range.

int_bitsint, optional

Number of fixed-point integer bits.

frac_bitsint, optional

Number of fixed-point fractional bits.

bitsint, optional

Number of fixed-point bits.

exp_bitsint, optional

Number of floating-point exponential bits.

man_bitsint, optional

Number of floating-point mantissa bits.

biasint, optional

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

Returns:
resultAPyFloatArray or APyFixedArray

Array with evenly spaced values within a given interval.

apytypes.fullrange(start: APyFixed | APyCFixed | APyFloat | APyCFloat | int | float, stop: APyFixed | APyCFixed | APyFloat | APyCFloat | int | float | None = None, *, int_bits: int, frac_bits: int | None = None, bits: int | None = None, exp_bits: None = None, man_bits: None = None, bias: None = None) APyFixedArray
apytypes.fullrange(start: APyFixed | APyCFixed | APyFloat | APyCFloat | int | float, stop: APyFixed | APyCFixed | APyFloat | APyCFloat | int | float | None = None, *, bits: int, int_bits: int | None = None, frac_bits: int | None = None, exp_bits: None = None, man_bits: None = None, bias: None = None) APyFixedArray
apytypes.fullrange(start: APyFixed | APyCFixed | APyFloat | APyCFloat | int | float, stop: APyFixed | APyCFixed | APyFloat | APyCFloat | int | float | None = None, *, frac_bits: int, bits: int | None = None, int_bits: int | None = None, exp_bits: None = None, man_bits: None = None, bias: None = None) APyFixedArray
apytypes.fullrange(start: APyFixed | APyCFixed | APyFloat | APyCFloat | int | float, stop: APyFixed | APyCFixed | APyFloat | APyCFloat | int | float | None = None, *, exp_bits: int, man_bits: int | None = None, bias: int | None = None, int_bits: None = None, frac_bits: None = None, bits: None = None) APyFloatArray
apytypes.fullrange(start: APyFixed | APyCFixed | APyFloat | APyCFloat | int | float, stop: APyFixed | APyCFixed | APyFloat | APyCFloat | int | float | None = None, *, man_bits: int, exp_bits: int | None = None, bias: int | None = None, int_bits: None = None, frac_bits: None = None, bits: None = None) APyFloatArray
apytypes.fullrange(start: APyFixed | APyCFixed | APyFloat | APyCFloat | int | float, stop: APyFixed | APyCFixed | APyFloat | APyCFloat | int | float | None = None, *, bias: int, man_bits: int | None = None, exp_bits: int | None = None, int_bits: None = None, frac_bits: None = None, bits: None = None) APyFloatArray
apytypes.fullrange(start: APyFixed, stop: APyFixed | int | float | None = None, *, int_bits: None = None, frac_bits: None = None, bits: None = None, exp_bits: None = None, man_bits: None = None, bias: None = None) APyFixedArray
apytypes.fullrange(start: APyFixed | int | float, stop: APyFixed, *, int_bits: None = None, frac_bits: None = None, bits: None = None, exp_bits: None = None, man_bits: None = None, bias: None = None) APyFixedArray
apytypes.fullrange(start: APyFloat, stop: APyFloat | int | float | None = None, *, int_bits: None = None, frac_bits: None = None, bits: None = None, exp_bits: None = None, man_bits: None = None, bias: None = None) APyFloatArray
apytypes.fullrange(start: APyFloat | int | float, stop: APyFloat, *, int_bits: None = None, frac_bits: None = None, bits: None = None, exp_bits: None = None, man_bits: None = None, bias: None = None) APyFloatArray
apytypes.fullrange(start: APyFixed | APyCFixed | APyFloat | APyCFloat | int | float, stop: APyFixed | APyCFixed | APyFloat | APyCFloat | int | float | None = None, *, int_bits: int | None = None, frac_bits: int | None = None, bits: int | None = None, exp_bits: int | None = None, man_bits: int | None = None, bias: int | None = None) APyFixedArray | APyCFixedArray | APyFloatArray | APyCFloatArray

Create an array with all values within a given interval.

The function can be called with varying number of positional arguments:

  • arange(stop): Values are generated within the half-open interval [0, stop) (in other words, the interval including start but excluding stop).

  • arange(start, stop): Values are generated within the half-open interval [start, stop).

If no bit-specifiers are given, the array type is deduced based on start and stop. In this case, all APyTypes scalars must be of the same format.

Parameters:
startint, float, APyFloat, APyFixed

Start number.

stopint, float, APyFloat, APyFixed, optional

Stop number.

int_bitsint, optional

Number of fixed-point integer bits.

frac_bitsint, optional

Number of fixed-point fractional bits.

bitsint, optional

Number of fixed-point bits.

exp_bitsint, optional

Number of floating-point exponential bits.

man_bitsint, optional

Number of floating-point mantissa bits.

biasint, optional

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

Returns:
resultAPyFloatArray or APyFixedArray

Array with all values within a given interval.

apytypes.meshgrid(*arrays: APyFixedArray | APyCFixedArray | APyFloatArray | APyCFloatArray, indexing: Literal['xy', 'ij'] = 'xy') list[APyFixedArray | APyCFixedArray | APyFloatArray | APyCFloatArray]

Create a list of coordinate arrays based on several coordinate vectors (1-D arrays). The input vectors must all have the same bit specifiers.

Added in version 0.4.

Parameters:
arraysAPyFixedArray, APyFloatArray, APyCFixedArray, APyCFloatArray

The coordinate vectors (1-D arrays).

indexing{“xy”, “ij”}, default: “xy”

The indexing mode to use for the meshgrid. “xy” is the standard Cartesian indexing, while “ij” is the matrix indexing.

Returns:
resultlist of APyFixedArray, APyFloatArray, APyCFixedArray, APyCFloatArray

List of 2-D arrays representing the meshgrid.

Examples

>>> import apytypes as apy
>>> x = apy.fx(range(3), int_bits=5, frac_bits=0)
>>> y = apy.fx(range(4, 7), int_bits=5, frac_bits=0)
>>> xx, yy = apy.meshgrid(x, y)
>>> xx
APyFixedArray([[0, 1, 2],
               [0, 1, 2],
               [0, 1, 2]], int_bits=5, frac_bits=0)
>>> yy
APyFixedArray([[4, 4, 4],
               [5, 5, 5],
               [6, 6, 6]], int_bits=5, frac_bits=0)

Array modification functions

apytypes.expand_dims(a: APyFixedArray, axis: int | tuple[int, ...]) APyFixedArray
apytypes.expand_dims(a: APyFloatArray, axis: int | tuple[int, ...]) APyFloatArray
apytypes.expand_dims(a: APyCFixedArray, axis: int | tuple[int, ...]) APyCFixedArray
apytypes.expand_dims(a: APyCFloatArray, axis: int | tuple[int, ...]) APyCFloatArray

Expand the shape of an array.

Insert a new axis that will appear at the axis position in the expanded array shape.

Parameters:
aAPyFloatArray, APyFixedArray, APyCFixedArray, or

APyCFloatArray The array whose axes should be reordered.

axisint or tuple of ints

Position in the expanded axes where the new axis (or axes) is placed.

Returns:
resultAPyFloatArray or APyFixedArray

Copy of a with the number of dimensions increased.

Examples

>>> import apytypes as apy
>>> x = apy.fx([1, 2], int_bits=5, frac_bits=0)
>>> x.shape
(2,)
>>> y = apy.expand_dims(x, axis=0)
>>> y
APyFixedArray([[1, 2]], int_bits=5, frac_bits=0)
>>> y.shape
(1, 2)
>>> y = apy.expand_dims(x, axis=1)
>>> y
APyFixedArray([[1],
               [2]], int_bits=5, frac_bits=0)
>>> y.shape
(2, 1)

axis may also be a tuple:

>>> y = apy.expand_dims(x, axis=(0, 1))
>>> y
APyFixedArray([[[1, 2]]], int_bits=5, frac_bits=0)
>>> y.shape
(1, 1, 2)
>>> y = apy.expand_dims(x, axis=(2, 0))
>>> y
APyFixedArray([[[1],
                [2]]], int_bits=5, frac_bits=0)
>>> y.shape
(1, 2, 1)
apytypes.ravel(a: APyFixedArray) APyFixedArray
apytypes.ravel(a: APyFloatArray) APyFloatArray
apytypes.ravel(a: APyCFixedArray) APyCFixedArray
apytypes.ravel(a: APyCFloatArray) APyCFloatArray

Return a copy of the array collapsed into one dimension.

Same as flatten() with current memory-copy model.

Returns:
collapsedAPyFloatArray or APyFixedArray

copy of a but collapsed

Examples

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

apytypes.moveaxis(a: APyFixedArray, source: int | Sequence[int], destination: int | Sequence[int]) APyFixedArray
apytypes.moveaxis(a: APyFloatArray, source: int | Sequence[int], destination: int | Sequence[int]) APyFloatArray
apytypes.moveaxis(a: APyCFixedArray, source: int | Sequence[int], destination: int | Sequence[int]) APyCFixedArray
apytypes.moveaxis(a: APyCFloatArray, source: int | Sequence[int], destination: int | Sequence[int]) APyCFloatArray

Move axes of an array to new positions.

Other axes remain in their original order.

Parameters:
aAPyFloatArray or APyFixedArray

The array whose axes should be reordered.

sourceint or sequence of int

Original positions of the axes to move. These must be unique.

destinationint or sequence of int

Destination positions for each of the original axes. These must also be unique.

Returns:
resultAPyFloatArray or APyFixedArray

Copy of array with moved axes.

Examples

>>> import apytypes as apy
>>> x = apy.zeros((3, 4, 5), int_bits=16, frac_bits=0)
>>> apy.moveaxis(x, 0, -1).shape
(4, 5, 3)
>>> apy.moveaxis(x, -1, 0).shape
(5, 3, 4)

These all achieve the same result:

>>> apy.transpose(x).shape
(5, 4, 3)
>>> apy.swapaxes(x, 0, -1).shape
(5, 4, 3)
>>> apy.moveaxis(x, [0, 1], [-1, -2]).shape
(5, 4, 3)
>>> apy.moveaxis(x, [0, 1, 2], [-1, -2, -3]).shape
(5, 4, 3)
apytypes.squeeze(a: APyFixedArray, axis: int | tuple[int, ...] | None = None) APyFixedArray
apytypes.squeeze(a: APyFloatArray, axis: int | tuple[int, ...] | None = None) APyFloatArray
apytypes.squeeze(a: APyCFloatArray, axis: int | tuple[int, ...] | None = None) APyCFloatArray
apytypes.squeeze(a: APyCFixedArray, axis: int | tuple[int, ...] | None = None) APyCFixedArray

Remove axes of length one from a.

Parameters:
aAPyFloatArray, APyFixedArray, or APyCFixedArray, or APyCFloatArray

Input array.

axisint or tuple of ints, optional

Selects a subset of the entries of length one in the shape.

Returns:
squeezedAPyFloatArray, APyFixedArray, APyCFixedArray, or APyCFloatArray

The input array, but with all or a subset of the dimensions of length 1 removed.

Raises:
ValueError

If axis is not None, and an axis being squeezed is not of length 1

apytypes.swapaxes(a: APyFixedArray, axis1: int, axis2: int) APyFixedArray
apytypes.swapaxes(a: APyFloatArray, axis1: int, axis2: int) APyFloatArray
apytypes.swapaxes(a: APyCFixedArray, axis1: int, axis2: int) APyCFixedArray
apytypes.swapaxes(a: APyCFloatArray, axis1: int, axis2: int) APyCFloatArray

Interchange two axes of an array.

Parameters:
aAPyFloatArray or APyFixedArray

The array whose axes should be reordered.

axis1int

First axis.

axis2int

Second axis.

Returns:
a_swappedAPyFloatArray or APyFixedArray

Copy of a with axes swapped

Examples

>>> import apytypes as apy
>>> x = apy.fp([[1, 2, 3]], exp_bits=5, man_bits=2)
>>> apy.swapaxes(x, 0, 1)
APyFloatArray(
    [[ 0],
     [ 0],
     [ 0]],

    [[15],
     [16],
     [16]],

    [[ 0],
     [ 0],
     [ 2]],
    exp_bits=5,
    man_bits=2
)
>>> x = apy.fp([[[0, 1], [2, 3]], [[4, 5], [6, 7]]], exp_bits=5, man_bits=3)
>>> x
APyFloatArray(
    [[[ 0,  0],
      [ 0,  0]],

     [[ 0,  0],
      [ 0,  0]]],


    [[[ 0, 15],
      [16, 16]],

     [[17, 17],
      [17, 17]]],


    [[[ 0,  0],
      [ 0,  4]],

     [[ 0,  2],
      [ 4,  6]]],
    exp_bits=5,
    man_bits=3
)
>>> apy.swapaxes(x, 0, 2)
APyFloatArray(
    [[[ 0,  0],
      [ 0,  0]],

     [[ 0,  0],
      [ 0,  0]]],


    [[[ 0, 17],
      [16, 17]],

     [[15, 17],
      [16, 17]]],


    [[[ 0,  0],
      [ 0,  4]],

     [[ 0,  2],
      [ 4,  6]]],
    exp_bits=5,
    man_bits=3
)

Array utility functions

apytypes.convolve(a: APyFixedArray, v: APyFixedArray, mode: Literal['full', 'same', 'valid'] = 'full') APyFixedArray
apytypes.convolve(a: APyFloatArray, v: APyFloatArray, mode: Literal['full', 'same', 'valid'] = 'full') APyFloatArray
apytypes.convolve(a: APyCFixedArray, v: APyCFixedArray, mode: Literal['full', 'same', 'valid'] = 'full') APyCFixedArray
apytypes.convolve(a: APyCFloatArray, v: APyCFloatArray, mode: Literal['full', 'same', 'valid'] = 'full') APyCFloatArray

Return the discrete linear convolution of two one-dimensional arrays.

Parameters:
aAPyFloatArray or APyFixedArray

First one-dimensional array of length M

vAPyFloatArray or APyFixedArray

Second one-dimensional array of length N.

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 or APyFixedArray

The convolved array.

apytypes.shape(arr: APyFixedArray | APyCFixedArray | APyFloatArray | APyCFloatArray) tuple[int, ...]

Return the shape of an array.

Parameters:
arrAPyFloatArray or APyFixedArray

Input data.

Returns:
tuple of int

Shape of the input array.

Raises:
TypeError

If the input does not have a shape attribute.

apytypes.export_csv(a: APyFixedArray, fname: str, delimiter: str = ',', layout: Literal['default', 'vunit'] = 'default') None
apytypes.export_csv(a: APyFloatArray, fname: str, delimiter: str = ',', layout: Literal['default', 'vunit'] = 'default') None

Store the bit values of an array to a CSV file.

The function supports multi-dimensional arrays:
  • For 1-D arrays, all elements are written on a single line.

  • For 2-D arrays, each row of the array is written on a separate line.

  • Higher-dimensional arrays must be handled manually unless supported by the chosen layout.

By default, a 1-D array will be exported as a single row CSV, and a 2-D array will be exported as multiple rows.

Attention

The index order of arrays may differ between APyTypes and other programs.

Note

The VUnit layout transposes the array so that the index order of VUnit’s get function will behave the same as in APyTypes. For a 2-D array, VUnit’s integer_array package will have the shape height, width = a.shape. For a 3-D array, VUnit’s integer_array package must be reshaped to height, width, depth = a.shape after importing it as a 2-D array. The array is stored in the CSV with the shape height, width = a.shape[1], a.shape[0]*a.shape[2]. Lastly, negative fixed-point values are represented using the minus sign to match the expectations of VUnit.

Hint

To export a complex-valued array, use separate CSV files for real and imaginary parts.

Added in version 0.4.

Parameters:
aAPyFixedArray or APyFloatArray

The array to store the bit values of.

fnamestr

Path to the CSV file to store bit values.

delimiterstr, optional

Character used in the CSV file to separate bit values. Default is ,.

layout{“default”, “vunit”}, default: “default”

Layout to use when storing the array.

See also

import_csv

Examples

>>> import apytypes as apy
>>> a = apy.fx(range(4), int_bits=4, frac_bits=0).reshape((2, 2))
>>> apy.export_csv(a, "input.csv")

A 3-D VUnit array can be exported as

>>> b = apy.fx(range(8), int_bits=4, frac_bits=0).reshape((2, 2, 2))
>>> apy.export_csv(b, "input_vunit.csv", layout="vunit")
apytypes.import_csv(fname: str, *, delimiter: str = ',', int_bits: int | None = None, frac_bits: int | None = None, bits: int | None = None, exp_bits: int | None = None, man_bits: int | None = None, bias: int | None = None, force_complex: bool = False, layout: Literal['default', 'vunit'] = 'default', vunit_3d_shape: tuple[int, ...] | None = None) APyFixedArray
apytypes.import_csv(fname: str, *, delimiter: str = ',', int_bits: int | None = None, frac_bits: int | None = None, bits: int | None = None, exp_bits: int | None = None, man_bits: int | None = None, bias: int | None = None, force_complex: bool = False, layout: Literal['default', 'vunit'] = 'default', vunit_3d_shape: tuple[int, ...] | None = None) APyFloatArray

Create an array from a CSV file containing bit values.

1-D and 2-D arrays are directly supported, while higher dimensional arrays must be reshaped manually after importing as either a 1-D or 2-D array.

By default, a one row CSV file is imported as a 1-D array, while a multi-row CSV file is imported as a 2-D array.

Attention

The index order may differ between APyTypes and other programs.

Note

1-D VUnit arrays can be imported using the default layout.

Added in version 0.4.

Parameters:
fnamestr

Path to the CSV file containing bit values.

delimiterstr, optional

Character used in the CSV file to separate bit values. Default is ,.

int_bitsint, optional

Number of fixed-point integer bits.

frac_bitsint, optional

Number of fixed-point fractional bits.

bitsint, optional

Number of fixed-point bits.

exp_bitsint, optional

Number of floating-point exponential bits.

man_bitsint, optional

Number of floating-point mantissa bits.

biasint, optional

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

force_complexbool, optional

If True, forces the array to be treated as complex.

layout{“default”, “vunit”}, default: “default”

Layout of the stored array.

vunit_3d_shapetuple, optional

Shape of the resulting 3-D array when using the “vunit” layout. Do not provide this for 1-D or 2-D arrays.

Returns:
resultAPyFloatArray or APyFixedArray

Array created from the bit values in the CSV file.

See also

export_csv

Examples

>>> import apytypes as apy
>>> a = apy.import_csv("input.csv", int_bits=4, frac_bits=0)
>>> a
APyFixedArray([[0, 1],
               [2, 3]], int_bits=4, frac_bits=0)

A 3-D VUnit array can be imported as

>>> b = apy.import_csv(
...     "input_vunit.csv",
...     int_bits=4,
...     frac_bits=0,
...     layout="vunit",
...     vunit_3d_shape=(2, 2, 2),
... )
>>> b
APyFixedArray([[[0, 1],
                [2, 3]],

               [[4, 5],
                [6, 7]]], int_bits=4, frac_bits=0)