コード例 #1
0
def NKron(matrix_A, matrix_B, *args):
    r"""计算两个及以上的矩阵的Kronecker积。

    Args:
        matrix_A (numpy.ndarray): 一个矩阵
        matrix_B (numpy.ndarray): 一个矩阵
        *args (numpy.ndarray): 其余矩阵

    Returns:
        ComplexVariable: 输入矩阵的Kronecker积

    .. code-block:: python
    
        from paddle_quantum.state import density_op_random
        from paddle_quantum.utils import NKron
        A = density_op_random(2)
        B = density_op_random(2)
        C = density_op_random(2)
        result = NKron(A, B, C)

    ``result`` 应为: :math:`A \otimes B \otimes C`
    """
    return reduce(
        lambda result, index: np_kron(result, index),
        args,
        np_kron(matrix_A, matrix_B),
    )
コード例 #2
0
ファイル: utils.py プロジェクト: shyamalschandra/Quantum-2
def NKron(AMatrix, BMatrix, *args):
    """
    Recursively execute kron n times. This function at least has two matrices.
    :param AMatrix: First matrix
    :param BMatrix: Second matrix
    :param args: If have more matrix, they are delivered by this matrix
    :return: The result of tensor product.
    """

    return reduce(
        lambda result, index: np_kron(result, index),
        args,
        np_kron(AMatrix, BMatrix), )
コード例 #3
0
ファイル: utils.py プロジェクト: test-tttt/test-rtd
def NKron(AMatrix, BMatrix, *args):
    r"""对输入的矩阵依次求克罗内克积

    Args:
        AMatrix (numpy.ndarray): 输入的矩阵A
        BMatrix (numpy.ndarray): 输入的矩阵B
        *args (numpy.ndarray): 输入的其他矩阵

    Returns:
        numpy.ndarray: 所求得的克罗内克积
    """

    return reduce(
        lambda result, index: np_kron(result, index),
        args,
        np_kron(AMatrix, BMatrix),
    )
コード例 #4
0
 def kron(self, other):
     '''
     Return self x other, where "x" is a Kronecker product operation.
     '''
     if self.isnone or other.isnone or self.mode != other.mode:
         raise ValueError('Incorrect input.')
     res = self.copy(copy_x=False)
     res.d = self.d + other.d
     if self.mode == MODE_NP or (self.mode == MODE_SP
                                 and self.type == 'vector'):
         res.x = np_kron(self.x, other.x)
     if self.mode == MODE_TT:
         res.x = tt_kron(other.x, self.x)
         res = res.round([self.tau, other.tau])
     if self.mode == MODE_SP and self.type == 'matrix':
         res.x = sp_kron(self.x, other.x)
     return res
コード例 #5
0
ファイル: numpy_builtin.py プロジェクト: AndiH/Python-STREAM
def triad(lhs, rhs1, rhs2, alpha):
    lhs = np_add(rhs1, np_kron(alpha, rhs2))
コード例 #6
0
ファイル: numpy_builtin.py プロジェクト: AndiH/Python-STREAM
def scale(lhs, rhs, alpha):
    lhs = np_kron(alpha, rhs)