forked from scipy/scipy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
REF: stats: refactor unuran wrapper to address memory leaks
The previous wrapper had memory leaks due to non-local returns. This PR eliminates the problem by using the `MessageStream` API (originally used in Qhull to handle errors occurring in `qhull` C API). UNU.RAN uses a global `FILE *` stream which makes it thread-unsafe to use those streams without first acquiring a lock. To expound on the problem, we have to call `unur_set_stream` under a lock otherwise some other thread could change the global `FILE *` variable and all the errors will be redirected to that wrong file. Moreover, as non-local jumps are not allowed, `PyErr_Occurred` is used to catch errors inside callbacks once the UNU.RAN function has been executed.
- Loading branch information
1 parent
8ce9e75
commit 01015cd
Showing
6 changed files
with
555 additions
and
567 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
from .unuran_wrapper import ( | ||
TransformedDensityRejection, | ||
DiscreteAliasUrn | ||
DiscreteAliasUrn, | ||
UNURANError | ||
) |
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
Oops, something went wrong.