in jat/processing_jat.py [0:0]
def to_tensor(x):
"""
Convert a nested structure of numpy arrays or tensors (including lists and tuples of them)
into a tensor. Assumes that all nested structures can be converted into a tensor directly.
:param x: Nested structure containing numpy arrays, tensors, lists, or tuples
:return: torch.Tensor
"""
with warnings.catch_warnings():
# Convert specific warning to an error
warnings.filterwarnings(
"error",
category=UserWarning,
message=".*Creating a tensor from a list of numpy.ndarrays is extremely slow.*",
)
try:
return torch.Tensor(x)
except Exception:
if isinstance(x, list):
return torch.stack([to_tensor(item) for item in x])
else:
raise TypeError("Unsupported type for conversion to tensor")