Skip to content
This repository was archived by the owner on Apr 28, 2023. It is now read-only.

Commit 3e6e532

Browse files
author
Sven Verdoolaege
committed
SetStridesFromSizes: handle 0D tensors
In particular, do not write into a negative array entry.
1 parent 5e21c1a commit 3e6e532

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

include/tc/core/utils/dlpack-inl.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ inline void SetStrides(DLTensor& t, const std::vector<int64_t>& strides) {
109109

110110
inline void SetStridesFromSizes(DLTensor& t, const std::vector<int64_t>&) {
111111
auto ndim = t.ndim;
112+
if (ndim == 0) {
113+
return;
114+
}
112115
t.strides[ndim - 1] = 1;
113116
for (int i = ndim - 2; i >= 0; --i) {
114117
t.strides[i] = t.strides[i + 1] * t.shape[i + 1];

0 commit comments

Comments
 (0)