Exemple #1
0
def test_sub(key, mat, quad):
    test = key[0]
    trial = key[1]
    m = mat((test[0](N, quad=quad), test[1]),
            (trial[0](N, quad=quad), trial[1]))
    mc = m - m
    assert mc.scale == 0.0

    m1 = shenfun.SparseMatrix(copy(dict(m)), m.shape)
    m2 = shenfun.SparseMatrix(copy(dict(m)), m.shape)

    mc = m1 - m2
    assert mc.scale == 0.0
Exemple #2
0
def test_iadd(key, mat, quad):
    test = key[0]
    trial = key[1]
    m = mat((test[0](N, quad=quad), test[1]),
            (trial[0](N, quad=quad), trial[1]))
    mc = deepcopy(m)
    m += mc
    assert m.scale == 2.0

    m1 = shenfun.SparseMatrix(deepcopy(dict(m)), m.shape)
    m2 = shenfun.SparseMatrix(deepcopy(dict(m)), m.shape)
    m1 += m2
    assert m1.scale == 2.0
Exemple #3
0
def test_mul2():
    mat = shenfun.SparseMatrix({0: 1}, (3, 3))
    v = np.ones(3)
    c = mat * v
    assert np.allclose(c, 1)
    mat = shenfun.SparseMatrix({-2:1, -1:1, 0: 1, 1:1, 2:1}, (3, 3))
    c = mat * v
    assert np.allclose(c, 3)
    SD = shenfun.Basis(8, "L", bc=(0, 0), plan=True, scaled=True)
    u = shenfun.TrialFunction(SD)
    v = shenfun.TestFunction(SD)
    mat = shenfun.inner(shenfun.grad(u), shenfun.grad(v))
    z = shenfun.Function(SD, val=1)
    c = mat * z
    assert np.allclose(c[:6], 1)
Exemple #4
0
def test_rmul(key, mat, quad):
    test = key[0]
    trial = key[1]
    m = mat((test[0](N, quad=quad), test[1]),
            (trial[0](N, quad=quad), trial[1]))
    mc = m*2.
    assert mc.scale == 2.0

    mat = shenfun.SparseMatrix(deepcopy(dict(m)), m.shape)
    mc = mat*2.
    assert mc.scale == 2.0
Exemple #5
0
def test_add(key, mat, quad):
    test = key[0]
    trial = key[1]
    m = mat((test[0](N, quad=quad), test[1]),
            (trial[0](N, quad=quad), trial[1]))
    mc = m + m
    assert mc.scale == 2.0

    mat = shenfun.SparseMatrix(deepcopy(dict(m)), m.shape)
    mc = m + mat
    for key, val in six.iteritems(mc):
        assert np.allclose(val, m[key]*2)
Exemple #6
0
def test_imul(key, mat, quad):
    test = key[0]
    trial = key[1]
    mat = mat((test[0](N, quad=quad), test[1]),
              (trial[0](N, quad=quad), trial[1]))
    mc = deepcopy(dict(mat))
    mat *= 2
    assert mat.scale == 2.0

    mat = shenfun.SparseMatrix(deepcopy(dict(mc)), mat.shape)
    mat *= 2
    assert mat.scale == 2.0
Exemple #7
0
def test_div(key, mat, quad):
    test = key[0]
    trial = key[1]
    m = mat((test[0](N, quad=quad), test[1]),
            (trial[0](N, quad=quad), trial[1]))

    mc = m / 2.
    assert mc.scale == 0.5

    mat = shenfun.SparseMatrix(copy(dict(m)), m.shape)
    mc = mat / 2.
    assert mc.scale == 0.5