Open3D (C++ API)
ReduceSubarraysSumCPU.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - Open3D: www.open3d.org -
3 // ----------------------------------------------------------------------------
4 // The MIT License (MIT)
5 //
6 // Copyright (c) 2019 www.open3d.org
7 //
8 // Permission is hereby granted, free of charge, to any person obtaining a copy
9 // of this software and associated documentation files (the "Software"), to deal
10 // in the Software without restriction, including without limitation the rights
11 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 // copies of the Software, and to permit persons to whom the Software is
13 // furnished to do so, subject to the following conditions:
14 //
15 // The above copyright notice and this permission notice shall be included in
16 // all copies or substantial portions of the Software.
17 //
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24 // IN THE SOFTWARE.
25 // ----------------------------------------------------------------------------
26 
27 #pragma once
28 
29 #include "tbb/parallel_for.h"
30 
31 namespace open3d {
32 namespace ml {
33 namespace detail {
34 
45 template <class T>
46 void ReduceSubarraysSumCPU(const T* const values,
47  const size_t values_size,
48  const int64_t* const prefix_sum,
49  const size_t prefix_sum_size,
50  T* out_sums) {
51  tbb::parallel_for(tbb::blocked_range<size_t>(0, prefix_sum_size),
52  [&](const tbb::blocked_range<size_t>& r) {
53  for (size_t i = r.begin(); i != r.end(); ++i) {
54  size_t begin_idx = prefix_sum[i];
55  // use values_size as end_idx for the last
56  // subarray
57  size_t end_idx = (i + 1 < prefix_sum_size
58  ? prefix_sum[i + 1]
59  : values_size);
60 
61  T sum = T(0);
62  for (size_t j = begin_idx; j < end_idx; ++j) {
63  sum += values[j];
64  }
65  out_sums[i] = sum;
66  }
67  });
68 }
69 
70 } // namespace detail
71 } // namespace ml
72 } // namespace open3d
void ReduceSubarraysSumCPU(const T *const values, const size_t values_size, const int64_t *const prefix_sum, const size_t prefix_sum_size, T *out_sums)
Definition: ReduceSubarraysSumCPU.h:46
Definition: Open3DViewer.h:29