| 494 | } |
| 495 | |
| 496 | void model::add_weights(OwningWeightsPtr&& ptr) |
| 497 | { |
| 498 | |
| 499 | // Check for null pointer |
| 500 | if (ptr == nullptr) { |
| 501 | LBANN_ERROR("attempted to add a null pointer as weights to ", |
| 502 | "model \"", |
| 503 | get_name(), |
| 504 | "\""); |
| 505 | } |
| 506 | |
| 507 | // Check that the new weights name is unique |
| 508 | // Note: Adding weights is O(n^2), but this is unlikely to be a |
| 509 | // bottleneck. If it is, consider maintaining a hash table |
| 510 | // containing all weights names (and properly updating it during |
| 511 | // copies and pointer remaps). |
| 512 | const auto& name = ptr->get_name(); |
| 513 | for (const auto& w : m_weights) { |
| 514 | if (w->get_name() == name) { |
| 515 | LBANN_ERROR("attempted to add weights \"", |
| 516 | name, |
| 517 | "\" to ", |
| 518 | "model \"", |
| 519 | get_name(), |
| 520 | "\", ", |
| 521 | "but the model already contains weights with that name"); |
| 522 | } |
| 523 | } |
| 524 | |
| 525 | // Add weights to model |
| 526 | m_weights.emplace_back(std::move(ptr)); |
| 527 | } |
| 528 | |
| 529 | void model::remove_weights(std::string const& removable_weight_name) |
| 530 | { |
no test coverage detected