Skip to content

Commit

Permalink
Fix partial_svd randomness when seed is not set
Browse files Browse the repository at this point in the history
  • Loading branch information
merajhashemi committed Dec 22, 2020
1 parent 65d5035 commit 0eb0942
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
5 changes: 3 additions & 2 deletions tensorly/backend/core.py
Expand Up @@ -761,8 +761,9 @@ def partial_svd(self, matrix, n_eigenvecs=None, random_state=None, **kwargs):
# We can perform a partial SVD
# construct np.random.RandomState for sampling a starting vector
if random_state is None:
# if random_state is not specified, do not initialize a starting vector
v0 = None
# if random_state is not specified, initilize with [-1, 1] using global numpy RNG
rns = np.random.mtrand._rand
v0 = rns.uniform(-1, 1, min_dim)
elif isinstance(random_state, int):
rns = np.random.RandomState(random_state)
# initilize with [-1, 1] as in ARPACK
Expand Down
5 changes: 3 additions & 2 deletions tensorly/contrib/sparse/backend/numpy_backend.py
Expand Up @@ -123,8 +123,9 @@ def partial_svd(matrix, n_eigenvecs=None, random_state=None, **kwargs):
# We can perform a partial SVD
# construct np.random.RandomState for sampling a starting vector
if random_state is None:
# if random_state is not specified, do not initialize a starting vector
v0 = None
# if random_state is not specified, initilize with [-1, 1] using global numpy RNG
rns = np.random.mtrand._rand
v0 = rns.uniform(-1, 1, min_dim)
elif isinstance(random_state, int):
rns = np.random.RandomState(random_state)
# initilize with [-1, 1] as in ARPACK
Expand Down

0 comments on commit 0eb0942

Please sign in to comment.