APyCFloatArray
¶
- class apytypes.APyCFloatArray(*args, **kwargs)¶
Class for configurable complex-valued array floating-point formats.
Added in version 0.4.
Note
For real-valued floating-point formats, see
APyFloat
andAPyFloatArray
.- Attributes:
Methods
Broadcast array to new shape.
Change format of the floating-point array.
Return the discrete linear convolution with another one-dimensional array.
Create a copy of the object.
Return cumulative product of elements along a given axes.
Return the cumulative sum of the elements along a given axis.
Return a copy of the array collapsed into one dimension.
Test if two
APyCFloatArray
objects are identical.Return cumulative product of elements along a given axis treating NaN as 0.
Return cumulative sum of elements along a given axis treating NaN as 0.
Return product of the elements along a given axis treating NaN as 0.
Return the sum of the elements along specified axis/axes treating NaN as 0.
Return product of elements along specified axis/axes.
Return a copy of the array collapsed into one dimension.
Reshape the APyCFloatArray to the specified shape without changing its data.
Remove axes of size one at the specified axis/axes.
Return the sum of the elements along specified axis/axes.
Interchange two axes of an array.
Return array as a
numpy.ndarray
ofnumpy.complex128
.Return copy of array with axes transposed.
Constructor¶
Conversion to other types¶
- to_numpy(self) numpy.ndarray[dtype=complex128] ¶
Return array as a
numpy.ndarray
ofnumpy.complex128
.The returned array has the same shape and values as self. This method rounds away from infinity on ties.
- Returns:
Creation from other types¶
- from_array(ndarray: ndarray[order='C'], exp_bits: int, man_bits: int, bias: int | None = None) APyCFloatArray ¶
Create an
APyCFloatArray
from an ndarray.- Parameters:
- Returns:
See also
Examples
>>> import apytypes as apy >>> import numpy as np >>> a = apy.APyCFloatArray.from_array( ... np.array([ ... [1.0, 2.0, 3.0], ... [4.0, 5.0, 6.0], ... ]), ... man_bits=10, ... exp_bits=10 ... ) >>> print(a) [[1+0j, 2+0j, 3+0j], [4+0j, 5+0j, 6+0j]]
- from_float(complex_sequence: Iterable[Any], exp_bits: int, man_bits: int, bias: int | None = None) APyCFloatArray ¶
Create an
APyCFloatArray
from iterable sequence of numbers.This is an alias for
from_complex()
, look there for more documentation.- Parameters:
- complex_sequence
Iterable
of numbers. Values to initialize from. The tensor shape will be taken from the sequence shape.
- exp_bits
int
Number of exponent bits in the created floating-point tensor.
- man_bits
int
Number of mantissa bits in the created floating-point tensor.
- bias
int
, optional Bias in the created floating-point tensor.
- complex_sequence
- Returns:
- from_complex(complex_sequence: Iterable[Any], exp_bits: int, man_bits: int, bias: int | None = None) APyCFloatArray ¶
Create an
APyCFloatArray
from iterable sequence of numbers.Using NumPy arrays as input is in general faster than using e.g. lists.
- Parameters:
- complex_sequence
Iterable
of numbers. Values to initialize from. The tensor shape will be taken from the sequence shape.
- exp_bits
int
Number of exponent bits in the created floating-point tensor.
- man_bits
int
Number of mantissa bits in the created floating-point tensor.
- bias
int
, optional Bias in the created floating-point tensor.
- complex_sequence
- Returns:
See also
Examples
>>> import apytypes as apy >>> a = apy.APyCFloatArray.from_complex( ... [1.0, 1.25, 1.49], exp_bits=4, man_bits=6 ... ) >>> a APyCFloatArray( [ (0, 0), (0, 0), (0, 0)], [ (7, 0), (7, 0), (7, 0)], [ (0, 0), (16, 0), (31, 0)], exp_bits=4, man_bits=6 ) >>> print(a) [ 1+0j, 1.25+0j, 1.484375+0j]
>>> b = apy.APyCFloatArray.from_complex( ... [ ... [1.0, 2.0, 3.0], ... [4.0, 5.0, 6.0], ... ], ... exp_bits=5, ... man_bits=2 ... ) >>> b APyCFloatArray( [[ (0, 0), (0, 0), (0, 0)], [ (0, 0), (0, 0), (0, 0)]], [[(15, 0), (16, 0), (16, 0)], [(17, 0), (17, 0), (17, 0)]], [[ (0, 0), (0, 0), (2, 0)], [ (0, 0), (1, 0), (2, 0)]], exp_bits=5, man_bits=2 ) >>> print(b) [[1+0j, 2+0j, 3+0j], [4+0j, 5+0j, 6+0j]]
Other creation functions¶
- copy(self) APyCFloatArray ¶
Create a copy of the object.
- eye(n: int, exp_bits: int, man_bits: int, m: int | None = None, bias: int | None = None) APyCFloatArray ¶
Initialize an array with ones on the diagonal.
- Parameters:
- Returns:
APyCFloatArray
An array with the specified value on the diagonal.
- full(shape: int | tuple[int, ...], fill_value: APyCFloat) APyCFloatArray ¶
Initialize an array filled with the specified value.
- Parameters:
- shape
tuple
Shape of the array.
- fill_valueAPyFloat
Value to fill the array.
- shape
- Returns:
APyCFloatArray
An array filled with the specified value.
- identity(n: int, exp_bits: int, man_bits: int, bias: int | None = None) APyCFloatArray ¶
Initialize an identity matrix with ones on the diagonal.
- Parameters:
- Returns:
APyCFloatArray
An identity matrix with ones on the diagonal.
- ones(shape: int | tuple[int, ...], exp_bits: int, man_bits: int, bias: int | None = None) APyCFloatArray ¶
Initialize an array with ones.
- Parameters:
- Returns:
APyCFloatArray
An array filled with ones.
- zeros(shape: int | tuple[int, ...], exp_bits: int, man_bits: int, bias: int | None = None) APyCFloatArray ¶
Initialize an array with zeros.
- Parameters:
- Returns:
APyCFloatArray
An array filled with zeros.
Change word length¶
- cast(self, exp_bits: int | None = None, man_bits: int | None = None, bias: int | None = None, quantization: QuantizationMode | None = None) APyCFloatArray ¶
Change format of the floating-point array.
This is the primary method for performing quantization when dealing with APyTypes floating-point arrays.
- Parameters:
- exp_bits
int
, optional Number of exponent bits in the result.
- man_bits
int
, optional Number of mantissa bits in the result.
- bias
int
, optional Bias used in the result.
- quantization
QuantizationMode
, optional. Quantization mode to use in this cast. If None, use the global quantization mode.
- exp_bits
- Returns:
Comparison¶
- is_identical(self, other: object, ignore_zero_sign: bool = False) bool ¶
Test if two
APyCFloatArray
objects are identical.Two
APyCFloatArray
objects are considered identical if, and only if:They represent exactly the same tensor shape
They store the exact same floating-point values in all elements
They have the exact same bit format (exp_bits, man_bits, and bias)
- Parameters:
- other
APyCFloatArray
The floating-point object to test identicality against.
- ignore_zero_sign
bool
, default:False
If
True
, plus and minus zero are considered identical. IfFalse
, plus and minus zero are considered different.
- other
- Returns:
Convolution¶
- convolve(self, other: APyCFloatArray, mode: str = 'full') APyCFloatArray ¶
Return the discrete linear convolution with another one-dimensional array.
Requires that
ndim = 1
for both self and other.- Parameters:
- other
APyCFloatArray
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
- other
- Returns:
- convolved
APyCFloatArray
The convolved array.
- convolved
Transposition¶
- transpose(self, axes: tuple[int, ...] | None = None) APyCFloatArray ¶
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:
- axes
tuple
ofint
, 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 torange(a.ndim)[::-1]
, which reverses the order of the axes.
- axes
- Returns:
APyCFloatArray
a with its axes permuted.
Examples
>>> import apytypes as apy >>> a = apy.APyCFloatArray.from_float( ... [[ 1.0, 2.0, 3.0], ... [-4.0, -5.0, -6.0]], ... exp_bits=5, ... man_bits=5 ... ) >>> print(a) [[ 1+0j, 2+0j, 3+0j], [-4+0j, -5+0j, -6+0j]] >>> print(a.transpose()) [[ 1+0j, -4+0j], [ 2+0j, -5+0j], [ 3+0j, -6+0j]]
>>> b = apy.APyCFloatArray.from_float( ... [1.0] * 6, ... exp_bits=5, ... man_bits=5 ... ).reshape((1, 2, 3)) >>> b.transpose((1, 0, 2)).shape (2, 1, 3) >>> b.transpose((-2, -3, -1)).shape (2, 1, 3)
Array shape manipulation¶
- flatten(self) APyCFloatArray ¶
Return a copy of the array collapsed into one dimension.
- Returns:
Examples
>>> import apytypes as apy >>> arr = apy.APyCFloatArray.from_float([[ 1, 2], ... [-3, -4]], exp_bits=8, man_bits=23) >>> print(arr) [[ 1+0j, 2+0j], [-3+0j, -4+0j]] >>> print(arr.flatten()) [ 1+0j, 2+0j, -3+0j, -4+0j]
- ravel(self) APyCFloatArray ¶
Return a copy of the array collapsed into one dimension. Same as flatten with current memory-copy model.
- Returns:
Examples
>>> import apytypes as apy >>> arr = apy.APyCFloatArray.from_float([[ 1, 2], ... [-3, -4]], exp_bits=8, man_bits=23) >>> print(arr) [[ 1+0j, 2+0j], [-3+0j, -4+0j]] >>> print(arr.ravel()) [ 1+0j, 2+0j, -3+0j, -4+0j]
- reshape(self, new_shape: int | tuple[int, ...]) APyCFloatArray ¶
Reshape the APyCFloatArray to the specified shape without changing its data.
- Parameters:
- Returns:
- 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
>>> import apytypes as apy >>> arr = apy.APyCFloatArray.from_float( ... [1, 2, -3, -4], exp_bits=8, man_bits=23 ... ) >>> print(arr) [ 1+0j, 2+0j, -3+0j, -4+0j] >>> print(arr.reshape((2, 2))) [[ 1+0j, 2+0j], [-3+0j, -4+0j]] >>> print(arr.reshape((4, 1))) [[ 1+0j], [ 2+0j], [-3+0j], [-4+0j]]
- squeeze(self, axis: int | tuple[int, ...] | None = None) APyCFloatArray ¶
Remove axes of size one at the specified axis/axes.
If no axis is given, remove all dimensions with size one.
- Parameters:
- Returns:
- 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) APyCFloatArray ¶
Interchange two axes of an array.
- Parameters:
- Returns:
- a_swapped
APyCFloatArray
Copy of a with axes swapped
- a_swapped
Examples
>>> import apytypes as apy >>> a = apy.APyCFloatArray.from_float( ... [[1, 2, 3]], exp_bits=5, man_bits=2 ... ) >>> print(a) [[1+0j, 2+0j, 3+0j]] >>> print(a.swapaxes(0, 1)) [[1+0j], [2+0j], [3+0j]]
>>> b = apy.APyCFloatArray.from_float( ... [[[0, 1], ... [2, 3]], ... ... [[4, 5], ... [6, 7]]], ... exp_bits=5, ... man_bits=5 ... ) >>> print(b) [[[0+0j, 1+0j], [2+0j, 3+0j]], [[4+0j, 5+0j], [6+0j, 7+0j]]] >>> print(b.swapaxes(0,2)) [[[0+0j, 4+0j], [2+0j, 6+0j]], [[1+0j, 5+0j], [3+0j, 7+0j]]]
Mathematical functions¶
- sum(self, axis: int | tuple[int, ...] | None = None) APyCFloatArray | APyCFloat ¶
Return the sum of the elements along specified axis/axes.
- Parameters:
- Returns:
- Raises:
IndexError
If a specified axis is outside of the existing number of dimensions for the array.
Examples
>>> import apytypes as apy >>> a = apy.APyCFloatArray.from_float( ... [1, 2, 3, 4, 5, 6], ... exp_bits=10, ... man_bits=10 ... ) >>> print(a) [1+0j, 2+0j, 3+0j, 4+0j, 5+0j, 6+0j] >>> print(a.sum()) (21+0j)
- prod(self, axis: int | tuple[int, ...] | None = None) APyCFloatArray | APyCFloat ¶
Return product of elements along specified axis/axes.
- Parameters:
- axis
tuple
, int, optional The axis/axes to calculate the product across. If not given an axis it will return the product of the flattened array.
- axis
- Returns:
- Raises:
IndexError
If a specified axis is outside of the existing number of dimensions for the array.
Examples
>>> import apytypes as apy >>> a = apy.APyCFloatArray.from_float( ... [1, 2, 3, 4, 5, 6], exp_bits=10, man_bits=10 ... ) >>> print(a) [1+0j, 2+0j, 3+0j, 4+0j, 5+0j, 6+0j] >>> print(a.prod()) (720+0j)
- nansum(self, axis: int | tuple[int, ...] | None = None) APyCFloatArray | APyCFloat ¶
Return the sum of the elements along specified axis/axes treating NaN as 0.
- Parameters:
- Returns:
- Raises:
IndexError
If a specified axis is outside of the existing number of dimensions for the array.
Examples
>>> import apytypes as apy >>> nan = float("nan") >>> a = apy.APyCFloatArray.from_float( ... [1, 2, 3, 4, 5, nan], ... exp_bits=10, ... man_bits=10 ... ) >>> print(a) [ 1+0j, 2+0j, 3+0j, 4+0j, 5+0j, nan+0j] >>> print(a.sum()) (nan+0j) >>> print(a.nansum()) (15+0j)
- nanprod(self, axis: int | tuple[int, ...] | None = None) APyCFloatArray | APyCFloat ¶
Return product of the elements along a given axis treating NaN as 0.
- Parameters:
- axis
int
, optional The axis to calculate the product across. If not given an axis it will return the product of the flattened array.
- axis
- Returns:
- Raises:
IndexError
If a specified axis is outside of the existing number of dimensions for the array.
- cumsum(self, axis: int | None = None) APyCFloatArray ¶
Return the cumulative sum of the elements along a given axis.
- Parameters:
- axis
int
, optional The axis to summate across. If not given an axis it will return the cumulative sum of the flattened array.
- axis
- Returns:
- Raises:
IndexError
If a specified axis is outside of the existing number of dimensions for the array.
Examples
>>> import apytypes as apy >>> a = apy.APyCFloatArray.from_float([[1, 2, 3], ... [4, 5, 6]], exp_bits=10, man_bits=10) >>> print(a) [[1+0j, 2+0j, 3+0j], [4+0j, 5+0j, 6+0j]] >>> print(a.cumsum()) [ 1+0j, 3+0j, 6+0j, 10+0j, 15+0j, 21+0j] >>> print(a.cumsum(0)) [[1+0j, 2+0j, 3+0j], [5+0j, 7+0j, 9+0j]] >>> print(a.cumsum(1)) [[ 1+0j, 3+0j, 6+0j], [ 4+0j, 9+0j, 15+0j]]
- cumprod(self, axis: int | None = None) APyCFloatArray ¶
Return cumulative product of elements along a given axes.
- Parameters:
- axis
int
, optional The axes to calculate the product across. If not given an axis it will return the cumulative product of the flattened array.
- axis
- Returns:
- Raises:
IndexError
If a specified axis is outside of the existing number of dimensions for the array.
Examples
>>> import apytypes as apy >>> a = apy.APyCFloatArray.from_float( ... [[1, 2, 3], ... [4, 5, 6]], ... exp_bits=10, ... man_bits=10 ... ) >>> print(a) [[1+0j, 2+0j, 3+0j], [4+0j, 5+0j, 6+0j]] >>> print(a.cumprod()) [ 1+0j, 2+0j, 6+0j, 24+0j, 120+0j, 720+0j] >>> print(a.cumprod(0)) [[ 1+0j, 2+0j, 3+0j], [ 4+0j, 10+0j, 18+0j]] >>> print(a.cumprod(1)) [[ 1+0j, 2+0j, 6+0j], [ 4+0j, 20+0j, 120+0j]]
- nancumsum(self, axis: int | None = None) APyCFloatArray ¶
Return cumulative sum of elements along a given axis treating NaN as 0.
- Parameters:
- axis
int
, optional The axis to summate across. If not given an axis it will return the cumulative sum of the flattened array.
- axis
- Returns:
- Raises:
IndexError
If a specified axis is outside of the existing number of dimensions for the array.
Examples
>>> import apytypes as apy >>> nan = float("nan") >>> a = apy.APyCFloatArray.from_float( ... [[ 1, 2, 3], ... [ 4, nan, 6]], ... exp_bits=10, ... man_bits=10 ... ) >>> print(a) [[ 1+0j, 2+0j, 3+0j], [ 4+0j, nan+0j, 6+0j]] >>> print(a.cumsum()) [ 1+0j, 3+0j, 6+0j, 10+0j, nan+0j, nan+0j] >>> print(a.nancumsum()) [ 1+0j, 3+0j, 6+0j, 10+0j, 10+0j, 16+0j]
>>> print(a.cumsum(0)) [[ 1+0j, 2+0j, 3+0j], [ 5+0j, nan+0j, 9+0j]] >>> print(a.nancumsum(0)) [[1+0j, 2+0j, 3+0j], [5+0j, 2+0j, 9+0j]]
>>> print(a.cumsum(1)) [[ 1+0j, 3+0j, 6+0j], [ 4+0j, nan+0j, nan+0j]] >>> print(a.nancumsum(1)) [[ 1+0j, 3+0j, 6+0j], [ 4+0j, 4+0j, 10+0j]]
- nancumprod(self, axis: int | None = None) APyCFloatArray ¶
Return cumulative product of elements along a given axis treating NaN as 0.
- Parameters:
- axis
int
, optional The axis to calculate the product across. If not given an axis it will return the cumulative product of the flattened array.
- axis
- Returns:
- Raises:
IndexError
If a specified axis is outside of the existing number of dimensions for the array.
Broadcasting¶
- broadcast_to(self, shape: int | tuple[int, ...]) APyCFloatArray ¶
Broadcast array to new shape.
- Parameters:
- Returns:
Convenience casting methods¶
Properties¶
Word length¶
Array properties¶
Transposition¶
- property T¶
The transposition of the array.
Equivalent to calling
APyCFloatArray.transpose()
.- Returns: