Skip to content

Commit

Permalink
Efficient Tensor conversion from list of numpy arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
josalhor committed Nov 12, 2023
1 parent f8ed453 commit 392b034
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion pomegranate/_utils.py
Original file line number Diff line number Diff line change
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 392b034

Please sign in to comment.