MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / Prepare

Function Prepare

tensorflow/lite/kernels/strided_slice.cc:142–176  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

140}
141
142TfLiteStatus Prepare(TfLiteContext* context, TfLiteNode* node) {
143 TF_LITE_ENSURE_EQ(context, NumInputs(node), 4);
144 TF_LITE_ENSURE_EQ(context, NumOutputs(node), 1);
145
146 StridedSliceContext op_context(context, node);
147
148 // Ensure validity of input tensor and its dimension
149 TF_LITE_ENSURE_EQ(context, NumDimensions(op_context.begin), 1);
150 TF_LITE_ENSURE_EQ(context, NumDimensions(op_context.end), 1);
151 TF_LITE_ENSURE_EQ(context, NumDimensions(op_context.strides), 1);
152 TF_LITE_ENSURE_EQ(context, op_context.input->type, op_context.output->type);
153 // Only INT32 begin/end/strides are supported
154 // TODO(soroosh) add support for INT64
155 TF_LITE_ENSURE_EQ(context, op_context.begin->type, kTfLiteInt32);
156 TF_LITE_ENSURE_EQ(context, op_context.end->type, kTfLiteInt32);
157 TF_LITE_ENSURE_EQ(context, op_context.strides->type, kTfLiteInt32);
158 TF_LITE_ENSURE_MSG(context, op_context.dims <= 4,
159 "StridedSlice op only supports 1D-4D input arrays.");
160
161 // TODO(soroosh): add the following missing functionalities
162 TF_LITE_ENSURE_MSG(context, op_context.params->ellipsis_mask == 0,
163 "ellipsis_mask is not implemented yet.");
164 TF_LITE_ENSURE_MSG(context, op_context.params->new_axis_mask == 0,
165 "new_axis_mask is not implemented yet.");
166
167 // Postpone allocation of output if any of the indexing tensors is not
168 // constant
169 if (!(IsConstantTensor(op_context.begin) &&
170 IsConstantTensor(op_context.end) &&
171 IsConstantTensor(op_context.strides))) {
172 SetTensorToDynamic(op_context.output);
173 return kTfLiteOk;
174 }
175 return ResizeOutputTensor(context, &op_context);
176}
177
178template <KernelType kernel_type>
179TfLiteStatus Eval(TfLiteContext* context, TfLiteNode* node) {

Callers

nothing calls this directly

Calls 6

NumInputsFunction · 0.85
NumDimensionsFunction · 0.85
SetTensorToDynamicFunction · 0.85
NumOutputsFunction · 0.70
IsConstantTensorFunction · 0.70
ResizeOutputTensorFunction · 0.70

Tested by

no test coverage detected