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
12 changes: 6 additions & 6 deletions pyttb/cp_apr.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ def tt_cp_apr_mu( # noqa: PLR0912,PLR0913,PLR0915
M.factor_matrices[n] *= Phi[n]

# Print status
if printinneritn != 0 and divmod(i, printinneritn)[1] == 0:
if (printinneritn > 0) and (divmod(i, printinneritn)[1] == 0):
print(
"\t\tMode = {n}, Inner Iter = {i}, "
f"KKT violation = {kktModeViolations[n]}"
Expand All @@ -323,7 +323,7 @@ def tt_cp_apr_mu( # noqa: PLR0912,PLR0913,PLR0915
M.normalize(normtype=1, mode=n)

kktViolations[iteration] = np.max(kktModeViolations)
if divmod(iteration, printitn)[1] == 0:
if (printitn > 0) and (divmod(iteration, printitn)[1] == 0):
print(
f"\tIter {iteration}: Inner Its = {nInnerIters[iteration]} "
f"KKT violation = {kktViolations[iteration]}, "
Expand Down Expand Up @@ -588,7 +588,7 @@ def tt_cp_apr_pdnr( # noqa: PLR0912,PLR0913,PLR0915
if i == 0 and kkt_violation > kktModeViolations[n]:
kktModeViolations[n] = kkt_violation

if printinneritn > 0 and np.mod(i, printinneritn) == 0:
if (printinneritn > 0) and (divmod(i, printinneritn) == 0):
print(
f"\tMode = {n}, Row = {jj}, InnerIt = {i}",
end="",
Expand Down Expand Up @@ -675,7 +675,7 @@ def tt_cp_apr_pdnr( # noqa: PLR0912,PLR0913,PLR0915
rowsubprobStopTol = np.maximum(stoptol, kktViolations[iteration]) / 100.0

# Print outer iteration status.
if printitn > 0 and np.mod(iteration, printitn) == 0:
if (printitn > 0) and (divmod(iteration, printitn)[1] == 0):
fnVals[iteration] = -tt_loglikelihood(input_tensor, M)
print(
f"{iteration}. Ttl Inner Its: {nInnerIters[iteration]}, "
Expand Down Expand Up @@ -966,7 +966,7 @@ def tt_cp_apr_pqnr( # noqa: PLR0912,PLR0913,PLR0915
if i == 0 and kkt_violation > kktModeViolations[n]:
kktModeViolations[n] = kkt_violation

if printinneritn > 0 and np.mod(i, printinneritn) == 0:
if (printinneritn > 0) and (divmod(i, printinneritn) == 0):
print(
f"\tMode = {n}, Row = {jj}, InnerIt = {i}",
end="",
Expand Down Expand Up @@ -1073,7 +1073,7 @@ def tt_cp_apr_pqnr( # noqa: PLR0912,PLR0913,PLR0915
kktViolations[iteration] = np.max(kktModeViolations)

# Print outer iteration status.
if printitn > 0 and np.mod(iteration, printitn) == 0:
if (printitn > 0) and (divmod(iteration, printitn)[1] == 0):
fnVals[iteration] = -tt_loglikelihood(input_tensor, M)
print(
f"{iteration}. Ttl Inner Its: {nInnerIters[iteration]}, KKT viol = "
Expand Down
2 changes: 1 addition & 1 deletion pyttb/tucker_als.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def tucker_als( # noqa: PLR0912, PLR0913, PLR0915
fit = 1 - (normresidual / normX) # fraction explained by model
fitchange = abs(fitold - fit)

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

# Check for convergence
Expand Down
Loading