Home | History | Annotate | Download | only in kernels
      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_WHERE_OP_H_
     17 #define TENSORFLOW_KERNELS_WHERE_OP_H_
     18 
     19 #include "third_party/eigen3/unsupported/Eigen/CXX11/Tensor"
     20 #include "tensorflow/core/framework/op_kernel.h"
     21 #include "tensorflow/core/framework/tensor_types.h"
     22 #include "tensorflow/core/platform/macros.h"
     23 #include "tensorflow/core/platform/types.h"
     24 
     25 namespace tensorflow {
     26 
     27 #define TF_CALL_WHERE_GPU_TYPES(m) \
     28   TF_CALL_int8(m);                 \
     29   TF_CALL_uint8(m);                \
     30   TF_CALL_int32(m);                \
     31   TF_CALL_int64(m);                \
     32   TF_CALL_float(m);                \
     33   TF_CALL_double(m);               \
     34   TF_CALL_complex64(m);            \
     35   TF_CALL_complex128(m);           \
     36   TF_CALL_bool(m);
     37 
     38 namespace functor {
     39 
     40 template <typename Device, typename T, typename TIndex>
     41 struct NumTrue {
     42   EIGEN_ALWAYS_INLINE static Status Compute(
     43       OpKernelContext* ctx, const Device& d,
     44       typename TTypes<T>::ConstFlat input,
     45       typename TTypes<TIndex>::Scalar num_true);
     46 };
     47 
     48 template <typename Device, int NDIM, typename T, typename TIndex>
     49 struct Where {
     50   // Copies indices of true values in input into output.  The pointer
     51   // found_true should sit on the host.  Compute should copy the
     52   // number of true elements found into it.  At the end, if
     53   //   *found_true != output.dimension(0),
     54   // then the input may have changed between the initial counting of
     55   // the true values and the call to Where.
     56   EIGEN_ALWAYS_INLINE static Status Compute(
     57       OpKernelContext* ctx, const Device& d,
     58       typename TTypes<T, NDIM>::ConstTensor input,
     59       typename TTypes<int64>::Matrix output, TIndex* found_true);
     60 };
     61 
     62 }  // namespace functor
     63 
     64 }  // namespace tensorflow
     65 
     66 #endif  // TENSORFLOW_KERNELS_WHERE_OP_H_
     67