Example #1
0
def test_linear_factors():
    from sympy.matrices import MatrixSymbol, linear_factors
    n, m, l = symbols('n m l')
    A = MatrixSymbol('A', n, m)
    B = MatrixSymbol('B', m, l)
    C = MatrixSymbol('C', n, l)

    assert linear_factors(2 * A * B + C, B, C) == {C: Identity(n), B: 2 * A}
    assert linear_factors(2 * A * B + C, B) == {B: 2 * A}
    assert linear_factors(2 * A * B, B) == {B: 2 * A}
    assert linear_factors(2 * A * B, C) == {C: ZeroMatrix(n, n)}

    A = MatrixSymbol('A', n, n)
    B = MatrixSymbol('B', n, n)
    C = MatrixSymbol('C', n, n)
    D = MatrixSymbol('C', m, m)
    raises(ValueError, lambda: linear_factors(2 * A * A + B, A))
    raises(ValueError, lambda: linear_factors(2 * A * A, A))
    raises(ValueError, lambda: linear_factors(2 * A * B, A, B))
    raises(ShapeError, lambda: linear_factors(2 * A * B, D))
    raises(ShapeError, lambda: linear_factors(2 * A * B + C, D))

    assert linear_factors(A, A) == {A: Identity(n)}
Example #2
0
def test_linear_factors():
    from sympy.matrices import MatrixSymbol, linear_factors
    n, m, l = symbols('n m l')
    A = MatrixSymbol('A', n, m)
    B = MatrixSymbol('B', m, l)
    C = MatrixSymbol('C', n, l)

    assert linear_factors(2*A*B + C, B, C) == { C: Identity(n), B: 2*A}
    assert linear_factors(2*A*B + C, B) == { B: 2*A}
    assert linear_factors(2*A*B, B) == {B: 2*A}
    assert linear_factors(2*A*B, C) == {C: ZeroMatrix(n, n)}

    A = MatrixSymbol('A', n, n)
    B = MatrixSymbol('B', n, n)
    C = MatrixSymbol('C', n, n)
    D = MatrixSymbol('C', m, m)
    raises(ValueError, "linear_factors(2*A*A + B, A)")
    raises(ValueError, "linear_factors(2*A*A, A)")
    raises(ValueError, "linear_factors(2*A*B, A, B)")
    raises(ShapeError, "linear_factors(2*A*B, D)")
    raises(ShapeError, "linear_factors(2*A*B+C, D)")

    assert linear_factors(A, A) == {A:Identity(n)}
Example #3
0
def test_linear_factors():
    from sympy.matrices import MatrixSymbol, linear_factors

    n, m, l = symbols("n m l")
    A = MatrixSymbol("A", n, m)
    B = MatrixSymbol("B", m, l)
    C = MatrixSymbol("C", n, l)

    assert linear_factors(2 * A * B + C, B, C) == {C: Identity(n), B: 2 * A}
    assert linear_factors(2 * A * B + C, B) == {B: 2 * A}
    assert linear_factors(2 * A * B, B) == {B: 2 * A}
    assert linear_factors(2 * A * B, C) == {C: ZeroMatrix(n, n)}

    A = MatrixSymbol("A", n, n)
    B = MatrixSymbol("B", n, n)
    C = MatrixSymbol("C", n, n)
    D = MatrixSymbol("C", m, m)
    raises(ValueError, lambda: linear_factors(2 * A * A + B, A))
    raises(ValueError, lambda: linear_factors(2 * A * A, A))
    raises(ValueError, lambda: linear_factors(2 * A * B, A, B))
    raises(ShapeError, lambda: linear_factors(2 * A * B, D))
    raises(ShapeError, lambda: linear_factors(2 * A * B + C, D))

    assert linear_factors(A, A) == {A: Identity(n)}