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