Open3D (C++ API)  0.15.1
ReduceSubarraysSumOpKernel.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - Open3D: www.open3d.org -
3 // ----------------------------------------------------------------------------
4 // The MIT License (MIT)
5 //
6 // Copyright (c) 2018-2021 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 "tensorflow/core/framework/op.h"
30 #include "tensorflow/core/framework/op_kernel.h"
31 #include "tensorflow/core/lib/core/errors.h"
32 
34 // namespace for code that is common for all kernels
35 namespace reduce_subarrays_sum_opkernel {
36 
37 // Base class with common code for the OpKernel implementations
38 class ReduceSubarraysSumOpKernel : public tensorflow::OpKernel {
39 public:
40  explicit ReduceSubarraysSumOpKernel(
41  tensorflow::OpKernelConstruction* construction)
42  : OpKernel(construction) {}
43 
44  void Compute(tensorflow::OpKernelContext* context) override {
45  using namespace tensorflow;
46  static_assert(sizeof(int64) == sizeof(int64_t),
47  "int64 type is not compatible");
48 
49  const Tensor& values = context->input(0);
50  OP_REQUIRES(context, values.shape().dims() == 1,
51  errors::InvalidArgument("values must be a rank 1 tensor"));
52 
53  const Tensor& row_splits = context->input(1);
54  OP_REQUIRES(
55  context, row_splits.shape().dims() == 1,
56  errors::InvalidArgument("row_splits must be a rank 1 tensor"));
57 
58  // special treatment for empty values vector
59  if (values.shape().dim_size(0) == 0) {
60  Tensor* sums_tensor = 0;
61  OP_REQUIRES_OK(context, context->allocate_output(0, values.shape(),
62  &sums_tensor));
63  return;
64  }
65 
66  Tensor* sums_tensor = 0;
67  TensorShape sums_shape({row_splits.shape().dim_size(0) - 1});
68  OP_REQUIRES_OK(context,
69  context->allocate_output(0, sums_shape, &sums_tensor));
70 
71  Kernel(context, values, row_splits, *sums_tensor);
72  }
73 
74  // Function with the device specific code
75  virtual void Kernel(tensorflow::OpKernelContext* context,
76  const tensorflow::Tensor& values,
77  const tensorflow::Tensor& row_splits,
78  tensorflow::Tensor& sums) = 0;
79 
80 private:
81 };
82 
83 } // namespace reduce_subarrays_sum_opkernel
ImGuiContext * context
Definition: Window.cpp:95