Skip to content

Commit 22e3bd4

Browse files
pytorchbotlucylq
andauthored
Expect at least one value in the tensor, to extract scalar from (#15783)
Summary: local scalar dense extracts a scalar from a tensor. Check that the tensor has at least one value Differential Revision: D86363818 Co-authored-by: lucylq <[email protected]>
1 parent ab9ed7c commit 22e3bd4

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

kernels/prim_ops/register_prim_ops.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,12 @@ static Kernel prim_ops[] = {
124124
EValue& out = *stack[1];
125125
executorch::aten::Tensor self_tensor =
126126
self.to<executorch::aten::Tensor>();
127+
ET_KERNEL_CHECK_MSG(
128+
context,
129+
self_tensor.numel() >= 1,
130+
InvalidArgument,
131+
/* void */,
132+
"Expected tensor with at least 1 element");
127133
ET_SWITCH_REAL_TYPES_AND(
128134
Bool,
129135
self_tensor.scalar_type(),

0 commit comments

Comments
 (0)