| 460 | // ============================================= |
| 461 | |
| 462 | void model::add_layer(OwningLayerPtr&& ptr) |
| 463 | { |
| 464 | |
| 465 | // Check for null pointer |
| 466 | if (ptr == nullptr) { |
| 467 | LBANN_ERROR("attempted to add a null pointer as layer to ", |
| 468 | "model \"", |
| 469 | get_name(), |
| 470 | "\""); |
| 471 | } |
| 472 | |
| 473 | // Check that the new layer name is unique |
| 474 | // Note: Adding layers is O(n^2), but this is unlikely to be a |
| 475 | // bottleneck. If it is, consider maintaining a hash table |
| 476 | // containing all layer names (and properly updating it during |
| 477 | // copies and pointer remaps). |
| 478 | const auto& name = ptr->get_name(); |
| 479 | for (const auto& l : m_layers) { |
| 480 | if (l->get_name() == name) { |
| 481 | LBANN_ERROR("attempted to add layer \"", |
| 482 | name, |
| 483 | "\" to ", |
| 484 | "model \"", |
| 485 | get_name(), |
| 486 | "\", ", |
| 487 | "but the model already contains a layer with that name"); |
| 488 | } |
| 489 | } |
| 490 | |
| 491 | // Add layer to model |
| 492 | m_layers.emplace_back(std::move(ptr)); |
| 493 | m_layers.back()->set_model(this); |
| 494 | } |
| 495 | |
| 496 | void model::add_weights(OwningWeightsPtr&& ptr) |
| 497 | { |
no test coverage detected