/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ==============================================================================*/ #ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_STRIDED_SLICE_LOGIC_H_ #define TENSORFLOW_LITE_KERNELS_INTERNAL_STRIDED_SLICE_LOGIC_H_ #include <limits> #include <vector> #include "tensorflow/lite/kernels/internal/compatibility.h" #include "tensorflow/lite/kernels/internal/types.h" namespace tflite { namespace strided_slice { // Use until std::clamp() is available from C++17. inline int Clamp(const int v, const int lo, const int hi) { … } inline void StridedSlicePadIndices(tflite::StridedSliceParams* p, int dim_count) { … } // Return the index for the first element along that axis. This index will be a // positive integer between [0, axis_size] (or [-1, axis_size -1] if stride < 0) // that can be used to index directly into the data. inline int StridedSliceStartForAxis(const tflite::StridedSliceParams& params, const RuntimeShape& input_shape, int32_t axis) { … } inline int StridedSliceEndForAxis(const tflite::StridedSliceParams& params, const RuntimeShape& input_shape, int axis, int start) { … } // Return the index for the first element along that axis. This index will be a // positive integer between [0, axis_size] (or [-1, axis_size -1] if stride < 0) // that can be used to index directly into the data. inline int StartForAxis(const tflite::StridedSliceParams& params, const RuntimeShape& input_shape, int axis) { … } // Return the "real" index for the end of iteration along that axis. This is an // "end" in the traditional C sense, in that it points to one past the last // element. ie. So if you were iterating through all elements of a 1D array of // size 4, this function would return 4 as the stop, because it is one past the // "real" indices of 0, 1, 2 & 3. inline int StopForAxis(const tflite::StridedSliceParams& params, const RuntimeShape& input_shape, int axis, int start_for_axis) { … } inline bool LoopCondition(int index, int stop, int stride) { … } inline tflite::StridedSliceParams BuildStridedSliceParams( int begin_mask, int end_mask, int shrink_axis_mask, const std::vector<int>& start_indices, const std::vector<int>& stop_indices, const std::vector<int>& strides) { … } } // namespace strided_slice } // namespace tflite #endif // TENSORFLOW_LITE_KERNELS_INTERNAL_STRIDED_SLICE_LOGIC_H_