qrisp.inplace_matrix_app#

inplace_matrix_app(vector, matrix)[source]#

Performs inplace matrix application to a vector-valued QuantumArray. Note that due to reversibility reasons, the matrix can only contain integers and has to be invertible over \(\text{GL}(2^n)\). This is equal to the condition that the determinant is odd.

Parameters
vectorQuantumArray

The QuantumArray to apply the matrix to.

matrixnumpy.ndarray

The matrix to apply.

Raises
Exception

Tried to multiply matrix with Quantum Array with unfitting shape.

Examples

We perform an inplace matrix multiplication between a randomly chosen matrix and a randomly chosen vector

>>> from qrisp import QuantumFloat, QuantumArray, inplace_matrix_app
>>> qtype = QuantumFloat(4)
>>> q_vector = QuantumArray(qtype, 3)
>>> q_vector[:] = [1,0,2]
>>> matrix = np.array([[2., 2., 1.],
                       [2., 3., 1.],
                       [3., 1., 2.]])
>>> inplace_matrix_app(q_vector, matrix)
>>> print(q_vector)
{OutcomeArray([4, 4, 7]): 1.0}