Open3D (C++ API)  0.18.0
ReduceSubarraysSum.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - Open3D: www.open3d.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2023 www.open3d.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #pragma once
9 
10 #include <tbb/parallel_for.h>
11 
12 namespace open3d {
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 open3d
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)
Definition: ReduceSubarraysSum.h:29
Definition: PinholeCameraIntrinsic.cpp:16