Skip to content

Fixes issue#39#41

Merged
statmlben merged 1 commit intosoftmin:mainfrom
Leona-LYT:main
Apr 2, 2026
Merged

Fixes issue#39#41
statmlben merged 1 commit intosoftmin:mainfrom
Leona-LYT:main

Conversation

@Leona-LYT
Copy link
Copy Markdown
Contributor

Description

Fix IPython crash caused by pybind11 C++ object exposure and unsafe NumPy views in plqERM_Ridge.fit().

When running in IPython, clf.fit(...) implicitly returns self, which triggers sklearn’s _repr_mimebundle_. This introspects estimator attributes and attempts to access self.opt_result_, a pybind11-wrapped C++ object (rehline_result) without a proper __repr__, causing crashes.

Additionally, attributes such as coef_, _Lambda, _Gamma, and _xi were NumPy views into Eigen memory owned by the C++ object, creating potential dangling reference issues.

Fix

  • Remove storage of raw C++ object (self.opt_result_)
  • Replace Eigen-backed NumPy views with .copy() to ensure safe ownership
  • Convert iterable outputs to Python-native types

Changes

  • self.coef_ = result.beta.copy()
  • self._Lambda = result.Lambda.copy()
  • self._Gamma = result.Gamma.copy()
  • self._xi = result.xi.copy()
  • self.n_iter_ = result.niter
  • self.dual_obj_ = list(result.dual_objfns)
  • self.primal_obj_ = list(result.primal_objfns)
  • Removed: self.opt_result_ = result

Impact

  • Prevents IPython/Jupyter crashes
  • Eliminates unsafe memory references
  • Aligns with sklearn estimator design expectations

Related Issue

Closes #39


Type of Change

  • Bug fix (non-breaking change that fixes an issue)

Checklist

  • I have tested my changes locally
  • Tests pass: pytest tests/ -v
  • Code follows the style guidelines (PEP 8)
  • Documentation has been updated (if applicable)
  • Commits are properly formatted

Additional Notes

Workaround prior to this fix:

clf.fit(X=X, y=y);  # suppress IPython auto-display

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 2, 2026

Welcome to Codecov 🎉

Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests.

ℹ️ You can also turn on project coverage checks and project coverage reporting on Pull Request comment

Thanks for integrating Codecov - We've got you covered ☂️

@statmlben statmlben merged commit bab4e1b into softmin:main Apr 2, 2026
13 checks passed
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.

[Bug] plqERM_Ridge.fit() crashes in IPython but works in plain Python

2 participants