Skip to content

Commit

Permalink
Efficient Tensor conversion from list of numpy arrays (#1071)
Browse files Browse the repository at this point in the history
  • Loading branch information
josalhor committed Nov 13, 2023
1 parent f8ed453 commit a446005
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion pomegranate/_utils.py
Expand Up @@ -56,7 +56,10 @@ def _cast_as_tensor(value, dtype=None):
return value
else:
return value.type(dtype)


if isinstance(value, list) and all(isinstance(v, numpy.ndarray) for v in value):
value = numpy.array(value)

if isinstance(value, (float, int, list, tuple, numpy.ndarray)):
if dtype is None:
return torch.tensor(value)
Expand Down

0 comments on commit a446005

Please sign in to comment.