Fix caching bug in signals.deterministic_signals.Deterministic #325
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.
This bug will cause the wrong delays to be returned when signals.deterministic_signals.Deterministic.get_delay() is called repeatedly with the same parameters (e.g., when computing finite-difference partial derivatives). It wouldn't be a problem when every set of parameters is new, as in MCMC sampling.
Reproducible symptom: when issuing the sequence
one finds that
yyret != xxret
(correct) butxxret2 = yyret
(wrong!).Cause: that
signals.deterministic_signals.Deterministic
computes the delay and stores it in an instance variable, then the caching mechanism (signal.cache_call
) saves a reference to the instance variable. So the second call (get_delay(yy)
) ends up modifying the cached value forxx
.Cure: The fix is for
get_delay
to return a new array whenever it's called (this won't prevent caching to function correctly).In general, any
Signal
that uses caching must return new numpy arrays if these are functions of the parameters. It's only OK to return references to instance variables for arrays that never change.