| 80 | } |
| 81 | |
| 82 | inline TfLiteIntArray* GetOutputShapeFromParam(TfLiteContext* context, |
| 83 | TfLiteNode* node) { |
| 84 | auto* params = reinterpret_cast<TfLiteReshapeParams*>(node->builtin_data); |
| 85 | |
| 86 | // The function is returned above this line if the shape tensor is usable. |
| 87 | // Now fallback to the shape parameter in `TfLiteReshapeParams`. |
| 88 | int num_dimensions = params->num_dimensions; |
| 89 | if (num_dimensions == 1 && params->shape[0] == 0) { |
| 90 | // Legacy tflite models use a shape parameter of [0] to indicate scalars, |
| 91 | // so adjust accordingly. TODO(b/111614235): Allow zero-sized buffers during |
| 92 | // toco conversion. |
| 93 | num_dimensions = 0; |
| 94 | } |
| 95 | TfLiteIntArray* output_shape = TfLiteIntArrayCreate(num_dimensions); |
| 96 | for (int i = 0; i < num_dimensions; ++i) { |
| 97 | output_shape->data[i] = params->shape[i]; |
| 98 | } |
| 99 | |
| 100 | return output_shape; |
| 101 | } |
| 102 | |
| 103 | // Check if the shape tensor is valid. Shapes should be int32 vectors. |
| 104 | inline bool ShapeIsVector(TfLiteContext* context, TfLiteNode* node) { |
no test coverage detected