-
Notifications
You must be signed in to change notification settings - Fork 6
Open
Labels
bugSomething isn't workingSomething isn't working
Description
Bug
import numpy as np
from rehline import plq_Ridge_Regressor
np.random.seed(42)
n = 2000
x = np.random.randn(n)
noise = np.random.randn(n) * (0.3 + 0.5 * np.abs(x))
y = 2 * x + noise
X = x.reshape(-1, 1)
clf = plq_Ridge_Regressor(
loss={'name': 'check_eps', 'qt': 0.9, 'epsilon': 0.1},
C=10.0 / n
)
clf.fit(X=X, y=y)- ✅ python script.py — works fine
- ❌ IPython — crashes
Cause
IPython auto-displays the return value of clf.fit(...) (which is self). This triggers sklearn's __repr__ / _repr_mimebundle_, which introspects all estimator attributes.
The problem is in plqERM_Ridge.fit() (_class.py):
self.opt_result_ = result # raw pybind11 C++ object stored as attribute
self.coef_ = result.beta # numpy view into C++ Eigen memory, no .copy()
self._Lambda = result.Lambda # same
self._Gamma = result.Gamma # same
self._xi = result.xi # sameresult is a pybind11-wrapped rehline_result C++ struct. When IPython's repr machinery touches this object (which has no __repr__ defined), it can crash. Additionally, self.coef_ etc. are not copies — they are numpy views into Eigen memory owned by the C++ object, creating dangling-reference risks.
Suggested fix
In _class.py, plqERM_Ridge.fit() (and similar in ReHLine.fit(), CQR_Ridge.fit(), plqERM_ElasticNet.fit()):
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)
# Remove: self.opt_result_ = resultWorkaround
clf.fit(X=X, y=y); # semicolon suppresses IPython display
Environment
- Python 3.13, macOS
- rehline 0.1.2.dev
- IPython (terminal)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working