MCPcopy Create free account
hub / github.com/LBANN/lbann / add_layer

Method add_layer

src/models/model.cpp:462–494  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

460// =============================================
461
462void 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
496void model::add_weights(OwningWeightsPtr&& ptr)
497{

Callers 2

construct_modelFunction · 0.80
write_protoMethod · 0.80

Calls 2

set_modelMethod · 0.80
get_nameMethod · 0.45

Tested by

no test coverage detected