AntoinePrv commented on code in PR #50929:
URL: https://github.com/apache/arrow/pull/50929#discussion_r3893076947
##########
cpp/src/arrow/tensor.cc:
##########
@@ -45,34 +45,36 @@ using internal::checked_cast;
namespace internal {
-Status ComputeRowMajorStrides(const FixedWidthType& type,
- const std::vector<int64_t>& shape,
- std::vector<int64_t>* strides) {
- const int byte_width = type.byte_width();
- const size_t ndim = shape.size();
-
- int64_t remaining = 0;
- if (!shape.empty() && shape.front() > 0) {
- remaining = byte_width;
- for (size_t i = 1; i < ndim; ++i) {
- if (internal::MultiplyWithOverflow(remaining, shape[i], &remaining)) {
- return Status::Invalid(
- "Row-major strides computed from shape would not fit in 64-bit
integer");
- }
- }
+Status ComputeRowMajorStrides(std::span<const int64_t> shape, int64_t
elem_size,
+ std::span<int64_t> strides) {
+ if (strides.size() != shape.size()) {
+ return Status::Invalid("strides must have the same length as shape");
}
- if (remaining == 0) {
- strides->assign(shape.size(), byte_width);
+ // An empty dimension makes the whole tensor empty, so any stride is as good.
Review Comment:
Outdated now.
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]