示例#1
0
    def eval_binary_expr(self, expr, op_func, *args, **kwargs):
        """
        A helper method for evaluating double-operand `pymbolic
        .primitives.Expression` instances.

        Takes the two children attributes of the given binary
        `pymbolic.primitives.Expression` instance and passes them
        to the given op_func and returns the result.

        :param expr: the double-operand `pymbolic.primitives.
        Expression` instance

        :param op_func: at least a double-argument function
        corresponding to the operation associated with `expr`

        :return: an evaluated, non-pymbolic object as a result
        of applying `op_func` to the two operands of `expr` together
        if the any of the operands can not be simplified further
        otherwise a pymbolic object of type `type(expr)` with
        the simplified operands
        """

        expr_type = type(expr)
        op1, op2 = expr.__getinitargs__()
        result = op_func(op1, op2, *args, **kwargs)

        return result if not equals(result, expr) \
            else expr_type(self.rec(op1, *args, **kwargs), self.rec(op2, *args, **kwargs))
示例#2
0
    def eval_unary_expr(self, expr, op_func, *args, **kwargs):
        """
        A helper method for evaluating single-operand `pymbolic
        .primitives.Expression` instances.

        Takes the only child attribute of the given unary `pymbolic
        .primitives.Expression` instance and passes it to the
        given op_func and returns the result.

        :param expr: the single-operand `pymbolic.primitives.
        Expression` instance

        :param op_func: at least a single-argument function
        corresponding to the operation associated with `expr`

        :return: an evaluated, non-pymbolic object as a result
        of applying `op_func` to the operand of `expr` if the
        operand can not be simplified further otherwise a
        pymbolic object of type `type(expr)` with a simplified
        operand
        """

        expr_type = type(expr)
        op, = expr.__getinitargs__()
        result = op_func(op, *args, **kwargs)

        return result if not equals(result, expr) \
            else expr_type(self.rec(op, *args, *kwargs))
示例#3
0
    def all_gaussian_steps(self, expr, h=0, k=0, *args, **kwargs):
        """
        Yields the steps in the gaussian elimination of `expr` if possible starting
        from `expr` all the way to the reduced row echelon form of `expr`.
        """

        while True:
            yield expr, h, k
            curr = self.next_gaussian_step(expr, h, k, *args, **kwargs)
            if equals(curr, (expr, h, k)):
                break
            expr, h, k = curr
示例#4
0
    def _eval_row_op(self, expr, op_func, *args, **kwargs):
        expr_type = type(expr)
        ops = expr.__getinitargs__()[:-1]
        og_mat = expr.__getinitargs__()[-1]
        eval_mat = self.rec(og_mat)

        if not isinstance(eval_mat, np.ndarray) or not equals(
                og_mat, eval_mat):
            return expr_type(*ops, eval_mat, *args, **kwargs)

        op_func(*ops, eval_mat)
        return eval_mat
示例#5
0
    def all_steps(self, expr, *args, **kwargs):
        """
        Yields the steps in the simplification of `expr` starting from
        `expr` all the way to the most simplified step.
        """

        while True:
            yield expr
            curr = self.next_step(expr, *args, **kwargs)
            if equals(curr, expr):
                break
            expr = curr
示例#6
0
 def __eq__(self, other):
     return type(other) == type(self) and equals(self.__getinitargs__(),
                                                 other.__getinitargs__())