qrunch.common.arrays.sparse_array
Simple implementation of a sparse array that can be iterated over.
Classes
Sparse multi-dimensional array. |
- class SparseArray
Bases:
Array,HasCustomEncodingSparse multi-dimensional array.
- property H: SparseArray
Return the Hermitian conjugate of the SparseArray.
- property T: SparseArray
Return the transpose of the SparseArray.
- __init__(dimensions: tuple[int, ...], data: Mapping[tuple[int, ...], float | complex | float64 | complex128]) None
Initialize the Sparse Array.
- Parameters:
dimensions (tuple[int, ...])
data (Mapping[tuple[int, ...], float | complex | float64 | complex128])
- Return type:
None
- compare(other: Array) bool
Return True, if equal to other array.
- Parameters:
other (Array)
- Return type:
bool
- conjugate() SparseArray
Conjugate all elements.
- Return type:
- property coordinates: ndarray[Any, dtype[float64]] | ndarray[Any, dtype[complex128]]
Get the coordinates stored in the sparse array.
- property data: ndarray[Any, dtype[float64]] | ndarray[Any, dtype[complex128]]
Get the data stored corresponding to the coordinates.
- classmethod decode(data: dict[str, Any]) SparseArray
Decode a dictionary.
- Parameters:
data (dict[str, Any]) – The dictionary representation.
- Return type:
- property dtype: type[float64] | type[complex128]
Get type of underlying data.
- encode() dict[str, Any]
Encode the instance into a dictionary.
- Return type:
dict[str, Any]
- is_hermitian() bool
Return true if the sparse array is Hermitian.
- Return type:
bool
- property n_nonzero: int
Return the amount of non-zero elements.
- property ndim: int
Dimension of the sparse array.
- rotate(rotation_matrices: tuple[ndarray[Any, dtype[float64]], ...]) SparseArray
Rotate the array with the given rotation matrix.
- Parameters:
rotation_matrices (tuple[ndarray[Any, dtype[float64]], ...]) – 2-dimensional real symmetric matrix controlling the rotation. Should match the structure given by the output of the rotation_matrix_structure method.
- Return type:
- rotation_matrix_structure() list[RotationBlockDefinition]
Get information on which blocks should be non-zero in the rotation matrix.
- Return type:
list[RotationBlockDefinition]
- property shape: tuple[int, ...]
Return the shape of the SparseArray.