| 56 | } |
| 57 | |
| 58 | TfLiteStatus Prepare(TfLiteContext* context, TfLiteNode* node) { |
| 59 | TF_LITE_ENSURE_EQ(context, NumInputs(node), 3); |
| 60 | TF_LITE_ENSURE_EQ(context, NumOutputs(node), 2); |
| 61 | |
| 62 | const TfLiteTensor* lookup = GetInput(context, node, 0); |
| 63 | TF_LITE_ENSURE_EQ(context, NumDimensions(lookup), 1); |
| 64 | TF_LITE_ENSURE_EQ(context, lookup->type, kTfLiteInt32); |
| 65 | |
| 66 | const TfLiteTensor* key = GetInput(context, node, 1); |
| 67 | TF_LITE_ENSURE_EQ(context, NumDimensions(key), 1); |
| 68 | TF_LITE_ENSURE_EQ(context, key->type, kTfLiteInt32); |
| 69 | |
| 70 | const TfLiteTensor* value = GetInput(context, node, 2); |
| 71 | TF_LITE_ENSURE(context, NumDimensions(value) >= 1); |
| 72 | TF_LITE_ENSURE_EQ(context, SizeOfDimension(key, 0), |
| 73 | SizeOfDimension(value, 0)); |
| 74 | if (value->type == kTfLiteString) { |
| 75 | TF_LITE_ENSURE_EQ(context, NumDimensions(value), 1); |
| 76 | } |
| 77 | |
| 78 | TfLiteTensor* hits = GetOutput(context, node, 1); |
| 79 | TF_LITE_ENSURE_EQ(context, hits->type, kTfLiteUInt8); |
| 80 | TfLiteIntArray* hitSize = TfLiteIntArrayCreate(1); |
| 81 | hitSize->data[0] = SizeOfDimension(lookup, 0); |
| 82 | |
| 83 | TfLiteTensor* output = GetOutput(context, node, 0); |
| 84 | TF_LITE_ENSURE_EQ(context, value->type, output->type); |
| 85 | |
| 86 | TfLiteStatus status = kTfLiteOk; |
| 87 | if (output->type != kTfLiteString) { |
| 88 | TfLiteIntArray* outputSize = TfLiteIntArrayCreate(NumDimensions(value)); |
| 89 | outputSize->data[0] = SizeOfDimension(lookup, 0); |
| 90 | for (int i = 1; i < NumDimensions(value); i++) { |
| 91 | outputSize->data[i] = SizeOfDimension(value, i); |
| 92 | } |
| 93 | status = context->ResizeTensor(context, output, outputSize); |
| 94 | } |
| 95 | if (context->ResizeTensor(context, hits, hitSize) == kTfLiteError) { |
| 96 | status = kTfLiteError; |
| 97 | } |
| 98 | return status; |
| 99 | } |
| 100 | |
| 101 | TfLiteStatus Eval(TfLiteContext* context, TfLiteNode* node) { |
| 102 | TfLiteTensor* output = GetOutput(context, node, 0); |
nothing calls this directly
no test coverage detected