This repository has been archived by the owner on Dec 18, 2023. It is now read-only.
Refactoring and minor bug fixing in requirements fixer #1760
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.
Summary:
The requirements-fixing code is not easy to understand, and some small errors and inefficiencies have crept in. I'm going to fix them in this diff to make it then easier to add a broadcasting fixer in an upcoming diff.
In this diff:
elementwise multiplication now correctly creates the requirement that the input types be identical with the output type. (As noted, in an upcoming diff we'll take care of the situation where inputs of dissimilar shape can be fixed by broadcasting.)
Fixed a typo with a misspelling of "requirements"
Methods
_meet_real_matrix_requirement_type
, and_meet_real_matrix_requirement
were misordered and redundant to other logic in the operator requirements fixer. By more carefully ordering the cases in the operator requirements fixer, we can simply delete these redundant methods.As noted,
_meet_operator_requirement
was too long and confusing. I've broken it up into many smaller cases each with its own logic for applying a simple fix.Making these changes had the beneficial side effect of fixing a very small bug in a test case. In test_fix_vectorized_models_8 we have a multiplication of a matrix of probabilities and a constant matrix with all positive real values. The previous code converted both operands to a real matrix, but we can legally convert them to positive real matrix, a more specific type. We now do so.
Reviewed By: AishwaryaSivaraman
Differential Revision: D40459965