Esempio n. 1
0
def test_copy():
    # make sure the vectors are copied and each have their own copy of
    # the data
    mv = MultiVector()
    mv[Multiindex([1, 2, 3])] = FlatVector([3, 4, 5])
    mv[Multiindex([1, 2, 4])] = FlatVector([3, 4, 7])
    assert_equal(mv[Multiindex([1, 2, 3])], FlatVector([3, 4, 5]))
    assert_equal(mv[Multiindex([1, 2, 4])], FlatVector([3, 4, 7]))
    mv2 = mv.copy()
    mv[Multiindex([1, 2, 3])].coeffs[2] = 8
    assert_equal(mv2[Multiindex([1, 2, 3])], FlatVector([3, 4, 5]))
    assert_equal(mv2[Multiindex([1, 2, 4])], FlatVector([3, 4, 7]))
    assert_equal(mv[Multiindex([1, 2, 3])], FlatVector([3, 4, 8]))
Esempio n. 2
0
def evaluate_operator_matrix(op):
    """Evaluate matrix representation of operator"""

    N = op.dim
    A = np.matrix(np.zeros((N, N)))
    e = FlatVector(np.zeros((N,)))
    T = time.time()
    for i in range(N):
        dt = time.time() - T
        if dt > 1:
            print "\t%i of %i (dt=%s)" % (i, N, dt)
            T = time.time()
        e.coeffs[i] = 1
        A[:, i] = op.apply(e).coeffs[:, None]
        e.coeffs[i] = 0
    return A