determine_backend_multi¶
- uarray.determine_backend_multi(dispatchables, *, domain, only=True, coerce=False, **kwargs)[source]¶
Set a backend supporting all
dispatchablesThis is useful for functions that call multimethods without any dispatchable arguments. You can use
determine_backend_multi()to ensure the same backend is used everywhere in a block of multimethod calls involving multiple arrays.- Parameters
dispatchables (Sequence[Union[uarray.Dispatchable, Any]]) – The dispatchables that must be supported
domain (string) – The domain to query for backends and set.
coerce (bool) – Whether or not to allow coercion to the backend’s types. Implies
only.only (bool) – Whether or not this should be the last backend to try.
dispatch_type (Optional[Any]) – The default dispatch type associated with
dispatchables, aka “marking”.
See also
determine_backendFor a single dispatch value
set_backendFor when you know which backend to set
Notes
Support is determined by the
__ua_convert__protocol. Backends not supporting the type must returnNotImplementedfrom their__ua_convert__if they don’t support input of that type.Examples
determine_backend()allows the backend to be set from a single object.determine_backend_multi()allows multiple objects to be checked simultaneously for support in the backend. Suppose we have aBackendABwhich supportsTypeAandTypeBin the same call, and aBackendBCthat doesn’t supportTypeA.>>> with ua.set_backend(ex.BackendAB), ua.set_backend(ex.BackendBC): ... a, b = ex.TypeA(), ex.TypeB() ... with ua.determine_backend_multi( ... [ua.Dispatchable(a, "mark"), ua.Dispatchable(b, "mark")], ... domain="ua_examples" ... ): ... res = ex.creation_multimethod() ... ex.call_multimethod(res, a, b) TypeA
This won’t call
BackendBCbecause it doesn’t supportTypeA.We can also use leave out the
ua.Dispatchableif we specify the defaultdispatch_typefor thedispatchablesargument.>>> with ua.set_backend(ex.BackendAB), ua.set_backend(ex.BackendBC): ... a, b = ex.TypeA(), ex.TypeB() ... with ua.determine_backend_multi( ... [a, b], dispatch_type="mark", domain="ua_examples" ... ): ... res = ex.creation_multimethod() ... ex.call_multimethod(res, a, b) TypeA