def test_equality(): a, b, c = Identity(3), eye(3), ImmutableMatrix(eye(3)) for x in [a, b, c]: for y in [a, b, c]: assert x.equals(y)
def test_Identity_doit(): Inn = Identity(Add(n, n, evaluate=False)) assert isinstance(Inn.rows, Add) assert Inn.doit() == Identity(2*n) assert isinstance(Inn.doit().rows, Mul)
import pytest from diofant import (Identity, ImmutableMatrix, MatAdd, Matrix, MatrixExpr, MatrixSymbol, eye) from diofant.abc import a from diofant.matrices.matrices import classof __all__ = () SM = MatrixSymbol('X', 3, 3) MM = Matrix([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) IM = ImmutableMatrix([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) meye = eye(3) imeye = ImmutableMatrix(eye(3)) ideye = Identity(3) def test_IM_MM(): assert isinstance(MM + IM, ImmutableMatrix) assert isinstance(IM + MM, ImmutableMatrix) assert isinstance(2 * IM + MM, ImmutableMatrix) assert MM.equals(IM) assert MM.equals(2) is False def test_ME_MM(): assert isinstance(Identity(3) + MM, MatrixExpr) assert isinstance(SM + MM, MatAdd) assert isinstance(MM + SM, MatAdd) assert (Identity(3) + MM)[1, 1] == 6
def test_ME_MM(): assert isinstance(Identity(3) + MM, MatrixExpr) assert isinstance(SM + MM, MatAdd) assert isinstance(MM + SM, MatAdd) assert (Identity(3) + MM)[1, 1] == 6
def test_remove_ids(): assert remove_ids(MatMul(A, Identity(m), B, evaluate=False)) == \ MatMul(A, B, evaluate=False) assert null_safe(remove_ids)(MatMul(Identity(n), evaluate=False)) == \ MatMul(Identity(n), evaluate=False)
def test_xxinv(): assert xxinv(MatMul(D, Inverse(D), D, evaluate=False)) == \ MatMul(Identity(n), D, evaluate=False)
def test_doit_square_MatrixSymbol_symsize(): assert MatPow(C, 0).doit() == Identity(n) assert MatPow(C, 0).doit(deep=False) == Identity(n) assert MatPow(C, 1).doit() == C for r in [2, -1, pi]: assert MatPow(C, r).doit() == MatPow(C, r)
def test_as_explicit_symbol(): X = MatrixSymbol('X', 2, 2) assert MatPow(X, 0).as_explicit() == ImmutableMatrix(Identity(2)) assert MatPow(X, 1).as_explicit() == X.as_explicit() assert MatPow(X, 2).as_explicit() == (X.as_explicit())**2
def test_eval_determinant(): assert det(Matrix()) == 1 assert det(Identity(n)) == 1 assert det(ZeroMatrix(n, n)) == 0 assert det(Transpose(A)) == det(A)
def test_errors(): pytest.raises(IndexError, lambda: Identity(2)[1, 2, 3, 4, 5]) pytest.raises(IndexError, lambda: Identity(2)[[1, 2, 3, 4, 5]])
def test_Identity_index(): I = Identity(3) assert I[0, 0] == I[1, 1] == I[2, 2] == 1 assert I[1, 0] == I[0, 1] == I[2, 1] == 0 pytest.raises(IndexError, lambda: I[3, 3])