You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using Numpy backend, it seems that Tensorly tensors have no attribute "device".
Steps or Code to Reproduce
importtensorlyastl# works OKtl.set_backend('pytorch')
A=tl.tensor((3,3),dtype=tl.float64,device="cpu")
print("torch|A:",A)
print("torch|A.dtype:",A.dtype)
print("torch|A.device:",A.device)
# raises an AttributeError: 'numpy.ndarray' object has no attribute 'device' # when printing A.devicetl.set_backend('numpy')
A=tl.tensor((3,3),dtype=tl.float64,device="cpu")
print("numpy|A:",A)
print("numpy|A.dtype:",A.dtype)
print("numpy|A.device:",A.device)
Expected behavior
It would be nice to have a "device" attribute set to "cpu" when Numpy is used as backend. The reason behind this is that sometimes we may want to create a new tensor, having e.g. similar 'device' and 'dtype' than another tensor. Even if a tensor with Numpy backend will obviously live on the cpu, this would prevent from having to add an if: else: block in the code.
Note also that A = tl.tensor((3,3),dtype=tl.float64,device="cuda") after tl.set_backend('numpy') raises no warning/error, perhaps it should?
Versions
Windows-10-10.0.19045-SP0
Python 3.11.4 | packaged by Anaconda, Inc. | (main, Jul 5 2023, 13:38:37) [MSC v.1916 64 bit (AMD64)]
NumPy 1.26.4
SciPy 1.10.1
TensorLy 0.8.1
PyTorch 2.2.0+cu121
The text was updated successfully, but these errors were encountered:
Yes, currently the context of a tensor depends on the backend. I did think about making it backend agnostic, I guess that is one option. We then need to normalize the device across all backends then.
Describe the bug
When using Numpy backend, it seems that Tensorly tensors have no attribute "device".
Steps or Code to Reproduce
Expected behavior
It would be nice to have a "device" attribute set to "cpu" when Numpy is used as backend. The reason behind this is that sometimes we may want to create a new tensor, having e.g. similar 'device' and 'dtype' than another tensor. Even if a tensor with Numpy backend will obviously live on the cpu, this would prevent from having to add an if: else: block in the code.
Note also that
A = tl.tensor((3,3),dtype=tl.float64,device="cuda")
aftertl.set_backend('numpy')
raises no warning/error, perhaps it should?Versions
Windows-10-10.0.19045-SP0
Python 3.11.4 | packaged by Anaconda, Inc. | (main, Jul 5 2023, 13:38:37) [MSC v.1916 64 bit (AMD64)]
NumPy 1.26.4
SciPy 1.10.1
TensorLy 0.8.1
PyTorch 2.2.0+cu121
The text was updated successfully, but these errors were encountered: