Exemplo n.º 1
0
def normalize_real_part(vecs, transposed=False):
    """Take the real part of a set of vectors and normalize it. This is used
    for returning real eigenvectors even when the PETSc scalar type is complex.
    """
    k = vecs.shape[0] if transposed else vecs.shape[1]

    vecs = np.ascontiguousarray(vecs.real)
    for i in range(k):
        where = (i, Ellipsis) if transposed else (Ellipsis, i)
        qu.nmlz(vecs[where], inplace=True)

    return vecs
Exemplo n.º 2
0
 def test_normalize_inplace_dop(self):
     a = qu.qu([1, -1j], 'dop')
     b = qu.nmlz(a, inplace=True)
     assert_almost_equal(qu.trace(a), 1.0)
     assert_almost_equal(qu.trace(b), 1.0)
Exemplo n.º 3
0
 def test_normalize_ket(self):
     a = qu.qu([1, -1j], 'ket')
     b = qu.nmlz(a, inplace=False)
     assert_almost_equal(qu.trace(b.H @ b), 1.0)
     assert_almost_equal(qu.trace(a.H @ a), 2.0)
Exemplo n.º 4
0
 def test_normalize_bra(self):
     a = qu.qu([1, -1j], 'bra')
     b = qu.nmlz(a, inplace=False)
     assert_almost_equal(qu.trace(b @ b.H), 1.0)
Exemplo n.º 5
0
 def test_normalize_dop(self):
     a = qu([1, -1j], 'dop')
     b = nmlz(a, inplace=False)
     assert_almost_equal(trace(b), 1.0)