File tree Expand file tree Collapse file tree 1 file changed +5
-6
lines changed
Expand file tree Collapse file tree 1 file changed +5
-6
lines changed Original file line number Diff line number Diff line change @@ -158,20 +158,19 @@ TensorView make_tensor_view(
158158 .append (" )" )
159159 .c_str ());
160160
161- bool isEmpty = true ;
161+ // A tensor can have zero elements even if some dimensions are non-zero
162+ // (e.g. shape (10, 0)). Emptiness must be based on numel().
163+ bool isEmpty = (val.numel () == 0 );
162164 for (int i = 0 ; i < val.dim (); ++i)
163165 {
166+ res.sizes [i] = val.size (i);
164167 res.strides [i] = val.stride (i) * elementSize;
165- if (res.strides [i] == 0 )
168+ if (!isEmpty && res.strides [i] == 0 )
166169 throw std::runtime_error (
167170 std::string (name)
168171 .append (" : tensors with broadcasted dimensions are not supported (use "
169172 " tensor.contiguous() to make tensor whole)" )
170173 .c_str ());
171-
172- res.sizes [i] = val.size (i);
173- if (res.sizes [i] > 0 )
174- isEmpty = false ;
175174 }
176175
177176 if (!res.data && !isEmpty)
You can’t perform that action at this time.
0 commit comments