quadax.TensorProductRule

class quadax.TensorProductRule(rules: NestedRule | Sequence[NestedRule], ndim: int | None = None, norm: Callable | float | int = inf, batch_size: int | None = None)Source

Integrate a function over a box using a tensor product of 1D nested rules.

The nodes are every combination of one axis’ nodes with the others, and the weights the corresponding products, so an axis is integrated exactly as the one dimensional rule given for it would integrate it. Error is estimated from the embedded low order rule of every axis at once.

Parameters:
  • rules (NestedRule or sequence of NestedRule) – The one dimensional rule to apply along each axis. A single rule is used for every axis, and then ndim says how many there are. A sequence gives each axis its own rule, and ndim is taken from its length.

  • ndim (int, optional) – Dimension of the box to integrate over. Required when rules is a single rule, and must not be given when it is a sequence.

  • norm (int, callable) – Norm to use for measuring error for vector valued integrands. No effect if the integrand is scalar valued. If an int, uses p-norm of the given order, otherwise should be callable.

  • batch_size (int, optional) – Number of points to evaluate the integrand at simultaneously. The default evaluates all the rule’s nodes at once.

Notes

The cost is the product of the axes’ node counts, so it grows exponentially in ndim: a 15 point Gauss-Kronrod rule costs 225 evaluations in two dimensions, 3375 in three, and 50625 in four. A Genz-Malik rule of the highest degree costs 69, 245 and 705, and of the default degree 33, 77 and 153. Tensor products earn their cost where the integrand is smooth enough for a high order rule to pay off along each axis, or where the axes differ enough to be worth giving different rules, and are a poor choice in high dimensions.

Examples

The same rule on every axis, or one per axis:

TensorProductRule(GaussKronrodRule(21), ndim=3)
TensorProductRule([GaussKronrodRule(21), ClenshawCurtisRule(32)])

Methods

integrate(fun, a, b, args)

Integrate a function over a box using a nested cubature rule.

norm(x)

Norm to use for measuring error for vector valued integrands.

Attributes

ndim

Dimension of the domain this rule integrates over.

nodes_per_call

How many evaluations of the integrand one application of the rule costs.