-
Notifications
You must be signed in to change notification settings - Fork 112
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
Deprecate redundant utilities for extracting constants #1046
Open
ricardoV94
wants to merge
6
commits into
pymc-devs:main
Choose a base branch
from
ricardoV94:fix_rewrite_bug
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains 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
ricardoV94
changed the title
Remove repeated utilities for extracting constants
Deprecate redundant utilities for extracting constants
Oct 21, 2024
ricardoV94
force-pushed
the
fix_rewrite_bug
branch
7 times, most recently
from
November 29, 2024 11:04
24716ac
to
8dcbc2b
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1046 +/- ##
==========================================
- Coverage 82.12% 82.07% -0.05%
==========================================
Files 183 183
Lines 48111 48108 -3
Branches 8667 8665 -2
==========================================
- Hits 39510 39485 -25
- Misses 6435 6452 +17
- Partials 2166 2171 +5
|
ricardoV94
force-pushed
the
fix_rewrite_bug
branch
from
December 3, 2024 10:50
8dcbc2b
to
6c20b96
Compare
@Armavica I removed the negative constant rewrite in the last commit |
ricardoV94
force-pushed
the
fix_rewrite_bug
branch
from
December 9, 2024 11:43
6c20b96
to
7961d57
Compare
Fixes bug in `local_add_neg_to_sub` reported in pymc-devs#584
ricardoV94
force-pushed
the
fix_rewrite_bug
branch
from
December 9, 2024 11:45
7961d57
to
8134f62
Compare
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.
Description
In PyTensor we have tho following similar utilities
pytensor.get_underlying_scalar_constant
pytensor.tensor.basic.get_underlying_scalar_constant_value
pytensor.tensor.basic.get_scalar_constant_value
pytensor.tensor.basic.extract_constant
pytensor.tensor.rewriting.math.get_constant
This PR removes and deprecates all except:
pytensor.tensor.basic.get_underlying_scalar_constant_value
pytensor.tensor.basic.get_scalar_constant_value
The reason for this distinction, is that the core utility,
get_underlying_scalar_constant_value
actually works for non-scalar inputs, if it can find a single scalar value underlies a potential n-dimensional tensor (say as in pt.zeros(5, 3, 2)). This is powerful, but can lead to subtle bugs when the caller forgets about it. This was the source of the bug behind #584 and was also likely present in other graphs such asgt(x, [0, 0, 0, 0])
and alike where the repeated condition broadcasts the output of the operation.The utility
get_scalar_constant_value
raises if the input is not a scalar (ndim=0) type.I don't love the
underlying
distinguishing the two. Perhapsunique
would be better.Both utilities now accept a
raise_not_constant
which when False (not-default) return the variable as is. I think I would prefer for it to returnNone
but this requires less code changes.Related Issue
local_add_neg_to_sub
rewrite gives wrong results with negative constants #584