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 forAPyFloatArray
. Specify force_complex to retrieve a complex-valued array type.- Parameters:
- shape
tuple
ofint
Shape of the array.
- int_bits
int
, optional Number of fixed-point integer bits.
- frac_bits
int
, optional Number of fixed-point fractional bits.
- bits
int
, optional Number of fixed-point bits.
- exp_bits
int
, optional Number of floating-point exponential bits.
- man_bits
int
, optional Number of floating-point mantissa bits.
- bias
int
, optional Exponent bias. If not provided, bias is
2**exp_bits - 1
.- force_complex
bool
, optional Retrieve the complex-valued array type,
APyCFixedArray
for fixed-point andAPyCFloatArray
for floating-point.
- shape
- Returns:
- result
APyFloatArray
orAPyFixedArray
orAPyCFixedArray
The initialized array with zeros.
- result
- 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 forAPyFloatArray
. Specify force_complex to retrieve a complex-valued array type.- Parameters:
- shape
tuple
ofint
Shape of the array.
- int_bits
int
, optional Number of fixed-point integer bits.
- frac_bits
int
, optional Number of fixed-point fractional bits.
- bits
int
, optional Number of fixed-point bits.
- exp_bits
int
, optional Number of floating-point exponential bits.
- man_bits
int
, optional Number of floating-point mantissa bits.
- bias
int
, optional Exponent bias. If not provided, bias is
2**exp_bits - 1
.- force_complex
bool
, optional Retrieve the complex-valued array type,
APyCFixedArray
for fixed-point andAPyCFloatArray
for floating-point.
- shape
- Returns:
- result
APyFloatArray
orAPyFixedArray
orAPyCFixedArray
The array initialized filled with ones.
- result
- 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 forAPyFloatArray
. Specify force_complex to retrieve a complex-valued array type.- Parameters:
- n
int
Number of rows in the output.
- m
int
, optional Number of columns in the output. If None, defaults to n.
- int_bits
int
, optional Number of fixed-point integer bits.
- frac_bits
int
, optional Number of fixed-point fractional bits.
- bits
int
, optional Number of fixed-point bits.
- exp_bits
int
, optional Number of floating-point exponential bits.
- man_bits
int
, optional Number of floating-point mantissa bits.
- bias
int
, optional Exponent bias. If not provided, bias is
2**exp_bits - 1
.- force_complex
bool
, optional Return the complex-valued array type,
APyCFixedArray
for fixed-point andAPyCFloatArray
for floating-point.
- n
- Returns:
- result
APyFloatArray
,APyFixedArray
orAPyCFixedArray
An array where all elements are equal to zero, except for the k-th diagonal, whose values are equal to one.
- result
- 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 forAPyFloatArray
. Specify force_complex to retrieve a complex-valued array type.- Parameters:
- n
int
Number of rows and columns in output.
- int_bits
int
, optional Number of fixed-point integer bits.
- frac_bits
int
, optional Number of fixed-point fractional bits.
- bits
int
, optional Number of fixed-point bits.
- exp_bits
int
, optional Number of floating-point exponential bits.
- man_bits
int
, optional Number of floating-point mantissa bits.
- bias
int
, optional Exponent bias. If not provided, bias is
2**exp_bits - 1
.- force_complex
bool
, optional Return the complex-valued array type,
APyCFixedArray
for fixed-point andAPyCFloatArray
for floating-point.
- n
- Returns:
- result
APyFloatArray
,APyFixedArray
orAPyCFixedArray
n x n array with ones (stored value) on the main diagonal and zeros elsewhere.
- result
- 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 forAPyFloatArray
. 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:
- shape
tuple
Shape of the array.
- fill_value
APyFloat
orAPyFixed
orint
or :class`float` Fill value.
- int_bits
int
, optional Number of fixed-point integer bits.
- frac_bits
int
, optional Number of fixed-point fractional bits.
- bits
int
, optional Number of fixed-point bits.
- exp_bits
int
, optional Number of floating-point exponential bits.
- man_bits
int
, optional Number of floating-point mantissa bits.
- bias
int
, optional Exponent bias. If not provided, bias is
2**exp_bits - 1
.
- shape
- Returns:
- result
APyFloatArray
orAPyFixedArray
Array of all fill_value with the given shape.
- result
- 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
andAPyCFixedArray
, or specify both exp_bits and man_bits forAPyFloatArray
.- Parameters:
- a
APyFixedArray
,APyFloatArray
, orAPyCFixedArray
The shape and data-type of a define these same attributes of the returned array.
- int_bits
int
, optional Number of fixed-point integer bits.
- frac_bits
int
, optional Number of fixed-point fractional bits.
- bits
int
, optional Number of fixed-point bits.
- exp_bits
int
, optional Number of floating-point exponential bits.
- man_bits
int
, optional Number of floating-point mantissa bits.
- bias
int
, optional Exponent bias. If not provided, bias is
2**exp_bits - 1
.
- a
- Returns:
- result
APyFloatArray
orAPyFixedArray
The initialized array with all zeros.
- result
- 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 forAPyFloatArray
.- Parameters:
- a
APyFixedArray
,APyFloatArray
, orAPyCFixedArray
The shape and data-type of a define these same attributes of the returned array.
- int_bits
int
, optional Number of fixed-point integer bits.
- frac_bits
int
, optional Number of fixed-point fractional bits.
- bits
int
, optional Number of fixed-point bits.
- exp_bits
int
, optional Number of floating-point exponential bits.
- man_bits
int
, optional Number of floating-point mantissa bits.
- bias
int
, optional Exponent bias. If not provided, bias is
2**exp_bits - 1
.
- a
- Returns:
- result
APyFloatArray
orAPyFixedArray
The array initialized filled with all ones.
- result
- 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 forAPyFloatArray
.- Parameters:
- a
APyFloatArray
orAPyFixedArray
The shape and array type of the returned array.
- fill_value
APyFloat
orAPyFixed
or int or float The value to fill the array with.
- int_bits
int
, optional Number of fixed-point integer bits.
- frac_bits
int
, optional Number of fixed-point fractional bits.
- bits
int
, optional Number of fixed-point bits.
- exp_bits
int
, optional Number of floating-point exponential bits.
- man_bits
int
, optional Number of floating-point mantissa bits.
- bias
int
, optional Exponent bias. If not provided, bias is
2**exp_bits - 1
.
- a
- Returns:
- result
APyFloatArray
orAPyFixedArray
Array filled with fill_value, having the same shape and type as a.
- result
- 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 includingstart
but excludingstop
).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 bystep
.
If no bit-specifiers are given, the array type is deduced based on
start
,stop
, andstep
. In this case, all APyTypes scalars must be of the same format.- Parameters:
- start
int
,float
,APyFloat
,APyFixed
Start number.
- stop
int
,float
,APyFloat
,APyFixed
, optional Stop number.
- step
int
,float
,APyFloat
,APyFixed
, optional Step size in range.
- int_bits
int
, optional Number of fixed-point integer bits.
- frac_bits
int
, optional Number of fixed-point fractional bits.
- bits
int
, optional Number of fixed-point bits.
- exp_bits
int
, optional Number of floating-point exponential bits.
- man_bits
int
, optional Number of floating-point mantissa bits.
- bias
int
, optional Exponent bias. If not provided, bias is
2**exp_bits - 1
.
- start
- Returns:
- result
APyFloatArray
orAPyFixedArray
Array with evenly spaced values within a given interval.
- result
- 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 includingstart
but excludingstop
).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
andstop
. In this case, all APyTypes scalars must be of the same format.- Parameters:
- start
int
,float
,APyFloat
,APyFixed
Start number.
- stop
int
,float
,APyFloat
,APyFixed
, optional Stop number.
- int_bits
int
, optional Number of fixed-point integer bits.
- frac_bits
int
, optional Number of fixed-point fractional bits.
- bits
int
, optional Number of fixed-point bits.
- exp_bits
int
, optional Number of floating-point exponential bits.
- man_bits
int
, optional Number of floating-point mantissa bits.
- bias
int
, optional Exponent bias. If not provided, bias is
2**exp_bits - 1
.
- start
- Returns:
- result
APyFloatArray
orAPyFixedArray
Array with all values within a given interval.
- result
- 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:
- arrays
APyFixedArray
,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.
- arrays
- Returns:
- resultlist of
APyFixedArray
,APyFloatArray
,APyCFixedArray
,APyCFloatArray
List of 2-D arrays representing the meshgrid.
- resultlist of
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:
- a
APyFloatArray
,APyFixedArray
,APyCFixedArray
, or APyCFloatArray
The array whose axes should be reordered.- axis
int
or tuple of ints Position in the expanded axes where the new axis (or axes) is placed.
- a
- Returns:
- result
APyFloatArray
orAPyFixedArray
Copy of a with the number of dimensions increased.
- result
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:
- collapsed
APyFloatArray
orAPyFixedArray
copy of a but collapsed
- 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:
- a
APyFloatArray
orAPyFixedArray
The array whose axes should be reordered.
- source
int
or sequence of int Original positions of the axes to move. These must be unique.
- destination
int
or sequence of int Destination positions for each of the original axes. These must also be unique.
- a
- Returns:
- result
APyFloatArray
orAPyFixedArray
Copy of array with moved axes.
- result
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:
- a
APyFloatArray
,APyFixedArray
, orAPyCFixedArray
, orAPyCFloatArray
Input array.
- axis
int
or tuple of ints, optional Selects a subset of the entries of length one in the shape.
- a
- Returns:
- squeezed
APyFloatArray
,APyFixedArray
,APyCFixedArray
, orAPyCFloatArray
The input array, but with all or a subset of the dimensions of length 1 removed.
- squeezed
- 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:
- a
APyFloatArray
orAPyFixedArray
The array whose axes should be reordered.
- axis1
int
First axis.
- axis2
int
Second axis.
- a
- Returns:
- a_swapped
APyFloatArray
orAPyFixedArray
Copy of a with axes swapped
- a_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:
- a
APyFloatArray
orAPyFixedArray
First one-dimensional array of length
M
- v
APyFloatArray
orAPyFixedArray
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
- a
- Returns:
- convolved
APyFloatArray
orAPyFixedArray
The convolved array.
- convolved
- apytypes.shape(arr: APyFixedArray | APyCFixedArray | APyFloatArray | APyCFloatArray) tuple[int, ...] ¶
Return the shape of an array.
- Parameters:
- arr
APyFloatArray
orAPyFixedArray
Input data.
- arr
- Returns:
- 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 shapeheight, width = a.shape
. For a 3-D array, VUnit’s integer_array package must be reshaped toheight, width, depth = a.shape
after importing it as a 2-D array. The array is stored in the CSV with the shapeheight, 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:
- a
APyFixedArray
orAPyFloatArray
The array to store the bit values of.
- fname
str
Path to the CSV file to store bit values.
- delimiter
str
, 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.
- a
See also
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:
- fname
str
Path to the CSV file containing bit values.
- delimiter
str
, optional Character used in the CSV file to separate bit values. Default is ,.
- int_bits
int
, optional Number of fixed-point integer bits.
- frac_bits
int
, optional Number of fixed-point fractional bits.
- bits
int
, optional Number of fixed-point bits.
- exp_bits
int
, optional Number of floating-point exponential bits.
- man_bits
int
, optional Number of floating-point mantissa bits.
- bias
int
, optional Exponent bias. If not provided, bias is
2**exp_bits - 1
.- force_complex
bool
, optional If True, forces the array to be treated as complex.
- layout{“default”, “vunit”}, default: “default”
Layout of the stored array.
- vunit_3d_shape
tuple
, optional Shape of the resulting 3-D array when using the “vunit” layout. Do not provide this for 1-D or 2-D arrays.
- fname
- Returns:
- result
APyFloatArray
orAPyFixedArray
Array created from the bit values in the CSV file.
- result
See also
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)