This is a pre-release version (latest).Go to latest (1.18.0)
{ } Raw JSON

bundles / scipy latest / scipy / integrate / _rules / _base / _cached_cast

function

scipy.integrate._rules._base:_cached_cast

source: build-install/usr/lib/python3.14/site-packages/scipy/integrate/_rules/_base.py:475

Signature

def _cached_cast(rule, attr, nodes, weights, dtype, device, xp)

Summary

Convert a rule's nodes/weights onto (xp, dtype, device), memoized.

Extended Summary

The built-in fixed rules keep their nodes and weights as NumPy host arrays: a rule object is constructed once, independently of any integrand, so at construction time there is no array whose namespace or device could be matched -- xp arrays built there would land on the backend's default device and get baked into the rule, forcing estimates with integrand arrays on another device to either raise or silently transfer (see gh-22680). Host data keeps construction backend- and device-neutral.

The target namespace, dtype and device only become known at apply time, from the actual integration limits; this helper performs the conversion there and memoizes the result on the rule (keyed on the full target triple), so the adaptive cubature loop does not re-cast -- or re-transfer, for non-default devices -- the constants for every subregion.

Aliases

  • scipy.integrate._rules._base._cached_cast