TF_LITE_ENSURE_EQ(context, NumInputs(node), 1);
TF_LITE_ENSURE_EQ(context, NumOutputs(node), 1);
- TfLiteTensor* input = GetInput(context, node, 0);
+ const TfLiteTensor* input = GetInput(context, node, 0);
TfLiteTensor* output = GetOutput(context, node, 0);
int num_dims = NumDimensions(input);
TfLiteStatus SinEval(TfLiteContext* context, TfLiteNode* node) {
using namespace tflite;
- TfLiteTensor* input = GetInput(context, node,0);
+ const TfLiteTensor* input = GetInput(context, node,0);
TfLiteTensor* output = GetOutput(context, node,0);
float* input_data = input->data.f;
TfLiteStatus GenericPrepare(TfLiteContext* context, TfLiteNode* node) {
TF_LITE_ENSURE_EQ(context, NumInputs(node), 1);
TF_LITE_ENSURE_EQ(context, NumOutputs(node), 1);
- TfLiteTensor* input = GetInput(context, node, 0);
+ const TfLiteTensor* input = GetInput(context, node, 0);
TfLiteTensor* output = GetOutput(context, node, 0);
TF_LITE_ENSURE_EQ(context, input->type, output->type);
TF_LITE_ENSURE_EQ(context, NumInputs(node), 1);
TF_LITE_ENSURE_EQ(context, NumOutputs(node), 1);
- TfLiteTensor* input = GetInput(context, node, 0);
+ const TfLiteTensor* input = GetInput(context, node, 0);
TfLiteTensor* output = GetOutput(context, node, 0);
TF_LITE_ENSURE_EQ(context, input->type, output->type);
TF_LITE_ENSURE_EQ(context, NumInputs(node), 1);
TF_LITE_ENSURE_EQ(context, NumOutputs(node), 1);
- TfLiteTensor* input = GetInput(context, node, 0);
+ const TfLiteTensor* input = GetInput(context, node, 0);
TfLiteTensor* output = GetOutput(context, node, 0);
TF_LITE_ENSURE_EQ(context, input->type, output->type);
TF_LITE_ENSURE_EQ(context, NumInputs(node), 1);
TF_LITE_ENSURE_EQ(context, NumOutputs(node), 1);
- TfLiteTensor* input = GetInput(context, node, 0);
+ const TfLiteTensor* input = GetInput(context, node, 0);
TfLiteTensor* output = GetOutput(context, node, 0);
TF_LITE_ENSURE_EQ(context, input->type, output->type);
TfLiteStatus PreluPrepare(TfLiteContext* context, TfLiteNode* node) {
TF_LITE_ENSURE_EQ(context, NumInputs(node), 2);
TF_LITE_ENSURE_EQ(context, NumOutputs(node), 1);
- TfLiteTensor* input = GetInput(context, node, 0);
+ const TfLiteTensor* input = GetInput(context, node, 0);
TfLiteTensor* output = GetOutput(context, node, 0);
- TfLiteTensor* alpha = GetInput(context, node, 1);
+ const TfLiteTensor* alpha = GetInput(context, node, 1);
output->type = input->type;
}
TfLiteStatus ReluEval(TfLiteContext* context, TfLiteNode* node) {
- TfLiteTensor* input = GetInput(context, node, 0);
+ const TfLiteTensor* input = GetInput(context, node, 0);
TfLiteTensor* output = GetOutput(context, node, 0);
switch (input->type) {
case kTfLiteFloat32: {
}
TfLiteStatus Relu1Eval(TfLiteContext* context, TfLiteNode* node) {
- TfLiteTensor* input = GetInput(context, node, 0);
+ const TfLiteTensor* input = GetInput(context, node, 0);
TfLiteTensor* output = GetOutput(context, node, 0);
switch (input->type) {
case kTfLiteFloat32: {
}
TfLiteStatus Relu6Eval(TfLiteContext* context, TfLiteNode* node) {
- TfLiteTensor* input = GetInput(context, node, 0);
+ const TfLiteTensor* input = GetInput(context, node, 0);
TfLiteTensor* output = GetOutput(context, node, 0);
switch (input->type) {
case kTfLiteFloat32: {
TfLiteStatus TanhEval(TfLiteContext* context, TfLiteNode* node) {
OpData* data = reinterpret_cast<OpData*>(node->user_data);
- TfLiteTensor* input = GetInput(context, node, 0);
+ const TfLiteTensor* input = GetInput(context, node, 0);
TfLiteTensor* output = GetOutput(context, node, 0);
switch (input->type) {
case kTfLiteFloat32: {
TfLiteStatus SigmoidEval(TfLiteContext* context, TfLiteNode* node) {
OpData* data = reinterpret_cast<OpData*>(node->user_data);
- TfLiteTensor* input = GetInput(context, node, 0);
+ const TfLiteTensor* input = GetInput(context, node, 0);
TfLiteTensor* output = GetOutput(context, node, 0);
switch (input->type) {
case kTfLiteFloat32: {
}
// Takes a 2D tensor and perform softmax along the second dimension.
-void Softmax2DFloat(TfLiteTensor* input, TfLiteTensor* output,
+void Softmax2DFloat(const TfLiteTensor* input, TfLiteTensor* output,
TfLiteSoftmaxParams* params) {
const int batch_size = input->dims->data[0];
const int input_size = input->dims->data[1];
}
}
-void Softmax2DQuantized(TfLiteTensor* input, TfLiteTensor* output,
+void Softmax2DQuantized(const TfLiteTensor* input, TfLiteTensor* output,
TfLiteSoftmaxParams* params, OpData* data) {
// TODO(ahentz): this is arguably a dirty trick. Since the implementation
// always traverses the last dimension of a 4D tensor, we will pretend our 2D
}
// Takes a 4D tensor and perform softmax along the forth dimension.
-void Softmax4DFloat(TfLiteTensor* input, TfLiteTensor* output,
+void Softmax4DFloat(const TfLiteTensor* input, TfLiteTensor* output,
TfLiteSoftmaxParams* params) {
optimized_ops::Softmax(GetTensorData<float>(input), GetTensorDims(input),
params->beta, GetTensorData<float>(output),
GetTensorDims(output));
}
-void Softmax4DQuantized(TfLiteTensor* input, TfLiteTensor* output,
+void Softmax4DQuantized(const TfLiteTensor* input, TfLiteTensor* output,
TfLiteSoftmaxParams* params, OpData* data) {
optimized_ops::Softmax(GetTensorData<uint8_t>(input), GetTensorDims(input),
data->input_multiplier, data->input_left_shift,
auto* params = reinterpret_cast<TfLiteSoftmaxParams*>(node->builtin_data);
OpData* data = reinterpret_cast<OpData*>(node->user_data);
- TfLiteTensor* input = GetInput(context, node, 0);
+ const TfLiteTensor* input = GetInput(context, node, 0);
TfLiteTensor* output = GetOutput(context, node, 0);
// TODO(ahentz): consider an implementation that works for many (all?)
}
TfLiteStatus LogSoftmaxEval(TfLiteContext* context, TfLiteNode* node) {
- TfLiteTensor* input = GetInput(context, node, 0);
+ const TfLiteTensor* input = GetInput(context, node, 0);
TfLiteTensor* output = GetOutput(context, node, 0);
switch (input->type) {
case kTfLiteFloat32:
}
TfLiteStatus PreluEval(TfLiteContext* context, TfLiteNode* node) {
- TfLiteTensor* input = GetInput(context, node, 0);
- TfLiteTensor* alpha = GetInput(context, node, 1);
- TfLiteTensor* output = GetOutput(context, node, 0);
+ const TfLiteTensor* input = GetInput(context, node, 0);
+ const TfLiteTensor* alpha = GetInput(context, node, 1);
+ const TfLiteTensor* output = GetOutput(context, node, 0);
if (input->type != kTfLiteFloat32) {
context->ReportError(context, "Only float32 supported currently.");
TF_LITE_ENSURE_EQ(context, NumInputs(node), 2);
TF_LITE_ENSURE_EQ(context, NumOutputs(node), 1);
- TfLiteTensor* input1 = GetInput(context, node, kInputTensor1);
- TfLiteTensor* input2 = GetInput(context, node, kInputTensor2);
+ const TfLiteTensor* input1 = GetInput(context, node, kInputTensor1);
+ const TfLiteTensor* input2 = GetInput(context, node, kInputTensor2);
TfLiteTensor* output = GetOutput(context, node, kOutputTensor);
TF_LITE_ENSURE_EQ(context, input1->type, input2->type);
template <KernelType kernel_type>
void EvalAddFloat(TfLiteContext* context, TfLiteNode* node,
TfLiteAddParams* params, const OpData* data,
- TfLiteTensor* input1, TfLiteTensor* input2,
+ const TfLiteTensor* input1, const TfLiteTensor* input2,
TfLiteTensor* output) {
float output_activation_min, output_activation_max;
CalculateActivationRangeFloat(params->activation, &output_activation_min,
template <KernelType kernel_type>
void EvalAddQuantized(TfLiteContext* context, TfLiteNode* node,
TfLiteAddParams* params, const OpData* data,
- TfLiteTensor* input1, TfLiteTensor* input2,
+ const TfLiteTensor* input1, const TfLiteTensor* input2,
TfLiteTensor* output) {
auto input1_offset = -input1->params.zero_point;
auto input2_offset = -input2->params.zero_point;
auto* params = reinterpret_cast<TfLiteAddParams*>(node->builtin_data);
OpData* data = reinterpret_cast<OpData*>(node->user_data);
- TfLiteTensor* input1 = GetInput(context, node, kInputTensor1);
- TfLiteTensor* input2 = GetInput(context, node, kInputTensor2);
+ const TfLiteTensor* input1 = GetInput(context, node, kInputTensor1);
+ const TfLiteTensor* input2 = GetInput(context, node, kInputTensor2);
TfLiteTensor* output = GetOutput(context, node, kOutputTensor);
if (output->type == kTfLiteFloat32) {
TF_LITE_ENSURE_EQ(context, NumInputs(node), 2);
TF_LITE_ENSURE_EQ(context, NumOutputs(node), 1);
- TfLiteTensor* input = GetInput(context, node, kInputTensor);
- TfLiteTensor* axis = GetInput(context, node, kAxis);
+ const TfLiteTensor* input = GetInput(context, node, kInputTensor);
+ const TfLiteTensor* axis = GetInput(context, node, kAxis);
// Make sure the axis is only 1 dimension.
TF_LITE_ENSURE_EQ(context, NumElements(axis), 1);
// The current impl actually ignores the axis argument.
// Only determine the index of the maximum value in the last dimension.
TfLiteStatus Eval(TfLiteContext* context, TfLiteNode* node) {
- TfLiteTensor* input = GetInput(context, node, kInputTensor);
- TfLiteTensor* axis = GetInput(context, node, kAxis);
+ const TfLiteTensor* input = GetInput(context, node, kInputTensor);
+ const TfLiteTensor* axis = GetInput(context, node, kAxis);
TfLiteTensor* output = GetOutput(context, node, kOutputTensor);
#define TF_LITE_ARG_MAX(data_type, axis_type, output_type) \
TF_LITE_ENSURE_EQ(context, NumInputs(node), 1);
TF_LITE_ENSURE_EQ(context, NumOutputs(node), 1);
- TfLiteTensor* input = GetInput(context, node, kInputTensor);
+ const TfLiteTensor* input = GetInput(context, node, kInputTensor);
TfLiteTensor* output = GetOutput(context, node, kOutputTensor);
TF_LITE_ENSURE_EQ(context, NumDimensions(input), 2);
auto* params =
reinterpret_cast<TfLiteAudioSpectrogramParams*>(node->user_data);
- TfLiteTensor* input = GetInput(context, node, kInputTensor);
+ const TfLiteTensor* input = GetInput(context, node, kInputTensor);
TfLiteTensor* output = GetOutput(context, node, kOutputTensor);
TF_LITE_ENSURE(context, params->spectrogram->Initialize(params->window_size,
TF_LITE_ENSURE_EQ(context, node->inputs->size, 4);
TF_LITE_ENSURE_EQ(context, node->outputs->size, 2);
- TfLiteTensor* input = GetInput(context, node, kInputTensor);
- TfLiteTensor* input_weights = GetInput(context, node, kWeightsTensor);
- TfLiteTensor* recurrent_weights =
+ const TfLiteTensor* input = GetInput(context, node, kInputTensor);
+ const TfLiteTensor* input_weights = GetInput(context, node, kWeightsTensor);
+ const TfLiteTensor* recurrent_weights =
GetInput(context, node, kRecurrentWeightsTensor);
- TfLiteTensor* bias = GetInput(context, node, kBiasTensor);
+ const TfLiteTensor* bias = GetInput(context, node, kBiasTensor);
// Check all the parameters of tensor match within themselves and match the
// input configuration.
TfLiteStatus Eval(TfLiteContext* context, TfLiteNode* node) {
auto* params = reinterpret_cast<TfLiteRNNParams*>(node->builtin_data);
- TfLiteTensor* input = GetInput(context, node, kInputTensor);
- TfLiteTensor* input_weights = GetInput(context, node, kWeightsTensor);
- TfLiteTensor* recurrent_weights =
+ const TfLiteTensor* input = GetInput(context, node, kInputTensor);
+ const TfLiteTensor* input_weights = GetInput(context, node, kWeightsTensor);
+ const TfLiteTensor* recurrent_weights =
GetInput(context, node, kRecurrentWeightsTensor);
- TfLiteTensor* bias = GetInput(context, node, kBiasTensor);
+ const TfLiteTensor* bias = GetInput(context, node, kBiasTensor);
TfLiteTensor* hidden_state = GetOutput(context, node, kHiddenStateTensor);
TfLiteTensor* output = GetOutput(context, node, kOutputTensor);
crops = GetInput(context, node, 2);
output = GetOutput(context, node, 0);
}
- TfLiteTensor* input;
- TfLiteTensor* block_shape;
- TfLiteTensor* crops;
+ const TfLiteTensor* input;
+ const TfLiteTensor* block_shape;
+ const TfLiteTensor* crops;
TfLiteTensor* output;
};
TF_LITE_ENSURE_EQ(context, input_to_input_weights->dims->data[1], n_input);
}
- TfLiteTensor* input_to_forget_weights =
+ const TfLiteTensor* input_to_forget_weights =
GetInput(context, node, input_to_forget_weights_tensor);
TF_LITE_ENSURE_EQ(context, input_to_forget_weights->dims->size, 2);
TF_LITE_ENSURE_EQ(context, input_to_forget_weights->dims->data[0], n_cell);
TF_LITE_ENSURE_EQ(context, input_to_forget_weights->dims->data[1], n_input);
- TfLiteTensor* input_to_cell_weights =
+ const TfLiteTensor* input_to_cell_weights =
GetInput(context, node, input_to_cell_weights_tensor);
TF_LITE_ENSURE_EQ(context, input_to_cell_weights->dims->size, 2);
TF_LITE_ENSURE_EQ(context, input_to_cell_weights->dims->data[0], n_cell);
n_output);
}
- TfLiteTensor* recurrent_to_forget_weights =
+ const TfLiteTensor* recurrent_to_forget_weights =
GetInput(context, node, recurrent_to_forget_weights_tensor);
TF_LITE_ENSURE_EQ(context, recurrent_to_forget_weights->dims->size, 2);
TF_LITE_ENSURE_EQ(context, recurrent_to_forget_weights->dims->data[0],
TF_LITE_ENSURE_EQ(context, recurrent_to_forget_weights->dims->data[1],
n_output);
- TfLiteTensor* recurrent_to_cell_weights =
+ const TfLiteTensor* recurrent_to_cell_weights =
GetInput(context, node, recurrent_to_cell_weights_tensor);
TF_LITE_ENSURE_EQ(context, recurrent_to_cell_weights->dims->size, 2);
TF_LITE_ENSURE_EQ(context, recurrent_to_cell_weights->dims->data[0], n_cell);
TF_LITE_ENSURE_EQ(context, input_gate_bias->dims->data[0], n_cell);
}
- TfLiteTensor* forget_gate_bias =
+ const TfLiteTensor* forget_gate_bias =
GetInput(context, node, forget_gate_bias_tensor);
TF_LITE_ENSURE_EQ(context, forget_gate_bias->dims->size, 1);
TF_LITE_ENSURE_EQ(context, forget_gate_bias->dims->data[0], n_cell);
- TfLiteTensor* cell_bias = GetInput(context, node, cell_gate_bias_tensor);
+ const TfLiteTensor* cell_bias =
+ GetInput(context, node, cell_gate_bias_tensor);
TF_LITE_ENSURE_EQ(context, cell_bias->dims->size, 1);
TF_LITE_ENSURE_EQ(context, cell_bias->dims->data[0], n_cell);
- TfLiteTensor* output_gate_bias =
+ const TfLiteTensor* output_gate_bias =
GetInput(context, node, output_gate_bias_tensor);
TF_LITE_ENSURE_EQ(context, output_gate_bias->dims->size, 1);
TF_LITE_ENSURE_EQ(context, output_gate_bias->dims->data[0], n_cell);
// Inferring batch size, number of outputs and sequence length and
// number of cells from the input tensors.
- TfLiteTensor* input = GetInput(context, node, kInputTensor);
+ const TfLiteTensor* input = GetInput(context, node, kInputTensor);
TF_LITE_ENSURE(context, input->dims->size > 1);
const int max_time = input->dims->data[0];
const int n_batch = input->dims->data[1];
const int n_input = input->dims->data[2];
- TfLiteTensor* fw_input_to_output_weights =
+ const TfLiteTensor* fw_input_to_output_weights =
GetInput(context, node, kFwInputToOutputWeightsTensor);
const int n_fw_cell = fw_input_to_output_weights->dims->data[0];
TF_LITE_ENSURE_EQ(context, fw_input_to_output_weights->dims->size, 2);
TF_LITE_ENSURE_EQ(context, fw_input_to_output_weights->dims->data[1],
n_input);
- TfLiteTensor* fw_recurrent_to_output_weights =
+ const TfLiteTensor* fw_recurrent_to_output_weights =
GetInput(context, node, kFwRecurrentToOutputWeightsTensor);
TF_LITE_ENSURE_EQ(context, fw_recurrent_to_output_weights->dims->size, 2);
TF_LITE_ENSURE_EQ(context, fw_recurrent_to_output_weights->dims->data[0],
TF_LITE_ENSURE_OK(context, context->ResizeTensor(context, fw_scratch_buffer,
fw_scratch_buffer_size));
// Same for the backward cell.
- TfLiteTensor* bw_input_to_output_weights =
+ const TfLiteTensor* bw_input_to_output_weights =
GetInput(context, node, kBwInputToOutputWeightsTensor);
const int n_bw_cell = bw_input_to_output_weights->dims->data[0];
TF_LITE_ENSURE_EQ(context, bw_input_to_output_weights->dims->size, 2);
TF_LITE_ENSURE_EQ(context, bw_input_to_output_weights->dims->data[1],
n_input);
- TfLiteTensor* bw_recurrent_to_output_weights =
+ const TfLiteTensor* bw_recurrent_to_output_weights =
GetInput(context, node, kBwRecurrentToOutputWeightsTensor);
TF_LITE_ENSURE_EQ(context, bw_recurrent_to_output_weights->dims->size, 2);
TF_LITE_ENSURE_EQ(context, bw_recurrent_to_output_weights->dims->data[0],
auto* params = reinterpret_cast<TfLiteLSTMParams*>(node->builtin_data);
// Input tensor.
- TfLiteTensor* input = GetInput(context, node, kInputTensor);
+ const TfLiteTensor* input = GetInput(context, node, kInputTensor);
const int max_time = input->dims->data[0];
const int n_batch = input->dims->data[1];
const int n_input = input->dims->data[2];
// Tensors for the forward cell.
TfLiteTensor* fw_input_to_input_weights =
GetOptionalInputTensor(context, node, kFwInputToInputWeightsTensor);
- TfLiteTensor* fw_input_to_forget_weights =
+ const TfLiteTensor* fw_input_to_forget_weights =
GetInput(context, node, kFwInputToForgetWeightsTensor);
- TfLiteTensor* fw_input_to_cell_weights =
+ const TfLiteTensor* fw_input_to_cell_weights =
GetInput(context, node, kFwInputToCellWeightsTensor);
- TfLiteTensor* fw_input_to_output_weights =
+ const TfLiteTensor* fw_input_to_output_weights =
GetInput(context, node, kFwInputToOutputWeightsTensor);
TfLiteTensor* fw_recurrent_to_input_weights =
GetOptionalInputTensor(context, node, kFwRecurrentToInputWeightsTensor);
- TfLiteTensor* fw_recurrent_to_forget_weights =
+ const TfLiteTensor* fw_recurrent_to_forget_weights =
GetInput(context, node, kFwRecurrentToForgetWeightsTensor);
- TfLiteTensor* fw_recurrent_to_cell_weights =
+ const TfLiteTensor* fw_recurrent_to_cell_weights =
GetInput(context, node, kFwRecurrentToCellWeightsTensor);
- TfLiteTensor* fw_recurrent_to_output_weights =
+ const TfLiteTensor* fw_recurrent_to_output_weights =
GetInput(context, node, kFwRecurrentToOutputWeightsTensor);
TfLiteTensor* fw_cell_to_input_weights =
TfLiteTensor* fw_input_gate_bias =
GetOptionalInputTensor(context, node, kFwInputGateBiasTensor);
- TfLiteTensor* fw_forget_gate_bias =
+ const TfLiteTensor* fw_forget_gate_bias =
GetInput(context, node, kFwForgetGateBiasTensor);
- TfLiteTensor* fw_cell_bias = GetInput(context, node, kFwCellGateBiasTensor);
- TfLiteTensor* fw_output_gate_bias =
+ const TfLiteTensor* fw_cell_bias =
+ GetInput(context, node, kFwCellGateBiasTensor);
+ const TfLiteTensor* fw_output_gate_bias =
GetInput(context, node, kFwOutputGateBiasTensor);
TfLiteTensor* fw_projection_weights =
// Tensors for the backward cell.
TfLiteTensor* bw_input_to_input_weights =
GetOptionalInputTensor(context, node, kBwInputToInputWeightsTensor);
- TfLiteTensor* bw_input_to_forget_weights =
+ const TfLiteTensor* bw_input_to_forget_weights =
GetInput(context, node, kBwInputToForgetWeightsTensor);
- TfLiteTensor* bw_input_to_cell_weights =
+ const TfLiteTensor* bw_input_to_cell_weights =
GetInput(context, node, kBwInputToCellWeightsTensor);
- TfLiteTensor* bw_input_to_output_weights =
+ const TfLiteTensor* bw_input_to_output_weights =
GetInput(context, node, kBwInputToOutputWeightsTensor);
TfLiteTensor* bw_recurrent_to_input_weights =
GetOptionalInputTensor(context, node, kBwRecurrentToInputWeightsTensor);
- TfLiteTensor* bw_recurrent_to_forget_weights =
+ const TfLiteTensor* bw_recurrent_to_forget_weights =
GetInput(context, node, kBwRecurrentToForgetWeightsTensor);
- TfLiteTensor* bw_recurrent_to_cell_weights =
+ const TfLiteTensor* bw_recurrent_to_cell_weights =
GetInput(context, node, kBwRecurrentToCellWeightsTensor);
- TfLiteTensor* bw_recurrent_to_output_weights =
+ const TfLiteTensor* bw_recurrent_to_output_weights =
GetInput(context, node, kBwRecurrentToOutputWeightsTensor);
TfLiteTensor* bw_cell_to_input_weights =
TfLiteTensor* bw_input_gate_bias =
GetOptionalInputTensor(context, node, kBwInputGateBiasTensor);
- TfLiteTensor* bw_forget_gate_bias =
+ const TfLiteTensor* bw_forget_gate_bias =
GetInput(context, node, kBwForgetGateBiasTensor);
- TfLiteTensor* bw_cell_bias = GetInput(context, node, kBwCellGateBiasTensor);
- TfLiteTensor* bw_output_gate_bias =
+ const TfLiteTensor* bw_cell_bias =
+ GetInput(context, node, kBwCellGateBiasTensor);
+ const TfLiteTensor* bw_output_gate_bias =
GetInput(context, node, kBwOutputGateBiasTensor);
TfLiteTensor* bw_projection_weights =
TfLiteStatus Prepare(TfLiteContext* context, TfLiteNode* node) {
TF_LITE_ENSURE_EQ(context, NumInputs(node), 1);
TF_LITE_ENSURE_EQ(context, NumOutputs(node), 1);
- TfLiteTensor* input = GetInput(context, node, kInputTensor);
+ const TfLiteTensor* input = GetInput(context, node, kInputTensor);
TfLiteTensor* output = GetOutput(context, node, kOutputTensor);
// TODO(ahentz): these two checks would make the new implementation
}
TfLiteStatus Eval(TfLiteContext* context, TfLiteNode* node) {
- TfLiteTensor* input = GetInput(context, node, kInputTensor);
+ const TfLiteTensor* input = GetInput(context, node, kInputTensor);
TfLiteTensor* output = GetOutput(context, node, kOutputTensor);
const int num_elements = NumElements(input);
TF_LITE_ENSURE_EQ(context, num_elements, NumElements(output));
TF_LITE_ENSURE_EQ(context, NumInputs(node), 2);
TF_LITE_ENSURE_EQ(context, NumOutputs(node), 1);
- TfLiteTensor* input1 = GetInput(context, node, kInputTensor1);
- TfLiteTensor* input2 = GetInput(context, node, kInputTensor2);
+ const TfLiteTensor* input1 = GetInput(context, node, kInputTensor1);
+ const TfLiteTensor* input2 = GetInput(context, node, kInputTensor2);
TfLiteTensor* output = GetOutput(context, node, kOutputTensor);
// Don't support string and bool.
GetTensorData<bool>(output), GetTensorDims(output));
TfLiteStatus GreaterEval(TfLiteContext* context, TfLiteNode* node) {
- TfLiteTensor* input1 = GetInput(context, node, kInputTensor1);
- TfLiteTensor* input2 = GetInput(context, node, kInputTensor2);
+ const TfLiteTensor* input1 = GetInput(context, node, kInputTensor1);
+ const TfLiteTensor* input2 = GetInput(context, node, kInputTensor2);
TfLiteTensor* output = GetOutput(context, node, kOutputTensor);
bool requires_broadcast = !HaveSameShapes(input1, input2);
// TODO(renjieliu): Support quantized data.
}
TfLiteStatus GreaterEqualEval(TfLiteContext* context, TfLiteNode* node) {
- TfLiteTensor* input1 = GetInput(context, node, kInputTensor1);
- TfLiteTensor* input2 = GetInput(context, node, kInputTensor2);
+ const TfLiteTensor* input1 = GetInput(context, node, kInputTensor1);
+ const TfLiteTensor* input2 = GetInput(context, node, kInputTensor2);
TfLiteTensor* output = GetOutput(context, node, kOutputTensor);
bool requires_broadcast = !HaveSameShapes(input1, input2);
// TODO(renjieliu): Support quantized data.
}
TfLiteStatus LessEval(TfLiteContext* context, TfLiteNode* node) {
- TfLiteTensor* input1 = GetInput(context, node, kInputTensor1);
- TfLiteTensor* input2 = GetInput(context, node, kInputTensor2);
+ const TfLiteTensor* input1 = GetInput(context, node, kInputTensor1);
+ const TfLiteTensor* input2 = GetInput(context, node, kInputTensor2);
TfLiteTensor* output = GetOutput(context, node, kOutputTensor);
bool requires_broadcast = !HaveSameShapes(input1, input2);
// TODO(renjieliu): Support quantized data.
}
TfLiteStatus LessEqualEval(TfLiteContext* context, TfLiteNode* node) {
- TfLiteTensor* input1 = GetInput(context, node, kInputTensor1);
- TfLiteTensor* input2 = GetInput(context, node, kInputTensor2);
+ const TfLiteTensor* input1 = GetInput(context, node, kInputTensor1);
+ const TfLiteTensor* input2 = GetInput(context, node, kInputTensor2);
TfLiteTensor* output = GetOutput(context, node, kOutputTensor);
bool requires_broadcast = !HaveSameShapes(input1, input2);
// TODO(renjieliu): Support quantized data.
bool hasBias = NumInputs(node) == 3;
TF_LITE_ENSURE(context, hasBias || NumInputs(node) == 2);
- TfLiteTensor* input = GetInput(context, node, kInputTensor);
- TfLiteTensor* filter = GetInput(context, node, kFilterTensor);
- TfLiteTensor* bias = nullptr;
+ const TfLiteTensor* input = GetInput(context, node, kInputTensor);
+ const TfLiteTensor* filter = GetInput(context, node, kFilterTensor);
+ const TfLiteTensor* bias = nullptr;
TF_LITE_ENSURE_EQ(context, NumOutputs(node), 1);
TfLiteTensor* output = GetOutput(context, node, kOutputTensor);
template <KernelType kernel_type>
void EvalFloat(TfLiteContext* context, TfLiteNode* node,
TfLiteDepthwiseConvParams* params, OpData* data,
- TfLiteTensor* input, TfLiteTensor* filter, TfLiteTensor* bias,
- TfLiteTensor* output) {
+ const TfLiteTensor* input, const TfLiteTensor* filter,
+ const TfLiteTensor* bias, TfLiteTensor* output) {
float output_activation_min, output_activation_max;
CalculateActivationRangeFloat(params->activation, &output_activation_min,
&output_activation_max);
template <KernelType kernel_type>
void EvalQuantized(TfLiteContext* context, TfLiteNode* node,
TfLiteDepthwiseConvParams* params, OpData* data,
- TfLiteTensor* input, TfLiteTensor* filter,
- TfLiteTensor* bias, TfLiteTensor* output) {
+ const TfLiteTensor* input, const TfLiteTensor* filter,
+ const TfLiteTensor* bias, TfLiteTensor* output) {
auto input_offset = -input->params.zero_point;
auto filter_offset = -filter->params.zero_point;
auto output_offset = output->params.zero_point;
OpData* data = reinterpret_cast<OpData*>(node->user_data);
TfLiteTensor* output = GetOutput(context, node, kOutputTensor);
- TfLiteTensor* input = GetInput(context, node, kInputTensor);
- TfLiteTensor* filter = GetInput(context, node, kFilterTensor);
- TfLiteTensor* bias =
+ const TfLiteTensor* input = GetInput(context, node, kInputTensor);
+ const TfLiteTensor* filter = GetInput(context, node, kFilterTensor);
+ const TfLiteTensor* bias =
(NumInputs(node) == 3) ? GetInput(context, node, kBiasTensor) : nullptr;
// TODO(aselle): Consider whether float conv and quantized conv should be
input = GetInput(context, node, 0);
output = GetOutput(context, node, 0);
}
- TfLiteTensor* input;
+ const TfLiteTensor* input;
TfLiteTensor* output;
};
TF_LITE_ENSURE_EQ(context, NumInputs(node), 2);
TF_LITE_ENSURE_EQ(context, NumOutputs(node), 1);
- TfLiteTensor* input1 = GetInput(context, node, kInputTensor1);
- TfLiteTensor* input2 = GetInput(context, node, kInputTensor2);
+ const TfLiteTensor* input1 = GetInput(context, node, kInputTensor1);
+ const TfLiteTensor* input2 = GetInput(context, node, kInputTensor2);
TfLiteTensor* output = GetOutput(context, node, kOutputTensor);
TF_LITE_ENSURE_EQ(context, input1->type, input2->type);
template <KernelType kernel_type>
void EvalFloat(TfLiteContext* context, TfLiteNode* node,
TfLiteDivParams* params, const OpData* data,
- TfLiteTensor* input1, TfLiteTensor* input2,
+ const TfLiteTensor* input1, const TfLiteTensor* input2,
TfLiteTensor* output) {
float output_activation_min, output_activation_max;
CalculateActivationRangeFloat(params->activation, &output_activation_min,
#undef TF_LITE_DIV
}
-
-
template <KernelType kernel_type>
TfLiteStatus Eval(TfLiteContext* context, TfLiteNode* node) {
auto* params = reinterpret_cast<TfLiteDivParams*>(node->builtin_data);
OpData* data = reinterpret_cast<OpData*>(node->user_data);
- TfLiteTensor* input1 = GetInput(context, node, kInputTensor1);
- TfLiteTensor* input2 = GetInput(context, node, kInputTensor2);
+ const TfLiteTensor* input1 = GetInput(context, node, kInputTensor1);
+ const TfLiteTensor* input2 = GetInput(context, node, kInputTensor2);
TfLiteTensor* output = GetOutput(context, node, kOutputTensor);
if (output->type == kTfLiteFloat32) {
TfLiteStatus SinPrepare(TfLiteContext* context, TfLiteNode* node) {
TF_LITE_ENSURE_EQ(context, NumInputs(node), 1);
TF_LITE_ENSURE_EQ(context, NumOutputs(node), 1);
- TfLiteTensor* input = GetInput(context, node, 0);
+ const TfLiteTensor* input = GetInput(context, node, 0);
TfLiteTensor* output = GetOutput(context, node, 0);
TF_LITE_ENSURE_EQ(context, input->type, output->type);
// Quantized float is not supported yet.
}
TfLiteStatus SinEval(TfLiteContext* context, TfLiteNode* node) {
- TfLiteTensor* input = GetInput(context, node, 0);
+ const TfLiteTensor* input = GetInput(context, node, 0);
TfLiteTensor* output = GetOutput(context, node, 0);
switch (input->type) {
case kTfLiteFloat32: {
size_t elements = NumElements(input);
- float* in = GetTensorData<float>(input);
- float* in_end = in + elements;
+ const float* in = GetTensorData<float>(input);
+ const float* in_end = in + elements;
float* out = output->data.f;
for (; in < in_end; in++, out++) *out = std::sin(*in);
return kTfLiteOk;
TF_LITE_ENSURE_EQ(context, NumInputs(node), 2);
TF_LITE_ENSURE_EQ(context, NumOutputs(node), 1);
- TfLiteTensor* lookup = GetInput(context, node, 0);
+ const TfLiteTensor* lookup = GetInput(context, node, 0);
TF_LITE_ENSURE_EQ(context, NumDimensions(lookup), 1);
TF_LITE_ENSURE_EQ(context, lookup->type, kTfLiteInt32);
- TfLiteTensor* value = GetInput(context, node, 1);
+ const TfLiteTensor* value = GetInput(context, node, 1);
TF_LITE_ENSURE(context, NumDimensions(value) >= 2);
TfLiteTensor* output = GetOutput(context, node, 0);
TfLiteStatus Eval(TfLiteContext* context, TfLiteNode* node) {
TfLiteTensor* output = GetOutput(context, node, 0);
- TfLiteTensor* lookup = GetInput(context, node, 0);
- TfLiteTensor* value = GetInput(context, node, 1);
+ const TfLiteTensor* lookup = GetInput(context, node, 0);
+ const TfLiteTensor* value = GetInput(context, node, 1);
const int row_size = SizeOfDimension(value, 0);
const int row_bytes = value->bytes / row_size;
TF_LITE_ENSURE_EQ(context, NumInputs(node), 5);
TF_LITE_ENSURE_EQ(context, NumOutputs(node), 1);
- TfLiteTensor* ids = GetInput(context, node, 0);
+ const TfLiteTensor* ids = GetInput(context, node, 0);
TF_LITE_ENSURE_EQ(context, NumDimensions(ids), 1);
TF_LITE_ENSURE_EQ(context, ids->type, kTfLiteInt32);
- TfLiteTensor* indices = GetInput(context, node, 1);
+ const TfLiteTensor* indices = GetInput(context, node, 1);
TF_LITE_ENSURE_EQ(context, NumDimensions(indices), 2);
TF_LITE_ENSURE_EQ(context, indices->type, kTfLiteInt32);
- TfLiteTensor* shape = GetInput(context, node, 2);
+ const TfLiteTensor* shape = GetInput(context, node, 2);
TF_LITE_ENSURE_EQ(context, NumDimensions(shape), 1);
TF_LITE_ENSURE_EQ(context, shape->type, kTfLiteInt32);
- TfLiteTensor* weights = GetInput(context, node, 3);
+ const TfLiteTensor* weights = GetInput(context, node, 3);
TF_LITE_ENSURE_EQ(context, NumDimensions(weights), 1);
TF_LITE_ENSURE_EQ(context, weights->type, kTfLiteFloat32);
TF_LITE_ENSURE_EQ(context, SizeOfDimension(indices, 0),
SizeOfDimension(weights, 0));
- TfLiteTensor* value = GetInput(context, node, 4);
+ const TfLiteTensor* value = GetInput(context, node, 4);
TF_LITE_ENSURE(context, NumDimensions(value) >= 2);
// Mark the output as a dynamic tensor.
auto* params =
reinterpret_cast<TfLiteEmbeddingLookupSparseParams*>(node->builtin_data);
TfLiteTensor* output = GetOutput(context, node, 0);
- TfLiteTensor* ids = GetInput(context, node, 0);
- TfLiteTensor* indices = GetInput(context, node, 1);
- TfLiteTensor* dense_shape = GetInput(context, node, 2);
- TfLiteTensor* weights = GetInput(context, node, 3);
- TfLiteTensor* value = GetInput(context, node, 4);
+ const TfLiteTensor* ids = GetInput(context, node, 0);
+ const TfLiteTensor* indices = GetInput(context, node, 1);
+ const TfLiteTensor* dense_shape = GetInput(context, node, 2);
+ const TfLiteTensor* weights = GetInput(context, node, 3);
+ const TfLiteTensor* value = GetInput(context, node, 4);
const int lookup_rank = SizeOfDimension(indices, 1);
const int embedding_rank = NumDimensions(value);
input = GetInput(context, node, 0);
output = GetOutput(context, node, 0);
}
- TfLiteTensor* input;
+ const TfLiteTensor* input;
TfLiteTensor* output;
};
constexpr int kOutputTensor = 0;
TfLiteStatus Prepare(TfLiteContext* context, TfLiteNode* node) {
- TfLiteTensor* input = GetInput(context, node, kInputTensor);
+ const TfLiteTensor* input = GetInput(context, node, kInputTensor);
TfLiteTensor* output = GetOutput(context, node, kOutputTensor);
TF_LITE_ENSURE_EQ(context, NumInputs(node), 1);
TF_LITE_ENSURE_EQ(context, NumOutputs(node), 1);
}
TfLiteStatus Eval(TfLiteContext* context, TfLiteNode* node) {
- TfLiteTensor* input = GetInput(context, node, kInputTensor);
+ const TfLiteTensor* input = GetInput(context, node, kInputTensor);
TfLiteTensor* output = GetOutput(context, node, kOutputTensor);
optimized_ops::Floor(GetTensorData<float>(input), GetTensorDims(input),
TF_LITE_ENSURE_EQ(context, node->inputs->size, 3);
TF_LITE_ENSURE_EQ(context, node->outputs->size, 1);
- TfLiteTensor* input = GetInput(context, node, kInputTensor);
- TfLiteTensor* filter = GetInput(context, node, kWeightsTensor);
+ const TfLiteTensor* input = GetInput(context, node, kInputTensor);
+ const TfLiteTensor* filter = GetInput(context, node, kWeightsTensor);
TfLiteTensor* bias = GetOptionalInputTensor(context, node, kBiasTensor);
TfLiteTensor* output = GetOutput(context, node, kOutputTensor);
TfLiteStatus EvalPie(TfLiteContext* context, TfLiteNode* node,
TfLiteFullyConnectedParams* params, OpData* data,
- TfLiteTensor* input, TfLiteTensor* filter,
- TfLiteTensor* bias, TfLiteTensor* output) {
+ const TfLiteTensor* input, const TfLiteTensor* filter,
+ const TfLiteTensor* bias, TfLiteTensor* output) {
int total_input_size = 1;
for (int i = 0; i < input->dims->size; i++) {
total_input_size *= input->dims->data[i];
TfLiteStatus EvalPieQuantized(TfLiteContext* context, TfLiteNode* node,
TfLiteFullyConnectedParams* params, OpData* data,
- TfLiteTensor* input, TfLiteTensor* filter,
- TfLiteTensor* bias, TfLiteTensor* input_quantized,
+ const TfLiteTensor* input,
+ const TfLiteTensor* filter,
+ const TfLiteTensor* bias,
+ TfLiteTensor* input_quantized,
TfLiteTensor* output) {
// Check the types for this hybrid Op.
TF_LITE_ENSURE_EQ(context, input->type, kTfLiteFloat32);
template <KernelType kernel_type>
TfLiteStatus EvalQuantized(TfLiteContext* context, TfLiteNode* node,
TfLiteFullyConnectedParams* params, OpData* data,
- TfLiteTensor* input, TfLiteTensor* filter,
- TfLiteTensor* bias, TfLiteTensor* output) {
+ const TfLiteTensor* input,
+ const TfLiteTensor* filter, const TfLiteTensor* bias,
+ TfLiteTensor* output) {
gemmlowp::GemmContext* gemm_context = gemm_support::GetFromContext(context);
int32_t input_offset = -input->params.zero_point;
template <KernelType kernel_type>
TfLiteStatus EvalFloat(TfLiteContext* context, TfLiteNode* node,
TfLiteFullyConnectedParams* params, OpData* data,
- TfLiteTensor* input, TfLiteTensor* filter,
- TfLiteTensor* bias, TfLiteTensor* output) {
+ const TfLiteTensor* input, const TfLiteTensor* filter,
+ const TfLiteTensor* bias, TfLiteTensor* output) {
float output_activation_min, output_activation_max;
CalculateActivationRangeFloat(params->activation, &output_activation_min,
&output_activation_max);
reinterpret_cast<TfLiteFullyConnectedParams*>(node->builtin_data);
OpData* data = reinterpret_cast<OpData*>(node->user_data);
- TfLiteTensor* input = GetInput(context, node, kInputTensor);
- TfLiteTensor* filter = GetInput(context, node, kWeightsTensor);
+ const TfLiteTensor* input = GetInput(context, node, kInputTensor);
+ const TfLiteTensor* filter = GetInput(context, node, kWeightsTensor);
TfLiteTensor* bias = GetOptionalInputTensor(context, node, kBiasTensor);
TfLiteTensor* output = GetOutput(context, node, kOutputTensor);
const auto* params =
reinterpret_cast<const TfLiteGatherParams*>(node->builtin_data);
- TfLiteTensor* input = GetInput(context, node, kInputTensor);
- TfLiteTensor* positions = GetInput(context, node, kInputPositions);
+ const TfLiteTensor* input = GetInput(context, node, kInputTensor);
+ const TfLiteTensor* positions = GetInput(context, node, kInputPositions);
TfLiteTensor* output = GetOutput(context, node, kOutputTensor);
// Only INT32 positions are supported.
TF_LITE_ENSURE_EQ(context, positions->type, kTfLiteInt32);
}
TfLiteStatus Eval(TfLiteContext* context, TfLiteNode* node) {
- TfLiteTensor* input = GetInput(context, node, kInputTensor);
- TfLiteTensor* positions = GetInput(context, node, kInputPositions);
+ const TfLiteTensor* input = GetInput(context, node, kInputTensor);
+ const TfLiteTensor* positions = GetInput(context, node, kInputPositions);
TfLiteTensor* output = GetOutput(context, node, kOutputTensor);
const int input_rank = NumDimensions(input);
#define TF_LITE_GATHER(data_type, index_type) \
TF_LITE_ENSURE_EQ(context, NumInputs(node), 3);
TF_LITE_ENSURE_EQ(context, NumOutputs(node), 2);
- TfLiteTensor* lookup = GetInput(context, node, 0);
+ const TfLiteTensor* lookup = GetInput(context, node, 0);
TF_LITE_ENSURE_EQ(context, NumDimensions(lookup), 1);
TF_LITE_ENSURE_EQ(context, lookup->type, kTfLiteInt32);
- TfLiteTensor* key = GetInput(context, node, 1);
+ const TfLiteTensor* key = GetInput(context, node, 1);
TF_LITE_ENSURE_EQ(context, NumDimensions(key), 1);
TF_LITE_ENSURE_EQ(context, key->type, kTfLiteInt32);
- TfLiteTensor* value = GetInput(context, node, 2);
+ const TfLiteTensor* value = GetInput(context, node, 2);
TF_LITE_ENSURE(context, NumDimensions(value) >= 1);
TF_LITE_ENSURE_EQ(context, SizeOfDimension(key, 0),
SizeOfDimension(value, 0));
TfLiteStatus Eval(TfLiteContext* context, TfLiteNode* node) {
TfLiteTensor* output = GetOutput(context, node, 0);
TfLiteTensor* hits = GetOutput(context, node, 1);
- TfLiteTensor* lookup = GetInput(context, node, 0);
- TfLiteTensor* key = GetInput(context, node, 1);
- TfLiteTensor* value = GetInput(context, node, 2);
+ const TfLiteTensor* lookup = GetInput(context, node, 0);
+ const TfLiteTensor* key = GetInput(context, node, 1);
+ const TfLiteTensor* value = GetInput(context, node, 2);
const int num_rows = SizeOfDimension(value, 0);
const int row_bytes = value->bytes / num_rows;
}
template <typename T, typename U>
-inline bool Mean(T* input_data, const int* input_dims, const int input_num_dims,
- T* output_data, const int* output_dims,
- const int output_num_dims, const int* axis,
- const int num_axis_dimensions, bool keep_dims, int* temp_index,
- int* resolved_axis, U* temp_sum) {
+inline bool Mean(const T* input_data, const int* input_dims,
+ const int input_num_dims, T* output_data,
+ const int* output_dims, const int output_num_dims,
+ const int* axis, const int num_axis_dimensions, bool keep_dims,
+ int* temp_index, int* resolved_axis, U* temp_sum) {
// resets output data.
size_t num_outputs = 1;
for (int idx = 0; idx < output_num_dims; ++idx) {
return tensor != nullptr ? tensor->data.b : nullptr;
}
+template <typename T>
+inline const T* GetTensorData(const TfLiteTensor* tensor);
+
+template <>
+inline const float* GetTensorData(const TfLiteTensor* tensor) {
+ return tensor != nullptr ? tensor->data.f : nullptr;
+}
+
+template <>
+inline const uint8_t* GetTensorData(const TfLiteTensor* tensor) {
+ return tensor != nullptr ? tensor->data.uint8 : nullptr;
+}
+
+template <>
+inline const int32_t* GetTensorData(const TfLiteTensor* tensor) {
+ return tensor != nullptr ? tensor->data.i32 : nullptr;
+}
+
+template <>
+inline const int64_t* GetTensorData(const TfLiteTensor* tensor) {
+ return tensor != nullptr ? tensor->data.i64 : nullptr;
+}
+
+template <>
+inline const bool* GetTensorData(const TfLiteTensor* tensor) {
+ return tensor != nullptr ? tensor->data.b : nullptr;
+}
+
inline int RemapDim(int max_dimensions, int d) {
return max_dimensions - d - 1;
}
namespace tflite {
-TfLiteStatus GetQuantizedConvolutionMultipler(
- TfLiteContext* context, TfLiteTensor* input, TfLiteTensor* filter,
- TfLiteTensor* bias, TfLiteTensor* output, double* multiplier) {
+TfLiteStatus GetQuantizedConvolutionMultipler(TfLiteContext* context,
+ const TfLiteTensor* input,
+ const TfLiteTensor* filter,
+ const TfLiteTensor* bias,
+ TfLiteTensor* output,
+ double* multiplier) {
const double input_product_scale = input->params.scale * filter->params.scale;
const double bias_scale = bias->params.scale;
const double output_scale = output->params.scale;
}
}
-bool HaveSameShapes(TfLiteTensor* input1, TfLiteTensor* input2) {
+bool HaveSameShapes(const TfLiteTensor* input1, const TfLiteTensor* input2) {
return TfLiteIntArrayEqual(input1->dims, input2->dims);
}
TfLiteStatus CalculateShapeForBroadcast(TfLiteContext* context,
- TfLiteTensor* input1,
- TfLiteTensor* input2,
+ const TfLiteTensor* input1,
+ const TfLiteTensor* input2,
TfLiteIntArray** output_shape) {
int64_t dims1 = NumDimensions(input1);
int64_t dims2 = NumDimensions(input2);
inline int SizeOfDimension(const TfLiteTensor* t, int dim) {
return t->dims->data[dim];
}
-inline TfLiteTensor* GetInput(TfLiteContext* context, TfLiteNode* node,
- int index) {
+inline const TfLiteTensor* GetInput(TfLiteContext* context, TfLiteNode* node,
+ int index) {
return &context->tensors[node->inputs->data[index]];
}
inline TfLiteTensor* GetOutput(TfLiteContext* context, TfLiteNode* node,
// Calculates the multiplication factor for a quantized convolution (or
// quantized depthwise convolution) involving the given tensors. Returns an
// error if the scales of the tensors are not compatible.
-TfLiteStatus GetQuantizedConvolutionMultipler(
- TfLiteContext* context, TfLiteTensor* input, TfLiteTensor* filter,
- TfLiteTensor* bias, TfLiteTensor* output, double* multiplier);
+TfLiteStatus GetQuantizedConvolutionMultipler(TfLiteContext* context,
+ const TfLiteTensor* input,
+ const TfLiteTensor* filter,
+ const TfLiteTensor* bias,
+ TfLiteTensor* output,
+ double* multiplier);
// Calculates the useful range of an activation layer given its activation
// tensor.
float* activation_max);
// Return true if the given tensors have the same shape.
-bool HaveSameShapes(TfLiteTensor* input1, TfLiteTensor* input2);
+bool HaveSameShapes(const TfLiteTensor* input1, const TfLiteTensor* input2);
// Calculate the output_shape that is necessary for element-wise operations
// with broadcasting involving the two input tensors.
TfLiteStatus CalculateShapeForBroadcast(TfLiteContext* context,
- TfLiteTensor* input1,
- TfLiteTensor* input2,
+ const TfLiteTensor* input1,
+ const TfLiteTensor* input2,
TfLiteIntArray** output_shape);
} // namespace tflite
TF_LITE_ENSURE_EQ(context, NumInputs(node), 1);
TF_LITE_ENSURE_EQ(context, NumOutputs(node), 1);
- TfLiteTensor* input = GetInput(context, node, kInputTensor);
+ const TfLiteTensor* input = GetInput(context, node, kInputTensor);
TfLiteTensor* output = GetOutput(context, node, kOutputTensor);
TF_LITE_ENSURE(context, NumDimensions(input) <= 4);
template <KernelType kernel_type>
TfLiteStatus Eval(TfLiteContext* context, TfLiteNode* node) {
- TfLiteTensor* input = GetInput(context, node, kInputTensor);
+ const TfLiteTensor* input = GetInput(context, node, kInputTensor);
TfLiteTensor* output = GetOutput(context, node, kOutputTensor);
if (output->type == kTfLiteFloat32) {
TF_LITE_ENSURE_EQ(context, NumInputs(node), 1);
TF_LITE_ENSURE_EQ(context, NumOutputs(node), 1);
- TfLiteTensor* input = GetInput(context, node, kInputTensor);
+ const TfLiteTensor* input = GetInput(context, node, kInputTensor);
TfLiteTensor* output = GetOutput(context, node, kOutputTensor);
TF_LITE_ENSURE_EQ(context, NumDimensions(input), 4);
auto* params =
reinterpret_cast<TfLiteLocalResponseNormParams*>(node->builtin_data);
- TfLiteTensor* input = GetInput(context, node, kInputTensor);
+ const TfLiteTensor* input = GetInput(context, node, kInputTensor);
TfLiteTensor* output = GetOutput(context, node, kOutputTensor);
if (output->type == kTfLiteFloat32) {
TF_LITE_ENSURE(context, NumInputs(node) == 2 || NumInputs(node) == 3);
TF_LITE_ENSURE_EQ(context, NumOutputs(node), 1);
- TfLiteTensor* hash = GetInput(context, node, 0);
+ const TfLiteTensor* hash = GetInput(context, node, 0);
TF_LITE_ENSURE_EQ(context, NumDimensions(hash), 2);
// Support up to 32 bits.
TF_LITE_ENSURE(context, SizeOfDimension(hash, 1) <= 32);
- TfLiteTensor* input = GetInput(context, node, 1);
+ const TfLiteTensor* input = GetInput(context, node, 1);
TF_LITE_ENSURE(context, NumDimensions(input) >= 1);
if (NumInputs(node) == 3) {
- TfLiteTensor* weight = GetInput(context, node, 2);
+ const TfLiteTensor* weight = GetInput(context, node, 2);
TF_LITE_ENSURE_EQ(context, NumDimensions(weight), 1);
TF_LITE_ENSURE_EQ(context, SizeOfDimension(weight, 0),
SizeOfDimension(input, 0));
reinterpret_cast<TfLiteLSHProjectionParams*>(node->builtin_data);
int32_t* out_buf = GetOutput(context, node, 0)->data.i32;
- TfLiteTensor* hash = GetInput(context, node, 0);
- TfLiteTensor* input = GetInput(context, node, 1);
- TfLiteTensor* weight =
+ const TfLiteTensor* hash = GetInput(context, node, 0);
+ const TfLiteTensor* input = GetInput(context, node, 1);
+ const TfLiteTensor* weight =
NumInputs(node) == 2 ? nullptr : GetInput(context, node, 2);
switch (params->type) {
TF_LITE_ENSURE_EQ(context, input_to_input_weights->dims->data[1], n_input);
}
- TfLiteTensor* input_to_forget_weights =
+ const TfLiteTensor* input_to_forget_weights =
GetInput(context, node, kInputToForgetWeightsTensor);
TF_LITE_ENSURE_EQ(context, input_to_forget_weights->dims->size, 2);
TF_LITE_ENSURE_EQ(context, input_to_forget_weights->dims->data[0], n_cell);
TF_LITE_ENSURE_EQ(context, input_to_forget_weights->dims->data[1], n_input);
- TfLiteTensor* input_to_cell_weights =
+ const TfLiteTensor* input_to_cell_weights =
GetInput(context, node, kInputToCellWeightsTensor);
TF_LITE_ENSURE_EQ(context, input_to_cell_weights->dims->size, 2);
TF_LITE_ENSURE_EQ(context, input_to_cell_weights->dims->data[0], n_cell);
n_output);
}
- TfLiteTensor* recurrent_to_forget_weights =
+ const TfLiteTensor* recurrent_to_forget_weights =
GetInput(context, node, kRecurrentToForgetWeightsTensor);
TF_LITE_ENSURE_EQ(context, recurrent_to_forget_weights->dims->size, 2);
TF_LITE_ENSURE_EQ(context, recurrent_to_forget_weights->dims->data[0],
TF_LITE_ENSURE_EQ(context, recurrent_to_forget_weights->dims->data[1],
n_output);
- TfLiteTensor* recurrent_to_cell_weights =
+ const TfLiteTensor* recurrent_to_cell_weights =
GetInput(context, node, kRecurrentToCellWeightsTensor);
TF_LITE_ENSURE_EQ(context, recurrent_to_cell_weights->dims->size, 2);
TF_LITE_ENSURE_EQ(context, recurrent_to_cell_weights->dims->data[0], n_cell);
TF_LITE_ENSURE_EQ(context, input_gate_bias->dims->data[0], n_cell);
}
- TfLiteTensor* forget_gate_bias =
+ const TfLiteTensor* forget_gate_bias =
GetInput(context, node, kForgetGateBiasTensor);
TF_LITE_ENSURE_EQ(context, forget_gate_bias->dims->size, 1);
TF_LITE_ENSURE_EQ(context, forget_gate_bias->dims->data[0], n_cell);
- TfLiteTensor* cell_bias = GetInput(context, node, kCellGateBiasTensor);
+ const TfLiteTensor* cell_bias = GetInput(context, node, kCellGateBiasTensor);
TF_LITE_ENSURE_EQ(context, cell_bias->dims->size, 1);
TF_LITE_ENSURE_EQ(context, cell_bias->dims->data[0], n_cell);
- TfLiteTensor* output_gate_bias =
+ const TfLiteTensor* output_gate_bias =
GetInput(context, node, kOutputGateBiasTensor);
TF_LITE_ENSURE_EQ(context, output_gate_bias->dims->size, 1);
TF_LITE_ENSURE_EQ(context, output_gate_bias->dims->data[0], n_cell);
// Inferring batch size, number of outputs and number of cells from the
// input tensors.
- TfLiteTensor* input = GetInput(context, node, kInputTensor);
+ const TfLiteTensor* input = GetInput(context, node, kInputTensor);
TF_LITE_ENSURE(context, input->dims->size > 1);
const int n_batch = input->dims->data[0];
const int n_input = input->dims->data[1];
- TfLiteTensor* input_to_output_weights =
+ const TfLiteTensor* input_to_output_weights =
GetInput(context, node, kInputToOutputWeightsTensor);
const int n_cell = input_to_output_weights->dims->data[0];
TF_LITE_ENSURE_EQ(context, input_to_output_weights->dims->size, 2);
TF_LITE_ENSURE_EQ(context, input_to_output_weights->dims->data[1], n_input);
- TfLiteTensor* recurrent_to_output_weights =
+ const TfLiteTensor* recurrent_to_output_weights =
GetInput(context, node, kRecurrentToOutputWeightsTensor);
TF_LITE_ENSURE_EQ(context, recurrent_to_output_weights->dims->size, 2);
TF_LITE_ENSURE_EQ(context, recurrent_to_output_weights->dims->data[0],
// The LSTM Op engine.
TfLiteStatus Eval(TfLiteContext* context, TfLiteNode* node) {
auto* params = reinterpret_cast<TfLiteLSTMParams*>(node->builtin_data);
- TfLiteTensor* input = GetInput(context, node, kInputTensor);
+ const TfLiteTensor* input = GetInput(context, node, kInputTensor);
TfLiteTensor* input_to_input_weights =
GetOptionalInputTensor(context, node, kInputToInputWeightsTensor);
- TfLiteTensor* input_to_forget_weights =
+ const TfLiteTensor* input_to_forget_weights =
GetInput(context, node, kInputToForgetWeightsTensor);
- TfLiteTensor* input_to_cell_weights =
+ const TfLiteTensor* input_to_cell_weights =
GetInput(context, node, kInputToCellWeightsTensor);
- TfLiteTensor* input_to_output_weights =
+ const TfLiteTensor* input_to_output_weights =
GetInput(context, node, kInputToOutputWeightsTensor);
TfLiteTensor* recurrent_to_input_weights =
GetOptionalInputTensor(context, node, kRecurrentToInputWeightsTensor);
- TfLiteTensor* recurrent_to_forget_weights =
+ const TfLiteTensor* recurrent_to_forget_weights =
GetInput(context, node, kRecurrentToForgetWeightsTensor);
- TfLiteTensor* recurrent_to_cell_weights =
+ const TfLiteTensor* recurrent_to_cell_weights =
GetInput(context, node, kRecurrentToCellWeightsTensor);
- TfLiteTensor* recurrent_to_output_weights =
+ const TfLiteTensor* recurrent_to_output_weights =
GetInput(context, node, kRecurrentToOutputWeightsTensor);
TfLiteTensor* cell_to_input_weights =
TfLiteTensor* input_gate_bias =
GetOptionalInputTensor(context, node, kInputGateBiasTensor);
- TfLiteTensor* forget_gate_bias =
+ const TfLiteTensor* forget_gate_bias =
GetInput(context, node, kForgetGateBiasTensor);
- TfLiteTensor* cell_bias = GetInput(context, node, kCellGateBiasTensor);
- TfLiteTensor* output_gate_bias =
+ const TfLiteTensor* cell_bias = GetInput(context, node, kCellGateBiasTensor);
+ const TfLiteTensor* output_gate_bias =
GetInput(context, node, kOutputGateBiasTensor);
TfLiteTensor* projection_weights =
input2 = GetInput(context, node, kInputTensor2);
output = GetOutput(context, node, kOutputTensor);
}
- TfLiteTensor* input1;
- TfLiteTensor* input2;
+ const TfLiteTensor* input1;
+ const TfLiteTensor* input2;
TfLiteTensor* output;
};
output = GetOutput(context, node, 0);
}
TfLiteMeanParams* params;
- TfLiteTensor* input;
- TfLiteTensor* axis;
+ const TfLiteTensor* input;
+ const TfLiteTensor* axis;
TfLiteTensor* output;
};
TF_LITE_ENSURE_EQ(context, NumInputs(node), 2);
TF_LITE_ENSURE_EQ(context, NumOutputs(node), 1);
- TfLiteTensor* inputWav = GetInput(context, node, kInputTensorWav);
- TfLiteTensor* inputRate = GetInput(context, node, kInputTensorRate);
+ const TfLiteTensor* inputWav = GetInput(context, node, kInputTensorWav);
+ const TfLiteTensor* inputRate = GetInput(context, node, kInputTensorRate);
TfLiteTensor* output = GetOutput(context, node, kOutputTensor);
TF_LITE_ENSURE_EQ(context, NumDimensions(inputWav), 3);
TfLiteStatus Eval(TfLiteContext* context, TfLiteNode* node) {
auto* params = reinterpret_cast<TfLiteMfccParams*>(node->user_data);
- TfLiteTensor* inputWav = GetInput(context, node, kInputTensorWav);
- TfLiteTensor* inputRate = GetInput(context, node, kInputTensorRate);
+ const TfLiteTensor* inputWav = GetInput(context, node, kInputTensorWav);
+ const TfLiteTensor* inputRate = GetInput(context, node, kInputTensorRate);
TfLiteTensor* output = GetOutput(context, node, kOutputTensor);
const int32 sample_rate = *GetTensorData<int>(inputRate);
TF_LITE_ENSURE_EQ(context, NumInputs(node), 2);
TF_LITE_ENSURE_EQ(context, NumOutputs(node), 1);
- TfLiteTensor* input1 = GetInput(context, node, kInputTensor1);
- TfLiteTensor* input2 = GetInput(context, node, kInputTensor2);
+ const TfLiteTensor* input1 = GetInput(context, node, kInputTensor1);
+ const TfLiteTensor* input2 = GetInput(context, node, kInputTensor2);
TfLiteTensor* output = GetOutput(context, node, kOutputTensor);
TF_LITE_ENSURE_EQ(context, input1->type, input2->type);
template <KernelType kernel_type>
void EvalFloat(TfLiteContext* context, TfLiteNode* node,
TfLiteMulParams* params, const OpData* data,
- TfLiteTensor* input1, TfLiteTensor* input2,
+ const TfLiteTensor* input1, const TfLiteTensor* input2,
TfLiteTensor* output) {
float output_activation_min, output_activation_max;
CalculateActivationRangeFloat(params->activation, &output_activation_min,
template <KernelType kernel_type>
void EvalQuantized(TfLiteContext* context, TfLiteNode* node,
TfLiteMulParams* params, const OpData* data,
- TfLiteTensor* input1, TfLiteTensor* input2,
+ const TfLiteTensor* input1, const TfLiteTensor* input2,
TfLiteTensor* output) {
auto input1_offset = -input1->params.zero_point;
auto input2_offset = -input2->params.zero_point;
auto* params = reinterpret_cast<TfLiteMulParams*>(node->builtin_data);
OpData* data = reinterpret_cast<OpData*>(node->user_data);
- TfLiteTensor* input1 = GetInput(context, node, kInputTensor1);
- TfLiteTensor* input2 = GetInput(context, node, kInputTensor2);
+ const TfLiteTensor* input1 = GetInput(context, node, kInputTensor1);
+ const TfLiteTensor* input2 = GetInput(context, node, kInputTensor2);
TfLiteTensor* output = GetOutput(context, node, kOutputTensor);
if (output->type == kTfLiteFloat32) {
TfLiteStatus Prepare(TfLiteContext* context, TfLiteNode* node) {
TF_LITE_ENSURE_EQ(context, NumInputs(node), 1);
TF_LITE_ENSURE_EQ(context, NumOutputs(node), 1);
- TfLiteTensor* input = GetInput(context, node, kInputTensor);
+ const TfLiteTensor* input = GetInput(context, node, kInputTensor);
TfLiteTensor* output = GetOutput(context, node, kOutputTensor);
output->type = input->type;
}
TfLiteStatus Eval(TfLiteContext* context, TfLiteNode* node) {
- TfLiteTensor* input = GetInput(context, node, kInputTensor);
+ const TfLiteTensor* input = GetInput(context, node, kInputTensor);
TfLiteTensor* output = GetOutput(context, node, kOutputTensor);
const int num_elements = NumElements(input);
switch (input->type) {
dims = NumDimensions(input);
}
TfLiteTensor* constant_values;
- TfLiteTensor* input;
- TfLiteTensor* paddings;
+ const TfLiteTensor* input;
+ const TfLiteTensor* paddings;
TfLiteTensor* output;
int dims;
};
TF_LITE_ENSURE_EQ(context, NumInputs(node), 1);
TF_LITE_ENSURE_EQ(context, NumOutputs(node), 1);
TfLiteTensor* output = GetOutput(context, node, 0);
- TfLiteTensor* input = GetInput(context, node, 0);
+ const TfLiteTensor* input = GetInput(context, node, 0);
TF_LITE_ENSURE_EQ(context, NumDimensions(input), 4);
TF_LITE_ENSURE_EQ(context, input->type, output->type);
template <KernelType kernel_type>
void AverageEvalFloat(TfLiteContext* context, TfLiteNode* node,
TfLitePoolParams* params, OpData* data,
- TfLiteTensor* input, TfLiteTensor* output) {
+ const TfLiteTensor* input, TfLiteTensor* output) {
float activation_min, activation_max;
CalculateActivationRangeFloat(params->activation, &activation_min,
&activation_max);
template <KernelType kernel_type>
void AverageEvalQuantized(TfLiteContext* context, TfLiteNode* node,
TfLitePoolParams* params, OpData* data,
- TfLiteTensor* input, TfLiteTensor* output) {
+ const TfLiteTensor* input, TfLiteTensor* output) {
int32_t activation_min;
int32_t activation_max;
CalculateActivationRangeUint8(params->activation, output, &activation_min,
template <KernelType kernel_type>
void MaxEvalFloat(TfLiteContext* context, TfLiteNode* node,
- TfLitePoolParams* params, OpData* data, TfLiteTensor* input,
- TfLiteTensor* output) {
+ TfLitePoolParams* params, OpData* data,
+ const TfLiteTensor* input, TfLiteTensor* output) {
float activation_min, activation_max;
CalculateActivationRangeFloat(params->activation, &activation_min,
&activation_max);
template <KernelType kernel_type>
void MaxEvalQuantized(TfLiteContext* context, TfLiteNode* node,
TfLitePoolParams* params, OpData* data,
- TfLiteTensor* input, TfLiteTensor* output) {
+ const TfLiteTensor* input, TfLiteTensor* output) {
int32_t activation_min;
int32_t activation_max;
CalculateActivationRangeUint8(params->activation, output, &activation_min,
template <KernelType kernel_type>
void L2EvalFloat(TfLiteContext* context, TfLiteNode* node,
- TfLitePoolParams* params, OpData* data, TfLiteTensor* input,
- TfLiteTensor* output) {
+ TfLitePoolParams* params, OpData* data,
+ const TfLiteTensor* input, TfLiteTensor* output) {
float activation_min, activation_max;
CalculateActivationRangeFloat(params->activation, &activation_min,
&activation_max);
OpData* data = reinterpret_cast<OpData*>(node->user_data);
TfLiteTensor* output = GetOutput(context, node, 0);
- TfLiteTensor* input = GetInput(context, node, 0);
+ const TfLiteTensor* input = GetInput(context, node, 0);
switch (input->type) { // Already know in/out types are same.
case kTfLiteFloat32:
AverageEvalFloat<kernel_type>(context, node, params, data, input, output);
OpData* data = reinterpret_cast<OpData*>(node->user_data);
TfLiteTensor* output = GetOutput(context, node, 0);
- TfLiteTensor* input = GetInput(context, node, 0);
+ const TfLiteTensor* input = GetInput(context, node, 0);
switch (input->type) { // Already know in/out types are same.
case kTfLiteFloat32:
MaxEvalFloat<kernel_type>(context, node, params, data, input, output);
OpData* data = reinterpret_cast<OpData*>(node->user_data);
TfLiteTensor* output = GetOutput(context, node, 0);
- TfLiteTensor* input = GetInput(context, node, 0);
+ const TfLiteTensor* input = GetInput(context, node, 0);
switch (input->type) { // Already know in/out types are same.
case kTfLiteFloat32:
L2EvalFloat<kernel_type>(context, node, params, data, input, output);
TF_LITE_ENSURE(context, NumInputs(node) == 1 || NumInputs(node) == 2);
TF_LITE_ENSURE_EQ(context, NumOutputs(node), 1);
- TfLiteTensor* input = GetInput(context, node, kInputTensor);
+ const TfLiteTensor* input = GetInput(context, node, kInputTensor);
TfLiteTensor* output = GetOutput(context, node, kOutputTensor);
// Tensorflow's Reshape allows one of the shape components to have the
}
TfLiteStatus Eval(TfLiteContext* context, TfLiteNode* node) {
- TfLiteTensor* input = GetInput(context, node, kInputTensor);
+ const TfLiteTensor* input = GetInput(context, node, kInputTensor);
TfLiteTensor* output = GetOutput(context, node, kOutputTensor);
memcpy(output->data.raw, input->data.raw, input->bytes);
constexpr int kSizeTensor = 1;
constexpr int kOutputTensor = 0;
-TfLiteStatus ResizeOutputTensor(TfLiteContext* context, TfLiteTensor* input,
- TfLiteTensor* size, TfLiteTensor* output) {
+TfLiteStatus ResizeOutputTensor(TfLiteContext* context,
+ const TfLiteTensor* input,
+ const TfLiteTensor* size,
+ TfLiteTensor* output) {
TfLiteIntArray* output_size = TfLiteIntArrayCreate(4);
output_size->data[0] = input->dims->data[0];
const int32* size_data = GetTensorData<int32>(size);
TF_LITE_ENSURE_EQ(context, NumInputs(node), 2);
TF_LITE_ENSURE_EQ(context, NumOutputs(node), 1);
- TfLiteTensor* input = GetInput(context, node, kInputTensor);
- TfLiteTensor* size = GetInput(context, node, kSizeTensor);
+ const TfLiteTensor* input = GetInput(context, node, kInputTensor);
+ const TfLiteTensor* size = GetInput(context, node, kSizeTensor);
TfLiteTensor* output = GetOutput(context, node, kOutputTensor);
// TODO(ahentz): Our current implementations rely on the inputs being 4D.
auto* params =
reinterpret_cast<TfLiteResizeBilinearParams*>(node->builtin_data);
- TfLiteTensor* input = GetInput(context, node, kInputTensor);
+ const TfLiteTensor* input = GetInput(context, node, kInputTensor);
TfLiteTensor* output = GetOutput(context, node, kOutputTensor);
- TfLiteTensor* size = GetInput(context, node, kSizeTensor);
+ const TfLiteTensor* size = GetInput(context, node, kSizeTensor);
if (IsDynamicTensor(output)) {
TF_LITE_ENSURE_OK(context,
TF_LITE_ENSURE_EQ(context, NumInputs(node), 3);
TF_LITE_ENSURE_EQ(context, NumOutputs(node), 1);
- TfLiteTensor* input_condition =
+ const TfLiteTensor* input_condition =
GetInput(context, node, kInputTensorCondition);
- TfLiteTensor* input_x = GetInput(context, node, kInputTensorX);
- TfLiteTensor* input_y = GetInput(context, node, kInputTensorY);
+ const TfLiteTensor* input_x = GetInput(context, node, kInputTensorX);
+ const TfLiteTensor* input_y = GetInput(context, node, kInputTensorY);
TfLiteTensor* output = GetOutput(context, node, kOutputTensor);
// Input must be bool.
}
TfLiteStatus SelectEval(TfLiteContext* context, TfLiteNode* node) {
- TfLiteTensor* input_condition =
+ const TfLiteTensor* input_condition =
GetInput(context, node, kInputTensorCondition);
- TfLiteTensor* input_x = GetInput(context, node, kInputTensorX);
- TfLiteTensor* input_y = GetInput(context, node, kInputTensorY);
+ const TfLiteTensor* input_x = GetInput(context, node, kInputTensorX);
+ const TfLiteTensor* input_y = GetInput(context, node, kInputTensorY);
TfLiteTensor* output = GetOutput(context, node, kOutputTensor);
bool is_rank_one = !HaveSameShapes(input_condition, input_x);
template <typename T>
TfLiteStatus CalculateOutputShapeVector(
- TfLiteContext* context, TfLiteTensor* input, TfLiteTensor* begin,
- TfLiteTensor* size, std::vector<int64_t>* output_shape_vector) {
+ TfLiteContext* context, const TfLiteTensor* input,
+ const TfLiteTensor* begin, const TfLiteTensor* size,
+ std::vector<int64_t>* output_shape_vector) {
for (int idx = 0; idx < NumDimensions(input); ++idx) {
T size_value = GetTensorData<T>(size)[idx];
if (size_value < 0) {
}
template <typename T>
-void GetBeginAndSizeVectors(int dimensions, TfLiteTensor* begin,
- TfLiteTensor* size, std::vector<int>* begins,
+void GetBeginAndSizeVectors(int dimensions, const TfLiteTensor* begin,
+ const TfLiteTensor* size, std::vector<int>* begins,
std::vector<int>* sizes) {
for (int idx = dimensions - 1; idx >= 0; --idx) {
begins->push_back(GetTensorData<T>(begin)[idx]);
}
}
-TfLiteStatus ResizeOutputShape(TfLiteContext* context, TfLiteTensor* input,
- TfLiteTensor* begin, TfLiteTensor* size,
- TfLiteTensor* output) {
+TfLiteStatus ResizeOutputShape(TfLiteContext* context,
+ const TfLiteTensor* input,
+ const TfLiteTensor* begin,
+ const TfLiteTensor* size, TfLiteTensor* output) {
std::vector<int64_t> output_shape_vector;
if (begin->type == kTfLiteInt32) {
TF_LITE_ENSURE_EQ(context, NumInputs(node), 3);
TF_LITE_ENSURE_EQ(context, NumOutputs(node), 1);
- TfLiteTensor* input = GetInput(context, node, kInputTensor);
- TfLiteTensor* begin = GetInput(context, node, kBeginTensor);
- TfLiteTensor* size = GetInput(context, node, kSizeTensor);
+ const TfLiteTensor* input = GetInput(context, node, kInputTensor);
+ const TfLiteTensor* begin = GetInput(context, node, kBeginTensor);
+ const TfLiteTensor* size = GetInput(context, node, kSizeTensor);
TfLiteTensor* output = GetOutput(context, node, kOutputTensor);
// Ensure validity of input tensor and its dimension.
}
TfLiteStatus Eval(TfLiteContext* context, TfLiteNode* node) {
- TfLiteTensor* input = GetInput(context, node, kInputTensor);
- TfLiteTensor* begin = GetInput(context, node, kBeginTensor);
- TfLiteTensor* size = GetInput(context, node, kSizeTensor);
+ const TfLiteTensor* input = GetInput(context, node, kInputTensor);
+ const TfLiteTensor* begin = GetInput(context, node, kBeginTensor);
+ const TfLiteTensor* size = GetInput(context, node, kSizeTensor);
TfLiteTensor* output = GetOutput(context, node, kOutputTensor);
if (IsDynamicTensor(output)) {
paddings = GetInput(context, node, 2);
output = GetOutput(context, node, 0);
}
- TfLiteTensor* input;
- TfLiteTensor* block_shape;
- TfLiteTensor* paddings;
+ const TfLiteTensor* input;
+ const TfLiteTensor* block_shape;
+ const TfLiteTensor* paddings;
TfLiteTensor* output;
};
TF_LITE_ENSURE_EQ(context, NumInputs(node), 1);
TF_LITE_ENSURE_EQ(context, NumOutputs(node), 1);
- TfLiteTensor* input = GetInput(context, node, kInputTensor);
+ const TfLiteTensor* input = GetInput(context, node, kInputTensor);
TfLiteTensor* output = GetOutput(context, node, kOutputTensor);
TF_LITE_ENSURE_EQ(context, NumDimensions(input), 4);
auto* params =
reinterpret_cast<TfLiteSpaceToDepthParams*>(node->builtin_data);
- TfLiteTensor* input = GetInput(context, node, kInputTensor);
+ const TfLiteTensor* input = GetInput(context, node, kInputTensor);
TfLiteTensor* output = GetOutput(context, node, kOutputTensor);
#define TF_LITE_SPACE_TO_DEPTH(type, scalar) \
input = GetInput(context, node, 1);
}
TfLiteSplitParams* params;
- TfLiteTensor* axis;
- TfLiteTensor* input;
+ const TfLiteTensor* axis;
+ const TfLiteTensor* input;
};
TfLiteStatus UseDynamicOutputTensors(TfLiteContext* context, TfLiteNode* node) {
}
TfLiteStatus ResizeOutputTensors(TfLiteContext* context, TfLiteNode* node,
- TfLiteTensor* axis, TfLiteTensor* input,
- int num_splits) {
+ const TfLiteTensor* axis,
+ const TfLiteTensor* input, int num_splits) {
int axis_value = GetTensorData<int>(axis)[0];
if (axis_value < 0) {
axis_value += NumDimensions(input);
namespace squeeze {
struct SqueezeContext {
- SqueezeContext(TfLiteContext* context, TfLiteNode* node) {
- params = reinterpret_cast<TfLiteSqueezeParams*>(node->builtin_data);
- input = GetInput(context, node, 0);
- output = GetOutput(context, node, 0);
- }
+ SqueezeContext(TfLiteContext* context, TfLiteNode* node)
+ : params(reinterpret_cast<TfLiteSqueezeParams*>(node->builtin_data)),
+ input(GetInput(context, node, 0)),
+ output(GetOutput(context, node, 0)) {}
TfLiteSqueezeParams* params;
- TfLiteTensor* input;
+ const TfLiteTensor* const input;
TfLiteTensor* output;
};
dims = NumDimensions(input);
}
const TfLiteStridedSliceParams* params;
- TfLiteTensor* input;
- TfLiteTensor* begin;
- TfLiteTensor* end;
- TfLiteTensor* strides;
+ const TfLiteTensor* input;
+ const TfLiteTensor* begin;
+ const TfLiteTensor* end;
+ const TfLiteTensor* strides;
TfLiteTensor* output;
int dims;
};
TF_LITE_ENSURE_EQ(context, NumInputs(node), 2);
TF_LITE_ENSURE_EQ(context, NumOutputs(node), 1);
- TfLiteTensor* input1 = GetInput(context, node, kInputTensor1);
- TfLiteTensor* input2 = GetInput(context, node, kInputTensor2);
+ const TfLiteTensor* input1 = GetInput(context, node, kInputTensor1);
+ const TfLiteTensor* input2 = GetInput(context, node, kInputTensor2);
TfLiteTensor* output = GetOutput(context, node, kOutputTensor);
TF_LITE_ENSURE_EQ(context, input1->type, input2->type);
template <KernelType kernel_type>
void EvalFloat(TfLiteContext* context, TfLiteNode* node,
TfLiteSubParams* params, const OpData* data,
- TfLiteTensor* input1, TfLiteTensor* input2,
+ const TfLiteTensor* input1, const TfLiteTensor* input2,
TfLiteTensor* output) {
float output_activation_min, output_activation_max;
CalculateActivationRangeFloat(params->activation, &output_activation_min,
template <KernelType kernel_type>
void EvalQuantized(TfLiteContext* context, TfLiteNode* node,
TfLiteSubParams* params, const OpData* data,
- TfLiteTensor* input1, TfLiteTensor* input2,
+ const TfLiteTensor* input1, const TfLiteTensor* input2,
TfLiteTensor* output) {
auto input1_offset = -input1->params.zero_point;
auto input2_offset = -input2->params.zero_point;
auto* params = reinterpret_cast<TfLiteSubParams*>(node->builtin_data);
OpData* data = reinterpret_cast<OpData*>(node->user_data);
- TfLiteTensor* input1 = GetInput(context, node, kInputTensor1);
- TfLiteTensor* input2 = GetInput(context, node, kInputTensor2);
+ const TfLiteTensor* input1 = GetInput(context, node, kInputTensor1);
+ const TfLiteTensor* input2 = GetInput(context, node, kInputTensor2);
TfLiteTensor* output = GetOutput(context, node, kOutputTensor);
if (output->type == kTfLiteFloat32) {
TF_LITE_ENSURE_EQ(context, node->outputs->size, 2);
TfLiteTensor* input = &context->tensors[node->inputs->data[kInputTensor]];
- TfLiteTensor* weights_feature =
+ const TfLiteTensor* weights_feature =
GetInput(context, node, kWeightsFeatureTensor);
- TfLiteTensor* weights_time = GetInput(context, node, kWeightsTimeTensor);
+ const TfLiteTensor* weights_time =
+ GetInput(context, node, kWeightsTimeTensor);
// Check all the parameters of tensor match within themselves and match the
// input configuration.
TfLiteStatus Eval(TfLiteContext* context, TfLiteNode* node) {
auto* params = reinterpret_cast<TfLiteSVDFParams*>(node->builtin_data);
- TfLiteTensor* input = GetInput(context, node, kInputTensor);
- TfLiteTensor* weights_feature =
+ const TfLiteTensor* input = GetInput(context, node, kInputTensor);
+ const TfLiteTensor* weights_feature =
GetInput(context, node, kWeightsFeatureTensor);
- TfLiteTensor* weights_time = GetInput(context, node, kWeightsTimeTensor);
+ const TfLiteTensor* weights_time =
+ GetInput(context, node, kWeightsTimeTensor);
TfLiteTensor* state = GetOutput(context, node, kStateTensor);
TfLiteTensor* output = GetOutput(context, node, kOutputTensor);
namespace {
TfLiteStatus ResizeOutput(TfLiteContext* context, TfLiteNode* node) {
- TfLiteTensor* top_k = GetInput(context, node, kInputTopK);
+ const TfLiteTensor* top_k = GetInput(context, node, kInputTopK);
// INT32 number of top results is supported.
TF_LITE_ENSURE_EQ(context, top_k->type, kTfLiteInt32);
// Check that the tensor contains only one value.
TF_LITE_ENSURE_EQ(context, NumElements(top_k), 1);
const int32 k = top_k->data.i32[0];
- TfLiteTensor* input = GetInput(context, node, kInputTensor);
+ const TfLiteTensor* input = GetInput(context, node, kInputTensor);
const int num_dimensions = NumDimensions(input);
// Check that input has one or more dimensions.
TF_LITE_ENSURE_MSG(context, input->dims->size >= 1,
TF_LITE_ENSURE_EQ(context, NumInputs(node), 2);
TF_LITE_ENSURE_EQ(context, NumOutputs(node), 2);
- TfLiteTensor* input = GetInput(context, node, kInputTensor);
+ const TfLiteTensor* input = GetInput(context, node, kInputTensor);
TfLiteTensor* output_values = GetOutput(context, node, kOutputValues);
TF_LITE_ENSURE_EQ(context, input->type, output_values->type);
- TfLiteTensor* top_k = GetInput(context, node, kInputTopK);
+ const TfLiteTensor* top_k = GetInput(context, node, kInputTopK);
TF_LITE_ENSURE_EQ(context, top_k->type, kTfLiteInt32);
// Set output dynamic if the input is not const.
if (IsDynamicTensor(output_values)) {
TF_LITE_ENSURE_OK(context, ResizeOutput(context, node));
}
- TfLiteTensor* top_k = GetInput(context, node, kInputTopK);
+ const TfLiteTensor* top_k = GetInput(context, node, kInputTopK);
const int32 k = top_k->data.i32[0];
// The tensor can have more than 2 dimensions or even be a vector, the code
// anyway calls the internal dimension as row;
- TfLiteTensor* input = GetInput(context, node, kInputTensor);
+ const TfLiteTensor* input = GetInput(context, node, kInputTensor);
const int32 row_size = input->dims->data[input->dims->size - 1];
int32 num_rows = 1;
for (int i = 0; i < input->dims->size - 1; ++i) {
perm = GetInput(context, node, 1);
output = GetOutput(context, node, 0);
}
- TfLiteTensor* input;
- TfLiteTensor* perm;
+ const TfLiteTensor* input;
+ const TfLiteTensor* perm;
TfLiteTensor* output;
};
TF_LITE_ENSURE_EQ(context, input_to_input_weights->dims->data[1], n_input);
}
- TfLiteTensor* input_to_forget_weights =
+ const TfLiteTensor* input_to_forget_weights =
GetInput(context, node, kInputToForgetWeightsTensor);
TF_LITE_ENSURE_EQ(context, input_to_forget_weights->dims->size, 2);
TF_LITE_ENSURE_EQ(context, input_to_forget_weights->dims->data[0], n_cell);
TF_LITE_ENSURE_EQ(context, input_to_forget_weights->dims->data[1], n_input);
- TfLiteTensor* input_to_cell_weights =
+ const TfLiteTensor* input_to_cell_weights =
GetInput(context, node, kInputToCellWeightsTensor);
TF_LITE_ENSURE_EQ(context, input_to_cell_weights->dims->size, 2);
TF_LITE_ENSURE_EQ(context, input_to_cell_weights->dims->data[0], n_cell);
n_output);
}
- TfLiteTensor* recurrent_to_forget_weights =
+ const TfLiteTensor* recurrent_to_forget_weights =
GetInput(context, node, kRecurrentToForgetWeightsTensor);
TF_LITE_ENSURE_EQ(context, recurrent_to_forget_weights->dims->size, 2);
TF_LITE_ENSURE_EQ(context, recurrent_to_forget_weights->dims->data[0],
TF_LITE_ENSURE_EQ(context, recurrent_to_forget_weights->dims->data[1],
n_output);
- TfLiteTensor* recurrent_to_cell_weights =
+ const TfLiteTensor* recurrent_to_cell_weights =
GetInput(context, node, kRecurrentToCellWeightsTensor);
TF_LITE_ENSURE_EQ(context, recurrent_to_cell_weights->dims->size, 2);
TF_LITE_ENSURE_EQ(context, recurrent_to_cell_weights->dims->data[0], n_cell);
TF_LITE_ENSURE_EQ(context, input_gate_bias->dims->data[0], n_cell);
}
- TfLiteTensor* forget_gate_bias =
+ const TfLiteTensor* forget_gate_bias =
GetInput(context, node, kForgetGateBiasTensor);
TF_LITE_ENSURE_EQ(context, forget_gate_bias->dims->size, 1);
TF_LITE_ENSURE_EQ(context, forget_gate_bias->dims->data[0], n_cell);
- TfLiteTensor* cell_bias = GetInput(context, node, kCellGateBiasTensor);
+ const TfLiteTensor* cell_bias = GetInput(context, node, kCellGateBiasTensor);
TF_LITE_ENSURE_EQ(context, cell_bias->dims->size, 1);
TF_LITE_ENSURE_EQ(context, cell_bias->dims->data[0], n_cell);
- TfLiteTensor* output_gate_bias =
+ const TfLiteTensor* output_gate_bias =
GetInput(context, node, kOutputGateBiasTensor);
TF_LITE_ENSURE_EQ(context, output_gate_bias->dims->size, 1);
TF_LITE_ENSURE_EQ(context, output_gate_bias->dims->data[0], n_cell);
// Inferring batch size, number of outputs and sequence length and
// number of cells from the input tensors.
- TfLiteTensor* input = GetInput(context, node, kInputTensor);
+ const TfLiteTensor* input = GetInput(context, node, kInputTensor);
TF_LITE_ENSURE(context, input->dims->size > 1);
const int max_time = input->dims->data[0];
const int n_batch = input->dims->data[1];
const int n_input = input->dims->data[2];
- TfLiteTensor* input_to_output_weights =
+ const TfLiteTensor* input_to_output_weights =
GetInput(context, node, kInputToOutputWeightsTensor);
const int n_cell = input_to_output_weights->dims->data[0];
TF_LITE_ENSURE_EQ(context, input_to_output_weights->dims->size, 2);
TF_LITE_ENSURE_EQ(context, input_to_output_weights->dims->data[1], n_input);
- TfLiteTensor* recurrent_to_output_weights =
+ const TfLiteTensor* recurrent_to_output_weights =
GetInput(context, node, kRecurrentToOutputWeightsTensor);
TF_LITE_ENSURE_EQ(context, recurrent_to_output_weights->dims->size, 2);
TF_LITE_ENSURE_EQ(context, recurrent_to_output_weights->dims->data[0],
// The LSTM Op engine.
TfLiteStatus Eval(TfLiteContext* context, TfLiteNode* node) {
auto* params = reinterpret_cast<TfLiteLSTMParams*>(node->builtin_data);
- TfLiteTensor* input = GetInput(context, node, kInputTensor);
+ const TfLiteTensor* input = GetInput(context, node, kInputTensor);
TfLiteTensor* input_to_input_weights =
GetOptionalInputTensor(context, node, kInputToInputWeightsTensor);
- TfLiteTensor* input_to_forget_weights =
+ const TfLiteTensor* input_to_forget_weights =
GetInput(context, node, kInputToForgetWeightsTensor);
- TfLiteTensor* input_to_cell_weights =
+ const TfLiteTensor* input_to_cell_weights =
GetInput(context, node, kInputToCellWeightsTensor);
- TfLiteTensor* input_to_output_weights =
+ const TfLiteTensor* input_to_output_weights =
GetInput(context, node, kInputToOutputWeightsTensor);
TfLiteTensor* recurrent_to_input_weights =
GetOptionalInputTensor(context, node, kRecurrentToInputWeightsTensor);
- TfLiteTensor* recurrent_to_forget_weights =
+ const TfLiteTensor* recurrent_to_forget_weights =
GetInput(context, node, kRecurrentToForgetWeightsTensor);
- TfLiteTensor* recurrent_to_cell_weights =
+ const TfLiteTensor* recurrent_to_cell_weights =
GetInput(context, node, kRecurrentToCellWeightsTensor);
- TfLiteTensor* recurrent_to_output_weights =
+ const TfLiteTensor* recurrent_to_output_weights =
GetInput(context, node, kRecurrentToOutputWeightsTensor);
TfLiteTensor* cell_to_input_weights =
TfLiteTensor* input_gate_bias =
GetOptionalInputTensor(context, node, kInputGateBiasTensor);
- TfLiteTensor* forget_gate_bias =
+ const TfLiteTensor* forget_gate_bias =
GetInput(context, node, kForgetGateBiasTensor);
- TfLiteTensor* cell_bias = GetInput(context, node, kCellGateBiasTensor);
- TfLiteTensor* output_gate_bias =
+ const TfLiteTensor* cell_bias = GetInput(context, node, kCellGateBiasTensor);
+ const TfLiteTensor* output_gate_bias =
GetInput(context, node, kOutputGateBiasTensor);
TfLiteTensor* projection_weights =
TF_LITE_ENSURE_EQ(context, node->inputs->size, 4);
TF_LITE_ENSURE_EQ(context, node->outputs->size, 2);
- TfLiteTensor* input = GetInput(context, node, kInputTensor);
- TfLiteTensor* input_weights = GetInput(context, node, kWeightsTensor);
- TfLiteTensor* recurrent_weights =
+ const TfLiteTensor* input = GetInput(context, node, kInputTensor);
+ const TfLiteTensor* input_weights = GetInput(context, node, kWeightsTensor);
+ const TfLiteTensor* recurrent_weights =
GetInput(context, node, kRecurrentWeightsTensor);
- TfLiteTensor* bias = GetInput(context, node, kBiasTensor);
+ const TfLiteTensor* bias = GetInput(context, node, kBiasTensor);
// Check all the parameters of tensor match within themselves and match the
// input configuration.
TfLiteStatus Eval(TfLiteContext* context, TfLiteNode* node) {
auto* params = reinterpret_cast<TfLiteSequenceRNNParams*>(node->builtin_data);
- TfLiteTensor* input = GetInput(context, node, kInputTensor);
- TfLiteTensor* input_weights = GetInput(context, node, kWeightsTensor);
- TfLiteTensor* recurrent_weights =
+ const TfLiteTensor* input = GetInput(context, node, kInputTensor);
+ const TfLiteTensor* input_weights = GetInput(context, node, kWeightsTensor);
+ const TfLiteTensor* recurrent_weights =
GetInput(context, node, kRecurrentWeightsTensor);
- TfLiteTensor* bias = GetInput(context, node, kBiasTensor);
+ const TfLiteTensor* bias = GetInput(context, node, kBiasTensor);
TfLiteTensor* hidden_state = GetOutput(context, node, kHiddenStateTensor);
TfLiteTensor* output = GetOutput(context, node, kOutputTensor);
TfLiteStatus Prepare(TfLiteContext* context, TfLiteNode* node) {
TfLiteIntArray* outputSize1 = TfLiteIntArrayCreate(1);
TfLiteIntArray* outputSize2 = TfLiteIntArrayCreate(1);
- TfLiteTensor* input = GetInput(context, node, 0);
+ const TfLiteTensor* input = GetInput(context, node, 0);
int dim = input->dims->data[0];
if (dim == 0) {
// TFLite non-string output should have size greater than 0.
}
TfLiteStatus Eval(TfLiteContext* context, TfLiteNode* node) {
- TfLiteTensor* input = GetInput(context, node, 0);
+ const TfLiteTensor* input = GetInput(context, node, 0);
int num_strings = tflite::GetStringCount(input);
TfLiteTensor* label = GetOutput(context, node, 0);
TfLiteTensor* weight = GetOutput(context, node, 1);