ax-le / nn-fac

Toolbox (python) for computing some Nonnegative Factorization by solving Nonnegative Least Squares problems.
BSD 3-Clause "New" or "Revised" License
5 stars 0 forks source link

The NTD function has an error in NumPy 2.1.0. #1

Open gkazunii opened 2 months ago

gkazunii commented 2 months ago

Hi! Following comments in 'ntd.py', I tried to run NTD as follows:

from nn_fac.ntd import ntd tensor = np.random.rand(80,100,120) ranks = [10,20,15] core, factors = ntd(tensor, ranks = ranks, init = "tucker", verbose = True )

Unfortunately, I encountered the following error:

ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (3,) + inhomogeneous part.

My python version was 3.12.3, the NumPy version was 2.1.0, the Tensorly version was 0.6.0.

I downgraded the Python version to 3.10.4, installed NumPy 1.23.5, and installed nn-fac again. Then, finally, the above code worked.

It would be appreciated if you could mention the appropriate Python/NumPy version in the readme file or remove this bug.

Thank you.

ax-le commented 2 months ago

Hi gkazunii! Thanks for opening this issue. It seems indeed that the current version of nn-fac does not work with numpy version 2+ (at least for the NTD, but I suspect that it will be true for the other algorithms). It should be fixed at some point, I will notify modifications related to this issue in this thread. For now, sorry for the inconvenience, but I suggest that you (and other people who might encounter this problem) use numpy version 1.23.5 and Python 3.10.4. I will mention this in the README and setup.py files. Thanks for noticing the bug! Have a nice day, ax-le

ax-le commented 2 months ago

Added on the README and the setup! On a note, it seems to me that the problem comes from the creation of an array from nested sub-arrays, which is forbidden in numpy without specifying it starting from version 1.24 (Numpy release note: "Ragged array creation will now always raise a ValueError unless dtype=object is passed. This includes very deeply nested sequences."