• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright 2015 The TensorFlow Authors. All Rights Reserved.
2 
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
6 
7     http://www.apache.org/licenses/LICENSE-2.0
8 
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
14 ==============================================================================*/
15 
16 #ifndef TENSORFLOW_KERNELS_SCATTER_ND_OP_H_
17 #define TENSORFLOW_KERNELS_SCATTER_ND_OP_H_
18 
19 #include "third_party/eigen3/unsupported/Eigen/CXX11/Tensor"
20 
21 #include "tensorflow/core/framework/bounds_check.h"
22 #include "tensorflow/core/framework/op_kernel.h"
23 #include "tensorflow/core/framework/register_types.h"
24 #include "tensorflow/core/framework/tensor.h"
25 #include "tensorflow/core/framework/tensor_shape.h"
26 #include "tensorflow/core/kernels/fill_functor.h"
27 #include "tensorflow/core/kernels/scatter_nd_op.h"
28 #include "tensorflow/core/platform/mutex.h"
29 #include "tensorflow/core/platform/types.h"
30 #include "tensorflow/core/util/util.h"
31 
32 namespace tensorflow {
33 
34 typedef Eigen::ThreadPoolDevice CPUDevice;
35 
36 class OpKernelContext;
37 
38 namespace scatter_nd_op {
39 
40 enum class UpdateOp { ASSIGN, ADD, SUB, MIN, MAX };
41 
42 }  // namespace scatter_nd_op
43 
44 namespace functor {
45 
46 // Functor used by ScatterOp to do the computations.
47 template <typename Device, typename T, typename Index,
48           scatter_nd_op::UpdateOp op, int IXDIM>
49 struct ScatterNdFunctor {
50   // Returns -1 on success or a nonnegative i s.t. indices[i] is a bad index.
51   Index operator()(
52       const Device& d, const Index slice_size,
53       const Eigen::array<Eigen::DenseIndex, IXDIM> output_shape_prefix,
54       typename TTypes<T, 2>::Tensor Tparams,
55       typename TTypes<Index, 2>::ConstTensor Tindices,
56       typename TTypes<T, 2>::ConstTensor Tupdates,
57       typename TTypes<T, 2>::Tensor Toutput);
58 };
59 
60 // Scatter updates into indices in Tensor out.  The argument allocate
61 // controls whether 'out' should be created.  If allocate is true,
62 // *out will be updated to the scattered tensor upon successful completion.
63 // If allocate is false, out must point to a Tensor allocated with the
64 // right type (T) and shape.  This tensor will not be zeroed out
65 // before the scatter is executed.
66 template <typename Device, typename T, typename Index,
67           scatter_nd_op::UpdateOp Op>
68 Status DoScatterNd(OpKernelContext* c, const Tensor& indices,
69                    const Tensor& updates, const TensorShape& shape, Tensor* out,
70                    bool allocate);
71 
72 }  // namespace functor
73 }  // namespace tensorflow
74 
75 #endif  // TENSORFLOW_KERNELS_SCATTER_ND_OP_H_
76