tensorflow/lite/kernels/strided_slice.cc
TfLiteStatus ResizeOutputTensor(TfLiteContext* context,
                                StridedSliceContext* op_context) {
  std::vector<int> output_shape_vector;
  StridedSliceParams op_params = BuildStridedSliceParams(op_context);
  RuntimeShape input_shape = GetTensorShape(op_context->input);

  for (int idx = op_context->dims - 1; idx >= 0; --idx) {
    int32_t stride = GetTensorData<int32_t>(op_context->strides)[idx];
    TF_LITE_ENSURE_MSG(context, stride != 0, "stride value has to be non-zero");

    int32_t begin =
        ::tflite::strided_slice::StartForAxis(op_params, input_shape, idx);
    int32_t end = ::tflite::strided_slice::StopForAxis(op_params, input_shape,
                                                       idx, begin);

    // When shrinking an axis, the end position does not matter (and can be
    // incorrect when negative indexing is used, see Issue #19260). Always use
    // begin + 1 to generate a length 1 slice, since begin has
    // already been adjusted for negative indices by GetBeginValueAtIndex.
    const bool shrink_axis = op_context->params->shrink_axis_mask & (1 << idx);
    if (shrink_axis) {
      end = begin + 1;
    }

    // This is valid for both positive and negative strides
    int32_t dim_shape = std::ceil((end - begin) / static_cast<float>(stride));
    dim_shape = dim_shape < 0 ? 0 : dim_shape;
    if (!shrink_axis) {
      output_shape_vector.push_back(dim_shape);
    }
  }

  TfLiteIntArray* output_shape =
      TfLiteIntArrayCreate(output_shape_vector.size());

  std::reverse_copy(output_shape_vector.begin(), output_shape_vector.end(),
                    output_shape->data);

  TF_LITE_ENSURE_STATUS(
      context->ResizeTensor(context, op_context->output, output_shape));

  return kTfLiteOk;
}
// Processes the indexing tensors (begin, end and strides) to resize the
// output tensor. This function is callable from both Prepare() and Eval() as
// long as the caller ensures the indexing tensors are present.
Processes the indexing tensors (begin, end and strides) to resize the
output tensor. This function is callable from both Prepare() and Eval() as
long as the caller ensures the indexing tensors are present.
Processes the indexing tensors ( begin end and strides ) to resize the output tensor . This function is callable from both Prepare () and Eval () as long as the caller ensures the indexing tensors are present .
TfLiteStatus ResizeOutputTensor(TfLiteContext* context,
                                StridedSliceContext* op_context) {
  std::vector<int> output_shape_vector;
  StridedSliceParams op_params = BuildStridedSliceParams(op_context);
  RuntimeShape input_shape = GetTensorShape(op_context->input);
  for (int idx = op_context->dims - 1; idx >= 0; --idx) {
    int32_t stride = GetTensorData<int32_t>(op_context->strides)[idx];
    TF_LITE_ENSURE_MSG(context, stride != 0, "stride value has to be non-zero");
    int32_t begin =
        ::tflite::strided_slice::StartForAxis(op_params, input_shape, idx);
    int32_t end = ::tflite::strided_slice::StopForAxis(op_params, input_shape,
                                                       idx, begin);
    const bool shrink_axis = op_context->params->shrink_axis_mask & (1 << idx);
    if (shrink_axis) {
      end = begin + 1;
    }
    int32_t dim_shape = std::ceil((end - begin) / static_cast<float>(stride));
    dim_shape = dim_shape < 0 ? 0 : dim_shape;
    if (!shrink_axis) {
      output_shape_vector.push_back(dim_shape);
    }
  }
  TfLiteIntArray* output_shape =
      TfLiteIntArrayCreate(output_shape_vector.size());
  std::reverse_copy(output_shape_vector.begin(), output_shape_vector.end(),
                    output_shape->data);
  TF_LITE_ENSURE_STATUS(
      context->ResizeTensor(context, op_context->output, output_shape));
  return kTfLiteOk;
}
TfLiteStatus ResizeOutputTensor ( TfLiteContext * context , StridedSliceContext * op_context ) { std :: vector < int > output_shape_vector ; StridedSliceParams op_params = BuildStridedSliceParams ( op_context ) ; RuntimeShape input_shape = GetTensorShape ( op_context -> input ) ; for ( int idx = op_context -> dims - 1 ; idx >= 0 ; -- idx ) { int32_t stride = GetTensorData < int32_t > ( op_context -> strides ) [ idx ] ; TF_LITE_ENSURE_MSG ( context , stride != 0 , " " ) ; int32_t begin = :: tflite :: strided_slice :: StartForAxis ( op_params , input_shape , idx ) ; int32_t end = :: tflite :: strided_slice :: StopForAxis ( op_params , input_shape , idx , begin ) ; const bool shrink_axis = op_context -> params -> shrink_axis_mask & ( 1 << idx ) ; if ( shrink_axis ) { end = begin + 1 ; } int32_t dim_shape = std :: ceil ( ( end - begin ) / static_cast < float > ( stride ) ) ; dim_shape = dim_shape < 0 ? 0 : dim_shape ; if ( ! shrink_axis ) { output_shape_vector . push_back ( dim_shape ) ; } } TfLiteIntArray * output_shape = TfLiteIntArrayCreate ( output_shape_vector . size ( ) ) ; std :: reverse_copy ( output_shape_vector . begin ( ) , output_shape_vector . end ( ) , output_shape -> data ) ; TF_LITE_ENSURE_STATUS ( context -> ResizeTensor ( context , op_context -> output , output_shape ) ) ; return kTfLiteOk ; }
Processes the indexing tensors (begin, end and strides) to resize the
output tensor.
Processes the indexing tensors ( begin end and strides ) to resize the output tensor .
// When shrinking an axis, the end position does not matter (and can be // incorrect when negative indexing is used, see Issue #19260). Always use // begin + 1 to generate a length 1 slice, since begin has // already been adjusted for negative indices by GetBeginValueAtIndex. // This is valid for both positive and negative strides