Reranko05 commented on code in PR #48710:
URL: https://github.com/apache/arrow/pull/48710#discussion_r4578196623


##########
cpp/src/arrow/array/util.cc:
##########
@@ -17,6 +17,8 @@
 
 #include "arrow/array/util.h"
 
+#include <arrow/compute/kernels/base_arithmetic_internal.h>
+

Review Comment:
   Could we avoid including `arrow/compute/kernels/base_arithmetic_internal.h` 
here? `MultiplyWithOverflow` is already available through 
`arrow/util/int_util_overflow.h`, so we could call 
`internal::MultiplyWithOverflow` directly.



##########
cpp/src/arrow/array/util.cc:
##########
@@ -926,6 +929,53 @@ Result<std::shared_ptr<Array>> 
MakeEmptyArray(std::shared_ptr<DataType> type,
   return builder->Finish();
 }
 
+Result<std::shared_ptr<Array>> Arange(int64_t start, int64_t stop, int64_t 
step,
+                                      MemoryPool* pool) {
+  if (step == 0) {
+    return Status::Invalid("Arange step cannot be zero");
+  }
+
+  auto error = [&]() {
+    return Status::Invalid("Arange: range [", start, ", ", stop, ") with step 
", step,
+                           " would produce an array that is too large");
+  };
+
+  uint64_t size;
+  if (step > 0 && stop > start) {
+    const uint64_t range = static_cast<uint64_t>(stop) - 
static_cast<uint64_t>(start);
+    const auto step_u = static_cast<uint64_t>(step);
+    size = (range - 1) / step_u + 1;
+  } else if (step < 0 && stop < start) {
+    const uint64_t range = static_cast<uint64_t>(start) - 
static_cast<uint64_t>(stop);
+    const uint64_t step_u = 0 - static_cast<uint64_t>(step);
+    size = (range - 1) / step_u + 1;
+  } else {
+    return MakeEmptyArray(int64(), pool);
+  }
+
+  uint64_t buffer_size_u;
+  if (MultiplyWithOverflow(size, sizeof(int64_t), &buffer_size_u) ||

Review Comment:
   ```suggestion
     if (internal::MultiplyWithOverflow(size, sizeof(int64_t), &buffer_size_u) 
||
   ```



-- 
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]

Reply via email to