Open3D (C++ API)  0.11.0
ReduceSubarraysSum.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 impl {
34 
47 template <class T>
48 void ReduceSubarraysSumCPU(const T* const values,
49  const size_t values_size,
50  const int64_t* const row_splits,
51  const size_t num_arrays,
52  T* out_sums) {
53  tbb::parallel_for(tbb::blocked_range<size_t>(0, num_arrays),
54  [&](const tbb::blocked_range<size_t>& r) {
55  for (size_t i = r.begin(); i != r.end(); ++i) {
56  size_t begin_idx = row_splits[i];
57  size_t end_idx = row_splits[i + 1];
58 
59  T sum = T(0);
60  for (size_t j = begin_idx; j < end_idx; ++j) {
61  sum += values[j];
62  }
63  out_sums[i] = sum;
64  }
65  });
66 }
67 
68 } // namespace impl
69 } // namespace ml
70 } // 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:48
Definition: PinholeCameraIntrinsic.cpp:35