Skip to content

Commit

Permalink
Speeding up tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JeanKossaifi committed Aug 22, 2017
1 parent 83f5101 commit 24ba475
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
5 changes: 4 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@ python:
install:
- pip install -r requirements.txt
- pip install coveralls
env:
matrix:
- BACKEND=numpy
- BACKEND=mxnet
# command to run tests
script:
- travis_wait make BACKEND=numpy test-coverage
- travis_wait make BACKEND=mxnet test-coverage
after_success:
- coveralls
16 changes: 8 additions & 8 deletions tensorly/decomposition/tests/test_candecomp_parafac.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@
from ...random import check_random_state
from ... import backend as T


def test_parafac():
"""Test for the CANDECOMP-PARAFAC decomposition
"""
rng = check_random_state(1234)
tol_norm_2 = 10e-2
tol_max_abs = 10e-2
tensor = T.tensor(rng.random_sample((3, 4, 2)))
factors_svd = parafac(tensor, rank=4, n_iter_max=200, init='svd')
factors_random = parafac(tensor, rank=4, n_iter_max=200, init='random', random_state=1234, verbose=1)
factors_svd = parafac(tensor, rank=4, n_iter_max=200, init='svd', tol=10e-5)
factors_random = parafac(tensor, rank=4, n_iter_max=200, init='random', tol=10e-5, random_state=1234, verbose=0)
rec_svd = kruskal_to_tensor(factors_svd)
rec_random = kruskal_to_tensor(factors_random)
error = T.norm(rec_svd - tensor, 2)
Expand Down Expand Up @@ -44,9 +43,9 @@ def test_non_negative_parafac():
tol_norm_2 = 10e-1
tol_max_abs = 1
rng = check_random_state(1234)
tensor = T.tensor(rng.random_sample((3, 3, 3))*2)
tensor = T.tensor(rng.random_sample((3, 3, 3))+1)
factors = parafac(tensor, rank=3, n_iter_max=120)
nn_factors = non_negative_parafac(tensor, rank=3, n_iter_max=500, init='svd', verbose=1)
nn_factors = non_negative_parafac(tensor, rank=3, n_iter_max=100, tol=10e-4, init='svd', verbose=0)

# Make sure all components are positive
for factor in nn_factors:
Expand All @@ -63,10 +62,10 @@ def test_non_negative_parafac():
T.assert_(T.max(T.abs(reconstructed_tensor - nn_reconstructed_tensor)) < tol_max_abs,
'abs norm of reconstruction error higher than tol')

factors_svd = non_negative_parafac(tensor, rank=3, n_iter_max=100,
factors_svd = non_negative_parafac(tensor, rank=3, n_iter_max=100, tol=10e-4,
init='svd')
factors_random = non_negative_parafac(tensor, rank=3, n_iter_max=100,
init='random', random_state=1234, verbose=1)
factors_random = non_negative_parafac(tensor, rank=3, n_iter_max=100, tol=10e-4,
init='random', random_state=1234, verbose=0)
rec_svd = kruskal_to_tensor(factors_svd)
rec_random = kruskal_to_tensor(factors_random)
error = T.norm(rec_svd - rec_random, 2)
Expand All @@ -75,3 +74,4 @@ def test_non_negative_parafac():
'norm 2 of difference between svd and random init too high')
T.assert_(T.max(T.abs(rec_svd - rec_random)) < tol_max_abs,
'abs norm of difference between svd and random init too high')

0 comments on commit 24ba475

Please sign in to comment.