Skip to content

Fix DictionaryLearner OMP crash when n_nonzero_coefs > n_components - #33695

Closed
Bahtya wants to merge 1 commit into
scikit-learn:mainfrom
Bahtya:fix/dict-learning-omp-n-nonzero-coefs
Closed

Bahtya wants to merge 1 commit into
scikit-learn:mainfrom
Bahtya:fix/dict-learning-omp-n-nonzero-coefs

Conversation

@Bahtya

@Bahtya Bahtya commented Apr 6, 2026

Copy link
Copy Markdown

Summary

Fixes #33454

When transform_algorithm='omp' and n_nonzero_coefs exceeds n_components, the value passes through uncapped, causing a ValueError deep in the OMP solver.

The default branch (when n_nonzero_coefs is None) already caps to n_components at line 415, but explicitly set values were not validated.

Fix

Cap regularization to n_components when explicitly set.

# Before:
regularization = n_nonzero_coefs
if regularization is None:
    regularization = min(max(n_features / 10, 1), n_components)

# After:
regularization = n_nonzero_coefs
if regularization is None:
    regularization = min(max(n_features / 10, 1), n_components)
else:
    regularization = min(regularization, n_components)

When transform_algorithm='omp' and n_nonzero_coefs exceeds n_components,
the value passes through uncapped, causing ValueError deep in the OMP
solver. The default branch already caps to n_components, but explicit
values were not validated.

Fix: cap regularization to n_components when it's explicitly set.

Fixes #33454

@virchan virchan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the PR, @Bahtya, and for helping improve scikit-learn.

I'm closing this PR per the Issues tagged "Needs Triage” section in the Contributing guide.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DictionaryLearner dies with 'omp' only

2 participants