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

Refactor towards Gaussian._eager_subs_affine() #284

Merged
merged 3 commits into from
Oct 22, 2019
Merged

Conversation

fritzo
Copy link
Member

@fritzo fritzo commented Oct 21, 2019

Addresses #72

This is step 1/3 in implementing affine recognition for Gaussian funsors, and is a pure refactoring PR. This does not actually implement ._eager_affine_subs(), and I will implement that in step 2/3 and remove the old MultivariateNormal pattern in step 3/3. This PR:

  • exposes the old _affine_inputs() function as a public affine_inputs() function
  • adds momoziation to affine_inputs()
  • moves the affine_inputs pattern for Contraction to cnf.py to allow a new dependency chain
    cnf.py -> gaussian.py -> affine.py where affine is used inside gaussian
  • refactors extract_affine() so that it is always correct but produces an affine representation only wrt those inputs that are actually affine. This is both less dangerous and the behavior we will want in Gaussian._eager_affine()
  • refactors Gaussian.eager_subs() into multiple functions.

Tested

  • pure refactoring is covered by existing tests

funsor/gaussian.py Outdated Show resolved Hide resolved
@@ -269,6 +283,13 @@ def eager_contraction_gaussian(red_op, bin_op, reduced_vars, x, y):
return (x + y).reduce(red_op, reduced_vars)


@affine_inputs.register(Contraction)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved verbatim from affine.py

Copy link
Member

@eb8680 eb8680 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@eb8680 eb8680 merged commit 493096f into master Oct 22, 2019
@eb8680 eb8680 deleted the affine-gaussian branch October 22, 2019 08:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants