sandialabs / pyttb

Python Tensor Toolbox
https://pyttb.readthedocs.io
BSD 2-Clause "Simplified" License
25 stars 13 forks source link

Silent failure of cp_als with NaNs #297

Closed ghbrown closed 5 months ago

ghbrown commented 5 months ago

If the input to cp_als() contains NaNs they silently propagate into nearly every output variable.

import numpy as np
import pyttb

T_np = np.random.rand(4,4,4)
T_np[0,0,0] = np.nan
T = pyttb.tensor(T_np)
K = pyttb.cp_als(T,2,maxiters=1,printitn=0)[0]
print(K)

I consider this a bug, partially because the output contains no useful information, unlike calling numpy.linalg.solve() on an input containing NaNs. For what it's worth, I personally don't like this behavior from numpy, but the output of solve() may contain very few NaNs depending on where they occur.

tgkolda commented 5 months ago

In many of the MATLAB routines, we don't check for errors like this because it decreases performance for very large tensors and thus other codes that don't include this check look like they are getting better performance. Just an FYI. I think it's okay if there's some onus on the user to check that their inputs are reasonable.