Preserve Gaussian subclasses in conversion factory - #5358
Open
FlorianPfaff wants to merge 2 commits into
Open
Conversation
FlorianPfaff
marked this pull request as ready for review
August 19, 2026 12:05
Contributor
✅MegaLinter analysis: Success
Notices
See detailed reports in MegaLinter artifacts Your project could benefit from a custom flavor, which would allow you to run only the linters you need, and thus improve runtime performances. (Skip this info by defining
|
This file contains hidden or 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
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.

Summary
Fix
GaussianDistribution.from_distribution(...)so the target-centricconvert_distribution(source, TargetSubclass)API actually returns the requested Gaussian subclass.Bug
The conversion gateway dispatches to
TargetSubclass.from_distribution(...).GaussianDistribution.from_distributionwas astaticmethodand explicitly constructedGaussianDistribution, so subclasses inheriting that factory silently lost their requested concrete type.The same problem affected the special
GaussianMixturebranch becauseto_gaussian()returns the base Gaussian representation.For example, converting a valid Gaussian source to a subclass of
GaussianDistributionreturned a plainGaussianDistributioneven though the requested target type was the subclass.Fix
GaussianDistribution.from_distributionto aclassmethodcls(...)GaussianMixture.to_gaussian()path exactlycls(...)only when a subclass was explicitly requestedcheck_validitybehaviorRegression coverage
Added focused tests covering both factory branches:
GaussianDistribution -> GaussianSubclassGaussianMixture -> GaussianSubclassBoth regressions verify the exact requested concrete type and preservation of the resulting mean/covariance.
Scope
mainatbaac3b1736bb8e81eafc1e3f69e10104636103b9Full repository/backend validation is delegated to GitHub Actions because this execution environment cannot clone/install the repository from GitHub.