Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple implementations of functions with the same backend #452

Open
yngvem opened this issue Oct 30, 2022 · 1 comment
Open

Multiple implementations of functions with the same backend #452

yngvem opened this issue Oct 30, 2022 · 1 comment
Labels
API design Issue for discussing design decisions enhancement

Comments

@yngvem
Copy link
Contributor

yngvem commented Oct 30, 2022

Continuing of the discussion in #434 (comment). We may want to allow multiple implementations of the same function. For example, we may want to make it possible to use opt-einsum to cache contraction paths without this being the default behaviour.

Here is an example with a possible API (without any accompanying implementation).

@allow_alternative_implementations
def absolute_value(x):
    return abs(x)

@absolute_value.alternative_implementation(name="sqrt_based")
def _sqrt_based_abs(x):
    return sqrt(x*x)


absolute_value(x)  # use original implementation
absolute_value.use_alternative("sqrt_based")

absolute_value(x)  # use sqrt_based

absolute_value.use_alternative(None)
absolute_value(x)  # use original implementation again
@JeanKossaifi
Copy link
Member

Thanks @yngvem! I really like it!

Maybe we could call it @dynamically_dispatched and then have options to dispatch. We could even use a unified system to do backend dispatching, tensor algebra backend dispatching and this.

@JeanKossaifi JeanKossaifi added enhancement API design Issue for discussing design decisions labels Oct 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API design Issue for discussing design decisions enhancement
Projects
None yet
Development

No branches or pull requests

2 participants