| 1375 | } // namespace |
| 1376 | |
| 1377 | void InsertCopyOperator(Model* model, const string& source_array_name, |
| 1378 | const string& target_array_name) { |
| 1379 | // Reshape to the same size. This should be a no-op. |
| 1380 | const Array& source_array = model->GetArray(source_array_name); |
| 1381 | std::vector<int> shape = source_array.shape().dims(); |
| 1382 | |
| 1383 | // Drop constant data from the target array as the copy will be done at |
| 1384 | // runtime. |
| 1385 | Array& target_array = model->GetOrCreateArray(target_array_name); |
| 1386 | target_array.buffer.reset(); |
| 1387 | CopyArrayAttribs(source_array, &target_array); |
| 1388 | |
| 1389 | // Insert copy operator. |
| 1390 | auto* copy_op = new TensorFlowReshapeOperator; |
| 1391 | copy_op->inputs = { |
| 1392 | source_array_name, |
| 1393 | CreateInt32Array( |
| 1394 | model, AvailableArrayName(*model, target_array_name + "_copy_shape"), |
| 1395 | shape)}; |
| 1396 | copy_op->outputs = {target_array_name}; |
| 1397 | if (target_array.has_shape()) { |
| 1398 | copy_op->shape = target_array.shape().dims(); |
| 1399 | } |
| 1400 | model->operators.emplace_back(copy_op); |
| 1401 | } |
| 1402 | |
| 1403 | void CloneArray(Model* model, const string& source_array_name, |
| 1404 | const string& target_array_name) { |
no test coverage detected