예제 #1
0
def test_neg():
    mv1 = MultiVector()
    mis1 = MultiindexSet.createCompleteOrderSet(3, 4)
    mv1.set_defaults(mis1, FlatVector([3, 4, 5]))
    mv = -mv1
    assert_equal(mv[Multiindex(mis1[-1])], FlatVector([-3, -4, -5]))
    assert_equal(mv1[Multiindex(mis1[-1])], FlatVector([3, 4, 5]))
예제 #2
0
def test_set_defaults():
    mv = MultiVector()
    mis = MultiindexSet.createCompleteOrderSet(3, 4)
    mv.set_defaults(mis, FlatVector([3, 4, 5]))
    assert_equal(mv[Multiindex([1, 2, 1])], FlatVector([3, 4, 5]))
    assert_equal(mv[Multiindex()], FlatVector([3, 4, 5]))
    assert_raises(KeyError, mv.__getitem__, Multiindex([1, 2, 2]))
예제 #3
0
def test_sub():
    mv1 = MultiVector()
    mv2 = MultiVector()
    mi1 = Multiindex([1, 2, 1])
    mi2 = Multiindex([3, 2, 1, 7])
    mis1 = MultiindexSet.createCompleteOrderSet(3, 4)
    mv1.set_defaults(mis1, FlatVector([3, 4, 5]))
    mv2.set_defaults(mis1, FlatVector([6, 8, 10]))
    mv1[mi2] = FlatVector([7, 10, 6])
    mv2[mi2] = FlatVector([2, 6, 13])
    mv3 = mv1 - mv2
    assert_equal(mv3[mi1], FlatVector([-3, -4, -5]))
    assert_equal(mv3[mi2], FlatVector([5, 4, -7]))
예제 #4
0
def test_mul():
    mv1 = MultiVector()
    mv2 = MultiVector()
    mis1 = MultiindexSet.createCompleteOrderSet(3, 4)
    #mis2 = MultiindexSet.createCompleteOrderSet(3, 5)
    mv1.set_defaults(mis1, FlatVector([3, 4, 5]))
    mv2.set_defaults(mis1, FlatVector([6, 8, 10]))
    assert_equal(2 * mv1, mv2)
    assert_equal(mv1 * 2, mv2)
    assert_equal(2.0 * mv1, mv2)
    assert_equal(mv1 * 2.0, mv2)
    assert_equal(mv1[Multiindex()], FlatVector([3, 4, 5]))
    assert_equal(mv1[Multiindex([1, 2, 1])], FlatVector([3, 4, 5]))
    mv1 *= 2.0
    assert_equal(mv1, mv2)
예제 #5
0
def test_mvwp_copy():
    # compares equal to copied MultiVectorWP but not to MultiVector 
    mv0 = MultiVector()
    mv1 = MultiVectorWithProjection()
    mis1 = MultiindexSet.createCompleteOrderSet(3, 4)
    mv0.set_defaults(mis1, FlatVector([3, 4, 5]))
    mv1.set_defaults(mis1, FlatVector([3, 4, 5]))
    mv2 = mv1.copy()
    assert_equal(mv2, mv1)
    assert_not_equal(mv2, mv0)

    # compares equal if project methods match, make sure project method is copied 
    mv3 = MultiVectorWithProjection(project=lambda : None)
    mv3.set_defaults(mis1, FlatVector([3, 4, 5]))
    mv4 = mv3.copy()
    assert_not_equal(mv2, mv3)
    assert_equal(mv4, mv3)
예제 #6
0
def test_add():
    mv1 = MultiVector()
    mv2 = MultiVector()
    mv3 = MultiVector()
    mis1 = MultiindexSet.createCompleteOrderSet(3, 4)
    mv1.set_defaults(mis1, FlatVector([3, 4, 5]))
    mv2.set_defaults(mis1, FlatVector([6, 8, 12]))
    mv3.set_defaults(mis1, FlatVector([9, 12, 17]))
    assert_equal(mv1 + mv2, mv3)
예제 #7
0
def test_equality():
    mv1 = MultiVector()
    mv2 = MultiVector()
    mv3 = MultiVector()
    mv4 = MultiVector()
    mis1 = MultiindexSet.createCompleteOrderSet(3, 4)
    mis2 = MultiindexSet.createCompleteOrderSet(3, 5)
    mv1.set_defaults(mis1, FlatVector([3, 4, 5]))
    mv2.set_defaults(mis1, FlatVector([3, 4, 5]))
    mv3.set_defaults(mis2, FlatVector([3, 4, 5]))
    mv4.set_defaults(mis1, FlatVector([3, 4, 6]))
    assert_true(mv1 == mv2)
    assert_false(mv1 != mv2)
    assert_true(mv1 != mv3)
    assert_false(mv1 == mv3)
    assert_true(mv1 != mv4)
    assert_false(mv1 == mv4)