Skip to content

Commit d335640

Browse files
committed
Merge branch 'omp-zerofix'
2 parents a04d701 + 60118bf commit d335640

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

sklearn/linear_model/omp.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ def _cholesky_omp(X, y, n_nonzero_coefs, tol=None, copy_X=True):
6363

6464
alpha = np.dot(X.T, y)
6565
residual = y
66+
gamma = np.empty(0)
6667
n_active = 0
6768
indices = range(X.shape[1]) # keeping track of swapping
6869

@@ -157,6 +158,7 @@ def _gram_omp(Gram, Xy, n_nonzero_coefs, tol_0=None, tol=None,
157158
alpha = Xy
158159
tol_curr = tol_0
159160
delta = 0
161+
gamma = np.empty(0)
160162
n_active = 0
161163

162164
max_features = len(Gram) if tol is not None else n_nonzero_coefs

sklearn/linear_model/tests/test_omp.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,3 +154,12 @@ def test_swapped_regressors():
154154
gamma_hat_gram = orthogonal_mp_gram(G, new_Xy, 2)
155155
assert_equal(np.flatnonzero(gamma_hat), [0, 21])
156156
assert_equal(np.flatnonzero(gamma_hat_gram), [0, 21])
157+
158+
159+
def test_no_atoms():
160+
y_empty = np.zeros_like(y)
161+
Xy_empty = np.dot(X.T, y_empty)
162+
gamma_empty = orthogonal_mp(X, y_empty, 1)
163+
gamma_empty_gram = orthogonal_mp_gram(G, Xy_empty, 1)
164+
assert_equal(np.all(gamma_empty == 0), True)
165+
assert_equal(np.all(gamma_empty_gram == 0), True)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy