Skip to content

Commit 18b39e3

Browse files
Clarify TypeError message (#5997)
* Clarify TypeError message * typo * Wrap tye() in repr() so that the type-check stfu * Even better message incidentally speeds up the thing, since all() possibly checked all elements and we don't. Co-authored-by: Vasilis Vryniotis <[email protected]>
1 parent 03bb324 commit 18b39e3

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

torchvision/utils.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,13 @@ def make_grid(
5656
"""
5757
if not torch.jit.is_scripting() and not torch.jit.is_tracing():
5858
_log_api_usage_once(make_grid)
59-
if not (torch.is_tensor(tensor) or (isinstance(tensor, list) and all(torch.is_tensor(t) for t in tensor))):
60-
raise TypeError(f"tensor or list of tensors expected, got {type(tensor)}")
59+
if not torch.is_tensor(tensor):
60+
if isinstance(tensor, list):
61+
for t in tensor:
62+
if not torch.is_tensor(t):
63+
raise TypeError(f"tensor or list of tensors expected, got a list containing {type(t)}")
64+
else:
65+
raise TypeError(f"tensor or list of tensors expected, got {type(tensor)}")
6166

6267
if "range" in kwargs.keys():
6368
warnings.warn(

0 commit comments

Comments
 (0)