generate_multimethod(argument_extractor: Callable[..., Tuple[ForwardRef('Dispatchable'), ...]], argument_replacer: Callable[[Tuple, Dict, Tuple], Tuple[Tuple, Dict]], domain: str, default: Optional[Callable] = None)
A callable which extracts the dispatchable arguments. Extracted arguments should be marked by the Dispatchable
class. It has the same signature as the desired multimethod.
A callable with the signature (args, kwargs, dispatchables), which should also return an (args, kwargs) pair with the dispatchables replaced inside the args/kwargs.
A string value indicating the domain of this multimethod.
The default implementation of this multimethod, where None
(the default) specifies there is no default implementation.
Generates a multimethod.
uarray
See the module documentation for how to override the method by creating backends.
In this example, a
is to be dispatched over, so we return it, while marking it as an int
. The trailing comma is needed because the args have to be returned as an iterable.
>>> def override_me(a, b):
... return Dispatchable(a, int),
Next, we define the argument replacer that replaces the dispatchables inside args/kwargs with the supplied ones.
>>> def override_replacer(args, kwargs, dispatchables):
... return (dispatchables[0], args[1]), {}
Next, we define the multimethod.
>>> overridden_me = generate_multimethod(
... override_me, override_replacer, "ua_examples"
... )
Notice that there's no default implementation, unless you supply one.
This example is valid syntax, but raise an exception at execution>>> overridden_me(1, "a") Traceback (most recent call last): ... uarray.BackendNotImplementedError: ...
>>> overridden_me2 = generate_multimethod(See :
... override_me, override_replacer, "ua_examples", default=lambda x, y: (x, y)
... )
... overridden_me2(1, "a") (1, 'a')
The following pages refer to to this document either explicitly or contain code examples using this.
scipy._lib._uarray._backend.generate_multimethod
scipy._lib._uarray._backend.create_multimethod
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