You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/03/03 20:12:30 UTC

[GitHub] [arrow] JabariBooker commented on a change in pull request #12460: ARROW-13530: [C++] Implement cumulative sum compute function

JabariBooker commented on a change in pull request #12460:
URL: https://github.com/apache/arrow/pull/12460#discussion_r819027668



##########
File path: cpp/src/arrow/compute/kernels/scalar_cumulative_sum.cc
##########
@@ -0,0 +1,147 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+#include "arrow/array/array_base.h"
+#include "arrow/compute/kernels/common.h"
+#include "arrow/result.h"
+#include "arrow/visit_type_inline.h"
+
+namespace arrow {
+namespace compute {
+namespace internal {
+namespace {
+
+template <typename CType>
+CType CumulativeSum(std::shared_ptr<Array>& input, ArrayData* output, CType start) {
+  CType sum = start;
+  CType* data = checked_cast<CType*>(input->data()->buffers[1]->data());
+  CType* out_values = checked_cast<CType*>(output->buffers[1]->mutable_data());
+  for (size_t i = input->offset; i < input->length; ++i) {
+    if (input->IsValid(i)) {
+      sum += data[i];
+      out_values[i] = sum;
+    }
+  }
+
+  return sum;
+}
+
+template <typename Type>
+struct CumulativeSumFunctor {
+  using CType = TypeTraits<Type>::CType;
+
+  Status Exec(KernelContext* ctx, const ExecBatch& batch, Datum* out) {
+    const NumericScalar& start_scalar =
+        checked_cast<const NumericScalar&>(*batch[1].scalar());
+    CType start = start_scalar.value;
+
+    switch (batch[0].kind()) {
+      case Datum::ARRAY:
+        std::shared_ptr<Array> input = batch[0].make_array();
+        ArrayData* output = out->array().get();
+
+        output->length = input->data()->length;
+        *output->type = std::move(input->type());
+        uint8_t* out_bitmap = output->buffers[0]->mutable_data();

Review comment:
       Should `mutable_address()` or `address()` be used instead as to access the buffer regardless of device? Is there an instance in which the output would be immutable?




-- 
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: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org