| 1476 | } |
| 1477 | |
| 1478 | void CreateOrCheckRnnStateArray(const string& name, int size, |
| 1479 | int state_num_dims, Model* model) { |
| 1480 | int batch = 1; |
| 1481 | int num_dims = -1; |
| 1482 | if (state_num_dims > 0) { |
| 1483 | num_dims = state_num_dims; |
| 1484 | } else { |
| 1485 | // state_num_dims is not given. We will infer it from an input tensor. |
| 1486 | for (const auto& input_array : model->flags.input_arrays()) { |
| 1487 | // Pick 'num_dims' and 'batch' from the first input_arrays, unless we find |
| 1488 | // a better match by name. |
| 1489 | if (input_array.name() == name || num_dims == -1) { |
| 1490 | num_dims = input_array.shape().dims_size(); |
| 1491 | if (num_dims > 0) { |
| 1492 | batch = input_array.shape().dims(0); |
| 1493 | } |
| 1494 | } |
| 1495 | } |
| 1496 | } |
| 1497 | Array& array = model->GetOrCreateArray(name); |
| 1498 | if (array.has_shape()) { |
| 1499 | num_dims = array.shape().dimensions_count(); |
| 1500 | } |
| 1501 | if (!array.has_shape() && num_dims >= 0) { |
| 1502 | Shape* shape = array.mutable_shape(); |
| 1503 | std::vector<int> dims; |
| 1504 | MakeArrayDims(num_dims, batch, 1, 1, size, &dims); |
| 1505 | *shape->mutable_dims() = dims; |
| 1506 | } |
| 1507 | } |
| 1508 | |
| 1509 | void ResolveModelFlags(const ModelFlags& model_flags, Model* model) { |
| 1510 | // Merge info about input_arrays from model_flags into model->flags |
no test coverage detected