| 28 | constexpr int kOutputTensor = 0; |
| 29 | |
| 30 | TfLiteStatus ComparisonPrepare(TfLiteContext* context, TfLiteNode* node) { |
| 31 | TF_LITE_ENSURE_EQ(context, NumInputs(node), 2); |
| 32 | TF_LITE_ENSURE_EQ(context, NumOutputs(node), 1); |
| 33 | |
| 34 | const TfLiteTensor* input1 = GetInput(context, node, kInputTensor1); |
| 35 | const TfLiteTensor* input2 = GetInput(context, node, kInputTensor2); |
| 36 | TfLiteTensor* output = GetOutput(context, node, kOutputTensor); |
| 37 | |
| 38 | // Don't support string. |
| 39 | TF_LITE_ENSURE(context, input1->type != kTfLiteString); |
| 40 | // Currently only support tensors have the same type. |
| 41 | TF_LITE_ENSURE_TYPES_EQ(context, input1->type, input2->type); |
| 42 | output->type = kTfLiteBool; |
| 43 | |
| 44 | bool requires_broadcast = !HaveSameShapes(input1, input2); |
| 45 | |
| 46 | TfLiteIntArray* output_size = nullptr; |
| 47 | if (requires_broadcast) { |
| 48 | TF_LITE_ENSURE_OK(context, CalculateShapeForBroadcast( |
| 49 | context, input1, input2, &output_size)); |
| 50 | } else { |
| 51 | output_size = TfLiteIntArrayCopy(input1->dims); |
| 52 | } |
| 53 | |
| 54 | return context->ResizeTensor(context, output, output_size); |
| 55 | } |
| 56 | |
| 57 | // TODO(ruic): optimize macros below to using template functions. |
| 58 | #define TF_LITE_QUANTIZE_COMPARISON(opname) \ |
nothing calls this directly
no test coverage detected