-
Notifications
You must be signed in to change notification settings - Fork 0
feat(core, distributions): switch to generics #96
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
base: refactor/rework-arch
Are you sure you want to change the base?
Conversation
rework_tests/unit/distributions/test_continuous_distribution.py
Outdated
Show resolved
Hide resolved
rework_tests/unit/distributions/test_continuous_distribution.py
Outdated
Show resolved
Hide resolved
rework_tests/unit/distributions/test_continuous_distribution.py
Outdated
Show resolved
Hide resolved
rework_tests/unit/distributions/test_continuous_distribution.py
Outdated
Show resolved
Hide resolved
iraedeus
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are many uses of np.isclose or np.assert_allclose with arbitrary atol values for all dtypes. I suggest trying atol=np.finfo(dtype).eps
| def test_init_does_not_recreate_components_with_correct_dtype(self, dtype): | ||
| """Tests that components with the correct dtype are not recreated.""" | ||
|
|
||
| comp_f32 = Exponential(loc=0.0, rate=1.0, dtype=dtype) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Invalid variable name, here the component has arbitrary precision
| comp_f32 = Exponential(loc=0.0, rate=1.0, dtype=dtype) | |
| comp = Exponential(loc=0.0, rate=1.0, dtype=dtype) |
| X = np.asarray(X, dtype=float64) | ||
| X = np.asarray(X, dtype=self.dtype) | ||
| component_pdfs = np.array([comp.pdf(X) for comp in self.components]) | ||
| return np.asarray(np.dot(self.weights, component_pdfs)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| """ | ||
|
|
||
| X = np.atleast_1d(X) | ||
| X = np.atleast_1d(X).astype(self.dtype) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| X = np.atleast_1d(X).astype(self.dtype) | |
| X = np.asarray(X, dtype=self.dtype) |
|
|
||
| dtype = mixture_model.dtype | ||
|
|
||
| expected_lpdf = np.log(mixture_model.pdf(X)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| expected_lpdf = np.log(mixture_model.pdf(X)) | |
| expected_lpdf = np.log(w1 * c1.pdf(X) + w2 * c2.pdf(X)) |
| assert isinstance(samples, np.ndarray) | ||
| assert samples.dtype == dtype | ||
|
|
||
| def test_generate_with_size_zero(self, mixture_model): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Forgot to check here dtype of the output
488aa59 to
fa9cbae
Compare
fa9cbae to
cd36859
Compare

This pull request refactors the core and distributions modules to use generic numeric types.
Implementation:
typing.Genericwith aTypeVar("DType").