1 /* Copyright 2018 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_EXTRACT_VOLUME_PATCHES_OP_H_ 17 #define TENSORFLOW_KERNELS_EXTRACT_VOLUME_PATCHES_OP_H_ 18 19 #include "tensorflow/core/framework/tensor_shape.h" 20 #include "tensorflow/core/framework/tensor_types.h" 21 #include "tensorflow/core/kernels/eigen_volume_patch.h" 22 #include "third_party/eigen3/unsupported/Eigen/CXX11/Tensor" 23 24 namespace tensorflow { 25 namespace functor { 26 27 template <typename Device, typename T> 28 struct ExtractVolumePatchesForward { operatorExtractVolumePatchesForward29 void operator()(const Device& d, typename TTypes<T, 5>::ConstTensor input, 30 int patch_planes, int patch_rows, int patch_cols, 31 int stride_planes, int stride_rows, int stride_cols, 32 /* int rate_planes, int rate_rows, int rate_cols, */ 33 const Eigen::PaddingType& padding, 34 typename TTypes<T, 5>::Tensor output) { 35 const int64 N = std::max(input.size(), output.size()); 36 if (N <= std::numeric_limits<Index32>::max()) { 37 auto output_32bit = To32Bit(output); 38 output_32bit.device(d) = 39 To32Bit(input) 40 .extract_volume_patches(patch_cols, patch_rows, patch_planes, 41 stride_cols, stride_rows, stride_planes, 42 padding) 43 .reshape(output_32bit.dimensions()); 44 } else { 45 output.device(d) = 46 input 47 .extract_volume_patches(patch_cols, patch_rows, patch_planes, 48 stride_cols, stride_rows, stride_planes, 49 padding) 50 .reshape(output.dimensions()); 51 } 52 } 53 }; 54 55 } // namespace functor 56 } // namespace tensorflow 57 58 #endif // TENSORFLOW_KERNELS_EXTRACT_VOLUME_PATCHES_OP_H_ 59