| 66 | } |
| 67 | |
| 68 | bool ShouldStepInRecursion(const TfLiteSkipGramParams* params, |
| 69 | const std::vector<int>& stack, int stack_idx, |
| 70 | int num_words) { |
| 71 | // If current stack size and next word enumeration are within valid range. |
| 72 | if (stack_idx < params->ngram_size && stack[stack_idx] + 1 < num_words) { |
| 73 | // If this stack is empty, step in for first word enumeration. |
| 74 | if (stack_idx == 0) { |
| 75 | return true; |
| 76 | } |
| 77 | // If next word enumeration are within the range of max_skip_size. |
| 78 | // NOTE: equivalent to |
| 79 | // next_word_idx = stack[stack_idx] + 1 |
| 80 | // next_word_idx - stack[stack_idx-1] <= max_skip_size + 1 |
| 81 | if (stack[stack_idx] - stack[stack_idx - 1] <= params->max_skip_size) { |
| 82 | return true; |
| 83 | } |
| 84 | } |
| 85 | return false; |
| 86 | } |
| 87 | |
| 88 | TfLiteStatus Eval(TfLiteContext* context, TfLiteNode* node) { |
| 89 | auto* params = reinterpret_cast<TfLiteSkipGramParams*>(node->builtin_data); |