-
Notifications
You must be signed in to change notification settings - Fork 299
Open
Description
Describe the bug
tl.decomposition.parafac() will change the shape of a cp tensor passed into the init parameter, potentially making its shape invalid. This happens when the tensor argument and init argument has different shapes along a dimension d, and said dimension is skipped in fixed_modes.
Steps or Code to Reproduce
import tensorly as tl
import numpy as np
X1 = np.random.randn(2, 3, 4, 5)
X2 = np.random.randn(2, 3, 4, 7)
decomp_ex = tl.decomposition.parafac(
X1, rank=3, random_state=7777
)
print([x.shape for x in decomp_ex[1]]) # correct shape [(2, 3), (3, 3), (4, 3), (5, 3)]
decomp_ex_2 = tl.decomposition.parafac(
X2,
rank=3,
init=tl.cp_tensor.CPTensor((decomp_ex[0], decomp_ex[1].copy())),
random_state=7777,
fixed_modes=[0, 1, 2],
)
print([x.shape for x in decomp_ex[1]]) # still correct shape
decomp_ex_3 = tl.decomposition.parafac(
X2,
rank=3,
init=decomp_ex,
random_state=7777,
fixed_modes=[0, 1, 2],
)
print([x.shape for x in decomp_ex[1]]) # altered shape [(2, 3), (3, 3), (4, 3), (7, 3)]
Expected behavior
tl.decomposition.parafac() should never change the value or shape of the init argument.
Actual result
The shape of the original tensor passed into init is changed to that of the decomposed tensor when init is used.
Versions
Linux-6.13.0-1-default-x86_64-with-glibc2.40
Python 3.12.3 | packaged by conda-forge | (main, Apr 15 2024, 18:38:13) [GCC 12.3.0]
NumPy 1.26.4
SciPy 1.15.1
TensorLy 0.9.0
Metadata
Metadata
Assignees
Labels
No labels