Ejemplo n.º 1
0
    def __new__(cls, function, expr):
        expr = _sympify(expr)
        if not expr.is_Matrix:
            raise ValueError("{} must be a matrix instance.".format(expr))

        if not isinstance(function, (FunctionClass, Lambda)):
            d = Dummy('d')
            function = Lambda(d, function(d))

        function = sympify(function)
        if not isinstance(function, (FunctionClass, Lambda)):
            raise ValueError(
                "{} should be compatible with SymPy function classes."
                .format(function))

        if 1 not in function.nargs:
            raise ValueError(
                '{} should be able to accept 1 arguments.'.format(function))

        if not isinstance(function, Lambda):
            d = Dummy('d')
            function = Lambda(d, function(d))

        obj = MatrixExpr.__new__(cls, function, expr)
        return obj
Ejemplo n.º 2
0
 def __new__(cls, vector):
     obj = MatrixExpr.__new__(cls, vector)
     shape = vector.shape
     dim = shape[1] if shape[0] == 1 else shape[0]
     obj._shape = (dim, dim)
     obj._vector = vector
     return obj
Ejemplo n.º 3
0
    def __new__(cls, function, expr):
        expr = _sympify(expr)
        if not expr.is_Matrix:
            raise ValueError("{} must be a matrix instance.".format(expr))

        if expr.shape == (1, 1):
            # Check if the function returns a matrix, in that case, just apply
            # the function instead of creating an ElementwiseApplyFunc object:
            ret = function(expr)
            if isinstance(ret, MatrixExpr):
                return ret

        if not isinstance(function, (FunctionClass, Lambda)):
            d = Dummy('d')
            function = Lambda(d, function(d))

        function = sympify(function)
        if not isinstance(function, (FunctionClass, Lambda)):
            raise ValueError(
                "{} should be compatible with SymPy function classes.".format(
                    function))

        if 1 not in function.nargs:
            raise ValueError(
                '{} should be able to accept 1 arguments.'.format(function))

        if not isinstance(function, Lambda):
            d = Dummy('d')
            function = Lambda(d, function(d))

        obj = MatrixExpr.__new__(cls, function, expr)
        return obj
Ejemplo n.º 4
0
 def __new__(cls, function, expr):
     obj = MatrixExpr.__new__(cls, expr)
     if not isinstance(function, FunctionClass):
         d = Dummy("d")
         function = Lambda(d, function(d))
     obj._function = function
     obj._expr = expr
     return obj
Ejemplo n.º 5
0
 def __new__(cls, function, expr):
     obj = MatrixExpr.__new__(cls, expr)
     if not isinstance(function, FunctionClass):
         d = Dummy("d")
         function = Lambda(d, function(d))
     obj._function = function
     obj._expr = expr
     return obj
Ejemplo n.º 6
0
 def __new__(cls, vector):
     obj = MatrixExpr.__new__(cls, vector)
     shape = vector.shape
     dim = shape[1] if shape[0] == 1 else shape[0]
     if vector.shape[0] != 1:
         obj._iscolumn = True
     else:
         obj._iscolumn = False
     obj._shape = (dim, dim)
     obj._vector = vector
     return obj
Ejemplo n.º 7
0
 def __new__(cls, vector):
     vector = _sympify(vector)
     obj = MatrixExpr.__new__(cls, vector)
     shape = vector.shape
     dim = shape[1] if shape[0] == 1 else shape[0]
     if vector.shape[0] != 1:
         obj._iscolumn = True
     else:
         obj._iscolumn = False
     obj._shape = (dim, dim)
     obj._vector = vector
     return obj
Ejemplo n.º 8
0
 def __new__(cls, function, expr):
     obj = MatrixExpr.__new__(cls, function, expr)
     obj._function = function
     obj._expr = expr
     return obj
 def __new__(cls, function, expr):
     obj = MatrixExpr.__new__(cls, function, expr)
     obj._function = function
     obj._expr = expr
     return obj