mrkn commented on a change in pull request #9395:
URL: https://github.com/apache/arrow/pull/9395#discussion_r571991331
##########
File path: cpp/src/arrow/tensor.cc
##########
@@ -127,14 +162,31 @@ Status CheckTensorStridesValidity(const
std::shared_ptr<Buffer>& data,
return Status::OK();
}
- std::vector<int64_t> last_index(shape);
- const int64_t n = static_cast<int64_t>(shape.size());
- for (int64_t i = 0; i < n; ++i) {
- --last_index[i];
+ // Check the largest offset can be computed without overflow
+ const size_t ndim = shape.size();
+ int64_t largest_offset = 0;
+ for (size_t i = 0; i < ndim; ++i) {
+ if (shape[i] == 0) continue;
+
+ int64_t dim_offset;
+ if (!internal::MultiplyWithOverflow(shape[i] - 1, strides[i],
&dim_offset)) {
+ if (dim_offset <= 0) {
+ // Ignore the negative dim_offset here because we are interested in
only the
+ // largest offset
Review comment:
Hmm, I guess we need to have a new property of the offset that indicates
the head item location from the data pointer because the negative offset leads
the access to the memory before the data pointer. Or, simply reject the
negative strides.
I'll investigate how numpy handles the negative strides, then I propose how
we should do.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]