fix: NumPy 2.4+ compatibility in feature selection fitting paths#11
Open
KenyaOtsuka wants to merge 1 commit into
Open
fix: NumPy 2.4+ compatibility in feature selection fitting paths#11KenyaOtsuka wants to merge 1 commit into
KenyaOtsuka wants to merge 1 commit into
Conversation
Previously, the right-hand side passed to `np.linalg.solve()` was reshaped to a column vector in the feature-selection paths of `__sub_fit` and `__sub_fit_save_select_feat`. The resulting solution `Wb` was a 2D column vector, so `Wb[i]` returned a length-1 array rather than a scalar. Assigning that length-1 array to a scalar element of `W` or `b` was deprecated in NumPy 1.25 and raises a `TypeError` in NumPy 2.4+. Changes: - `__sub_fit` (both threadpool and fallback branches): pass 1D RHS to `np.linalg.solve()`; replace the per-feature loop with a vectorized assignment `W[..., I[:-1]] = Wb[:-1]`. - `__sub_fit_save_select_feat`: same pattern; also replaces the `range(n_feat)` loop with `W[..., I] = Wb[:-1]`, which is safe for both feature-selection and use-all-features paths. - Replace `dtype=np.bool` (removed in NumPy 1.24) with `dtype=np.bool_`. The no-feature-selection multi-target solve path is left unchanged. Co-authored-by: Claude <claude@anthropic.com>
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 NumPy 2.4+ compatibility issues in the feature-selection fitting paths of
src/fastl2lir/fastl2lir.py.Background
In the feature-selection paths of
__sub_fitand__sub_fit_save_select_feat, the right-hand side passed tonp.linalg.solve()was reshaped to a column vector using.reshape(-1, 1).As a result, the solution
Wbalso became a 2D column vector. Expressions such asWb[i]therefore returned a length-1 array rather than a scalar. Assigning such a length-1 array to a scalar element ofWorbwas deprecated in NumPy 1.25 and raises aTypeErrorin NumPy 2.4+.Changes
In
__sub_fit, update both feature-selection branches to pass a 1D RHS tonp.linalg.solve().Replace the per-feature assignment loop with a vectorized assignment:
In
__sub_fit_save_select_feat, apply the same 1D-RHS pattern and replace the assignment loop with:Replace
dtype=np.boolwithdtype=np.bool_for compatibility with NumPy versions wherenp.boolwas removed.The no-feature-selection multi-target solve path in
__sub_fitis left unchanged, since that path intentionally solves a multi-target system.Tests
I ran the following tests and confirmed that all tests pass, including with NumPy deprecation warnings treated as errors: