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


##########
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) ||
+      buffer_size_u >> 63) {

Review Comment:
   Addressed locally, I applied the change with adjusted line wrapping, since 
the suggested form fails the clang-format pre-commit check.



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