Skip to content

Preserve Gaussian subclasses in conversion factory - #5358

Open
FlorianPfaff wants to merge 2 commits into
mainfrom
agent/fix-gaussian-conversion-subclasses
Open

Preserve Gaussian subclasses in conversion factory#5358
FlorianPfaff wants to merge 2 commits into
mainfrom
agent/fix-gaussian-conversion-subclasses

Conversation

@FlorianPfaff

Copy link
Copy Markdown
Owner

Summary

Fix GaussianDistribution.from_distribution(...) so the target-centric convert_distribution(source, TargetSubclass) API actually returns the requested Gaussian subclass.

Bug

The conversion gateway dispatches to TargetSubclass.from_distribution(...). GaussianDistribution.from_distribution was a staticmethod and explicitly constructed GaussianDistribution, so subclasses inheriting that factory silently lost their requested concrete type.

The same problem affected the special GaussianMixture branch because to_gaussian() returns the base Gaussian representation.

For example, converting a valid Gaussian source to a subclass of GaussianDistribution returned a plain GaussianDistribution even though the requested target type was the subclass.

Fix

  • convert GaussianDistribution.from_distribution to a classmethod
  • construct ordinary conversions through cls(...)
  • preserve the existing base-class GaussianMixture.to_gaussian() path exactly
  • reconstruct mixture conversions through cls(...) only when a subclass was explicitly requested
  • retain the existing check_validity behavior

Regression coverage

Added focused tests covering both factory branches:

  1. GaussianDistribution -> GaussianSubclass
  2. GaussianMixture -> GaussianSubclass

Both regressions verify the exact requested concrete type and preservation of the resulting mean/covariance.

Scope

Full repository/backend validation is delegated to GitHub Actions because this execution environment cannot clone/install the repository from GitHub.

@FlorianPfaff
FlorianPfaff marked this pull request as ready for review August 19, 2026 12:05
@github-actions

Copy link
Copy Markdown
Contributor

MegaLinter analysis: Success

Descriptor Linter Files Fixed Errors Max errors Warnings Elapsed time
✅ COPYPASTE jscpd yes no no 6.83s
✅ JSON prettier 7 0 0 0 0.66s
✅ JSON v8r 7 0 0 5.23s
✅ MARKDOWN markdownlint 68 0 0 0 2.52s
✅ MARKDOWN markdown-table-formatter 68 0 0 0 0.62s
✅ PYTHON black 1989 15 0 0 66.03s
✅ PYTHON isort 1989 27 0 0 2.94s
✅ REPOSITORY betterleaks yes no no 1.35s
✅ REPOSITORY checkov yes no no 35.03s
✅ REPOSITORY git_diff yes no no 0.14s
✅ REPOSITORY secretlint yes no no 104.01s
✅ REPOSITORY syft yes no no 2.65s
✅ REPOSITORY trivy-sbom yes no no 2.87s
✅ YAML prettier 11 0 0 0 0.7s
✅ YAML v8r 11 0 0 17.06s
✅ YAML yamllint 11 0 0 0.82s

Notices

⚠️ Your configuration references items that have been removed from MegaLinter and are ignored: MAKEFILE_CHECKMAKE. See Removed linters to find their replacements.

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 FLAVOR_SUGGESTIONS: false)

  • Documentation: Custom Flavors
  • Command: npx mega-linter-runner@10.0.0 --custom-flavor-setup --custom-flavor-linters PYTHON_BLACK,PYTHON_ISORT,COPYPASTE_JSCPD,JSON_V8R,JSON_PRETTIER,MARKDOWN_MARKDOWNLINT,MARKDOWN_MARKDOWN_TABLE_FORMATTER,REPOSITORY_CHECKOV,REPOSITORY_GIT_DIFF,REPOSITORY_BETTERLEAKS,REPOSITORY_SECRETLINT,REPOSITORY_SYFT,REPOSITORY_TRIVY_SBOM,YAML_PRETTIER,YAML_YAMLLINT,YAML_V8R

MegaLinter is provided by OX Security
Show us your support by starring ⭐ the repository

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant