예제 #1
0
def test_block_diag():
    assert np.allclose(cirq.block_diag(), np.zeros((0, 0)))

    assert np.allclose(cirq.block_diag(np.array([[1, 2], [3, 4]])),
                       np.array([[1, 2], [3, 4]]))

    assert np.allclose(
        cirq.block_diag(np.array([[1, 2], [3, 4]]),
                        np.array([[4, 5, 6], [7, 8, 9], [10, 11, 12]])),
        np.array([[1, 2, 0, 0, 0], [3, 4, 0, 0, 0], [0, 0, 4, 5, 6],
                  [0, 0, 7, 8, 9], [0, 0, 10, 11, 12]]))
예제 #2
0
def test_block_diag_dtype():
    assert cirq.block_diag().dtype == np.complex128

    assert (cirq.block_diag(np.array([[1]], dtype=np.int8)).dtype ==
            np.int8)

    assert cirq.block_diag(
            np.array([[1]], dtype=np.float32),
            np.array([[2]], dtype=np.float32)).dtype == np.float32

    assert cirq.block_diag(
            np.array([[1]], dtype=np.float64),
            np.array([[2]], dtype=np.float64)).dtype == np.float64

    assert cirq.block_diag(
            np.array([[1]], dtype=np.float32),
            np.array([[2]], dtype=np.float64)).dtype == np.float64

    assert cirq.block_diag(
            np.array([[1]], dtype=np.float32),
            np.array([[2]], dtype=np.complex64)).dtype == np.complex64

    assert cirq.block_diag(
            np.array([[1]], dtype=np.int),
            np.array([[2]], dtype=np.complex128)).dtype == np.complex128
예제 #3
0
def random_block_diagonal_symmetric_matrix(*ns: int) -> np.ndarray:
    return cirq.block_diag(*[random_symmetric_matrix(n) for n in ns])