Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyttb/cp_als.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ def cp_als( # noqa: PLR0912,PLR0913,PLR0915
else:
flag = 1

if (divmod(iteration, printitn)[1] == 0) or (printitn > 0 and flag == 0):
if (printitn > 0) and ((divmod(iteration, printitn)[1] == 0) or (flag == 0)):
print(f" Iter {iteration}: f = {fit:e} f-delta = {fitchange:7.1e}")

# Check for convergence
Expand Down
20 changes: 20 additions & 0 deletions tests/test_cp_als.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,3 +206,23 @@ def test_cp_als_sptensor_zeros(capsys):
capsys.readouterr()
assert pytest.approx(output3["fit"], 1) == 0
assert output3["normresidual"] == 0


def test_cp_als_tensor_printitn(capsys, sample_tensor):
_, T = sample_tensor

# default printitn
ttb.cp_als(T, 2, printitn=1, maxiters=2)
capsys.readouterr()

# zero printitn
ttb.cp_als(T, 2, printitn=0, maxiters=2)
capsys.readouterr()

# negative printitn
ttb.cp_als(T, 2, printitn=-1, maxiters=2)
capsys.readouterr()

# float printitn
ttb.cp_als(T, 2, printitn=1.5, maxiters=2)
capsys.readouterr()