Esempio n. 1
0
def validate(*args):
    if not all(arg.is_Matrix for arg in args):
        raise TypeError("Mix of Matrix and Scalar symbols")
    A = args[0]
    for B in args[1:]:
        if A.shape != B.shape:
            raise ShapeError("Matrices %s and %s are not aligned" % (A, B))
Esempio n. 2
0
 def __new__(cls, mat):
     mat = _sympify(mat)
     if not mat.is_Matrix:
         raise TypeError("mat should be a matrix")
     if not mat.is_square:
         raise ShapeError("Inverse of non-square matrix %s" % mat)
     return Basic.__new__(cls, mat)
Esempio n. 3
0
 def __new__(cls, mat, exp=S(-1)):
     # exp is there to make it consistent with
     # inverse.func(*inverse.args) == inverse
     mat = _sympify(mat)
     if not mat.is_Matrix:
         raise TypeError("mat should be a matrix")
     if not mat.is_square:
         raise ShapeError("Inverse of non-square matrix %s" % mat)
     return Basic.__new__(cls, mat, exp)
Esempio n. 4
0
def validate(*matrices):
    """ Checks for valid shapes for args of MatMul """
    for i in range(len(matrices)-1):
        A, B = matrices[i:i+2]
        if A.cols != B.rows:
            raise ShapeError("Matrices %s and %s are not aligned"%(A, B))
Esempio n. 5
0
 def __new__(cls, mat):
     mat = _sympify(mat)
     assert mat.is_Matrix
     if not mat.is_square:
         raise ShapeError("Inverse of non-square matrix %s" % mat)
     return Basic.__new__(cls, mat)