ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
ReduceSubarraysSum.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #pragma once
9 
10 #include <tbb/parallel_for.h>
11 
12 namespace cloudViewer {
13 namespace ml {
14 namespace impl {
15 
28 template <class T>
29 void ReduceSubarraysSumCPU(const T* const values,
30  const size_t values_size,
31  const int64_t* const row_splits,
32  const size_t num_arrays,
33  T* out_sums) {
34  tbb::parallel_for(tbb::blocked_range<size_t>(0, num_arrays),
35  [&](const tbb::blocked_range<size_t>& r) {
36  for (size_t i = r.begin(); i != r.end(); ++i) {
37  size_t begin_idx = row_splits[i];
38  size_t end_idx = row_splits[i + 1];
39 
40  T sum = T(0);
41  for (size_t j = begin_idx; j < end_idx; ++j) {
42  sum += values[j];
43  }
44  out_sums[i] = sum;
45  }
46  });
47 }
48 
49 } // namespace impl
50 } // namespace ml
51 } // namespace cloudViewer
void ReduceSubarraysSumCPU(const T *const values, const size_t values_size, const int64_t *const row_splits, const size_t num_arrays, T *out_sums)
Generic file read and write utility for python interface.