Conversation
The `etuple` function returns an instance of the `ExpressionTuple` class. If we wish to return an instance of a subclass of `ExpressionTuple` we need to implement a new function. This allows one to dispatch the `etuple` function to keep a uniform API.
The first argument passed to `etuple` determines which of the registered functions is called. The first argument is generally an `ExpressionTuple`, the etuplized version of the operator. However, when using subclasses of `ExpressionTuple` to customize evaluation, we want `etuple` to depend on the current operator and not its etuplized version.
brandonwillard
approved these changes
Sep 6, 2022
6 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
As a result of #19 / #20 we can customize the way expression tuples are evaluated by subclassing
ExpressionTuple. We would also like to get an instance of these subclasses when etuplizing the corresponding evaluated operators. To do so and keep a consistent API in this PR we allow the functionetupleto dispatch, and choose which registered version to use withinetuplize.Since this work was motivated by aesara-devs/aesara#1036, here is an example of how this works in practice:
We cannot avoid dispatching
etupleif we want to be able to unifyetuple(at.normal.random, ...)with the result ofetuplize(at.normal.random(x, y)). We could avoid (the imho awkward)etuplize_fnby allowing to dispatchetuplize_stepinstead (why dispatchetuplizeby the way?).