qrunch.common.arrays.array_protocols

Module for implementing protocols for arrays.

Classes

Array

Protocol for implementing arrays.

RotationBlockDefinition

Represents the slice of a block of a rotation matrix.

class Array

Bases: HasMetadataHashMethod, Protocol

Protocol for implementing arrays.

property H: Array

Hermitian conjugate of the Array.

property T: Array

Transpose of the Array.

__init__(*args, **kwargs)
compare(other: Array, rtol: float = 0.0) → bool

Return True if equal to other array.

Parameters:
  • other (Array) – The array to compare against.

  • rtol (float) – Relative tolerance for numerical comparison. If 0.0, exact equality is used.

Return type:

bool

conjugate() → Array

Conjugate all elements.

Return type:

Array

is_hermitian() → bool

Return true if the array is Hermitian.

Return type:

bool

property n_nonzero: int

Number of non-zero elements.

property ndim: int

Dimension of the array.

rotate(rotation_matrices: tuple[ndarray[tuple[Any, ...], dtype[float64]], ...]) → Self

Rotate the array with the given rotation matrix.

Parameters:

rotation_matrices (tuple[ndarray[tuple[Any, ...], dtype[float64]], ...]) – Tuple of 2-dimenional real symmetric matrix controlling the rotation. Should match the structure given by the output of the rotation_matrix_structure method.

Return type:

Self

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, ...]

Shape of the Array.

class RotationBlockDefinition

Bases: object

Represents the slice of a block of a rotation matrix.

All fields are immutable (frozen=True) so an instance can be safely reused.

Parameters:

shape – Shape of the rotation matrix.

__init__(shape: tuple[int, int]) → None
Parameters:

shape (tuple[int, int])

Return type:

None

n_free_params() → int

Get the amount of free parameters in the block.

Return type:

int

shape: tuple[int, int]
property size: int

Size of the block.