示例#1
0
    def diff(self, mi):
        """
        :arg mi: a multi-index (tuple) indicating how many x/y derivatives are
            to be taken.
        """
        try:
            expr = self.cache_by_mi[mi]
        except KeyError:
            from six import iteritems
            from sumpy.symbolic import Add

            closest_mi = self.get_closest_cached_mi(mi)
            expr = self.cache_by_mi[closest_mi]

            # Try to reduce the derivative using recurrences first, and if that
            # fails fall back to derivative taking.
            for next_deriv, next_mi in (self.get_derivative_taking_sequence(
                    closest_mi, mi)):

                recurrence = (self.wrangler.try_get_recurrence_for_derivative(
                    next_mi, self.cache_by_mi))

                if recurrence is not None:
                    expr = Add(*tuple(
                        coeff * self.cache_by_mi[ident]
                        for ident, coeff in iteritems(recurrence)))
                else:
                    expr = expr.diff(next_deriv)

                self.cache_by_mi[next_mi] = expr

        return expr
示例#2
0
文件: tools.py 项目: inducer/sumpy
    def diff(self, mi):
        """
        :arg mi: a multi-index (tuple) indicating how many x/y derivatives are
            to be taken.
        """
        try:
            expr = self.cache_by_mi[mi]
        except KeyError:
            from six import iteritems
            from sumpy.symbolic import Add

            closest_mi = self.get_closest_cached_mi(mi)
            expr = self.cache_by_mi[closest_mi]

            # Try to reduce the derivative using recurrences first, and if that
            # fails fall back to derivative taking.
            for next_deriv, next_mi in (
                        self.get_derivative_taking_sequence(closest_mi, mi)):

                recurrence = (
                        self.wrangler.try_get_recurrence_for_derivative(
                            next_mi, self.cache_by_mi))

                if recurrence is not None:
                    expr = Add(*tuple(
                            coeff * self.cache_by_mi[ident]
                            for ident, coeff in iteritems(recurrence)))
                else:
                    expr = expr.diff(next_deriv)

                self.cache_by_mi[next_mi] = expr

        return expr
示例#3
0
def test_cse_not_possible():
    # No substitution possible.
    e = Add(x, y)
    substs, reduced = cse([e])
    assert substs == []
    assert reduced == [x + y]
    # issue 6329
    eq = (meijerg((1, 2), (y, 4), (5,), [], x) +
          meijerg((1, 3), (y, 4), (5,), [], x))
    assert cse(eq) == ([], [eq])
示例#4
0
def test_nested_substitution():
    # Substitution within a substitution.
    e = Add(Pow(w*x + y, 2), sqrt(w*x + y))
    substs, reduced = cse([e])
    assert substs == [(x0, w*x + y)]
    assert reduced == [sqrt(x0) + x0**2]
示例#5
0
def test_cse_single():
    # Simple substitution.
    e = Add(Pow(x + y, 2), sqrt(x + y))
    substs, reduced = cse([e])
    assert substs == [(x0, x + y)]
    assert reduced == [sqrt(x0) + x0**2]