determine_backend(value, dispatch_type, *, domain, only=True, coerce=False)
This is useful for functions that call multimethods without any dispatchable arguments. You can use determine_backend
to ensure the same backend is used everywhere in a block of multimethod calls.
Support is determined by the __ua_convert__
protocol. Backends not supporting the type must return NotImplemented
from their __ua_convert__
if they don't support input of that type.
The value being tested
The dispatch type associated with value
, aka " marking <MarkingGlossary>
".
The domain to query for backends and set.
Whether or not to allow coercion to the backend's types. Implies only
.
Whether or not this should be the last backend to try.
Set the backend to the first active backend that supports value
set_backend
For when you know which backend to set
Suppose we have two backends BackendA
and BackendB
each supporting different types, TypeA
and TypeB
. Neither supporting the other type:
>>> with ua.set_backend(ex.BackendA):
... ex.call_multimethod(ex.TypeB(), ex.TypeB()) Traceback (most recent call last): ... uarray.BackendNotImplementedError: ...
Now consider a multimethod that creates a new object of TypeA
, or TypeB
depending on the active backend.
>>> with ua.set_backend(ex.BackendA), ua.set_backend(ex.BackendB):
... res = ex.creation_multimethod()
... ex.call_multimethod(res, ex.TypeA()) Traceback (most recent call last): ... uarray.BackendNotImplementedError: ...
res
is an object of TypeB
because BackendB
is set in the innermost with statement. So, call_multimethod
fails since the types don't match.
Instead, we need to first find a backend suitable for all of our objects.
This example is valid syntax, but raise an exception at execution>>> with ua.set_backend(ex.BackendA), ua.set_backend(ex.BackendB):See :
... x = ex.TypeA()
... with ua.determine_backend(x, "mark", domain="ua_examples"):
... res = ex.creation_multimethod()
... ex.call_multimethod(res, x) TypeA
The following pages refer to to this document either explicitly or contain code examples using this.
scipy._lib._uarray._backend.determine_backend
scipy._lib._uarray._backend.determine_backend_multi
Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.
Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)
SVG is more flexible but power hungry; and does not scale well to 50 + nodes.
All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them