本文整理汇总了C++中Input::addLink方法的典型用法代码示例。如果您正苦于以下问题:C++ Input::addLink方法的具体用法?C++ Input::addLink怎么用?C++ Input::addLink使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Input
的用法示例。
在下文中一共展示了Input::addLink方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
void
Network::link(const std::string& srcRegionName, const std::string& destRegionName,
const std::string& linkType, const std::string& linkParams,
const std::string& srcOutputName, const std::string& destInputName)
{
// Find the regions
if (! regions_.contains(srcRegionName))
NTA_THROW << "Network::link -- source region '" << srcRegionName << "' does not exist";
Region* srcRegion = regions_.getByName(srcRegionName);
if (! regions_.contains(destRegionName))
NTA_THROW << "Network::link -- dest region '" << destRegionName << "' does not exist";
Region* destRegion = regions_.getByName(destRegionName);
// Find the inputs/outputs
const Spec* srcSpec = srcRegion->getSpec();
std::string outputName = srcOutputName;
if (outputName == "")
outputName = srcSpec->getDefaultOutputName();
Output* srcOutput = srcRegion->getOutput(outputName);
if (srcOutput == NULL)
NTA_THROW << "Network::link -- output " << outputName
<< " does not exist on region " << srcRegionName;
const Spec *destSpec = destRegion->getSpec();
std::string inputName;
if (destInputName == "")
inputName = destSpec->getDefaultInputName();
else
inputName = destInputName;
Input* destInput = destRegion->getInput(inputName);
if (destInput == NULL)
{
NTA_THROW << "Network::link -- input '" << inputName
<< " does not exist on region " << destRegionName;
}
// Create the link itself
destInput->addLink(linkType, linkParams, srcOutput);
}
示例2: loadFromBundle
//.........这里部分代码省略.........
(*valiter) >> val;
phases.insert(val);
}
// 5. label
node = (*region).FindValue("label");
if (node == NULL)
NTA_THROW << "Invalid network structure file -- region"
<< name << "has no label";
std::string label;
*node >> label;
Region *r = addRegionFromBundle(name, nodeType, dimensions, fullPath, label);
setPhases_(r, phases);
}
const YAML::Node *links = doc.FindValue("Links");
if (links == NULL)
NTA_THROW << "Invalid network structure file -- no links";
if (links->Type() != YAML::NodeType::Sequence)
NTA_THROW << "Invalid network structure file -- links element is not a list";
for (YAML::Iterator link = links->begin(); link != links->end(); link++)
{
// Each link is a map -- extract the 5 values in the map
if ((*link).Type() != YAML::NodeType::Map)
NTA_THROW << "Invalid network structure file -- bad link (not a map)";
if ((*link).size() != 6)
NTA_THROW << "Invalid network structure file -- bad link (wrong size)";
// 1. type
node = (*link).FindValue("type");
if (node == NULL)
NTA_THROW << "Invalid network structure file -- link does not have a type";
std::string linkType;
*node >> linkType;
// 2. params
node = (*link).FindValue("params");
if (node == NULL)
NTA_THROW << "Invalid network structure file -- link does not have params";
std::string params;
*node >> params;
// 3. srcRegion (name)
node = (*link).FindValue("srcRegion");
if (node == NULL)
NTA_THROW << "Invalid network structure file -- link does not have a srcRegion";
std::string srcRegionName;
*node >> srcRegionName;
// 4. srcOutput
node = (*link).FindValue("srcOutput");
if (node == NULL)
NTA_THROW << "Invalid network structure file -- link does not have a srcOutput";
std::string srcOutputName;
*node >> srcOutputName;
// 5. destRegion
node = (*link).FindValue("destRegion");
if (node == NULL)
NTA_THROW << "Invalid network structure file -- link does not have a destRegion";
std::string destRegionName;
*node >> destRegionName;
// 6. destInput
node = (*link).FindValue("destInput");
if (node == NULL)
NTA_THROW << "Invalid network structure file -- link does not have a destInput";
std::string destInputName;
*node >> destInputName;
if (!regions_.contains(srcRegionName))
NTA_THROW << "Invalid network structure file -- link specifies source region '" << srcRegionName << "' but no such region exists";
Region* srcRegion = regions_.getByName(srcRegionName);
if (!regions_.contains(destRegionName))
NTA_THROW << "Invalid network structure file -- link specifies destination region '" << destRegionName << "' but no such region exists";
Region* destRegion = regions_.getByName(destRegionName);
Output* srcOutput = srcRegion->getOutput(srcOutputName);
if (srcOutput == NULL)
NTA_THROW << "Invalid network structure file -- link specifies source output '" << srcOutputName << "' but no such name exists";
Input* destInput = destRegion->getInput(destInputName);
if (destInput == NULL)
NTA_THROW << "Invalid network structure file -- link specifies destination input '" << destInputName << "' but no such name exists";
// Create the link itself
destInput->addLink(linkType, params, srcOutput);
} // links
}
示例3: read
void Network::read(NetworkProto::Reader& proto)
{
// Clear any previous regions
while (regions_.getCount() > 0)
{
auto pair = regions_.getByIndex(0);
delete pair.second;
regions_.remove(pair.first);
}
// Add regions
for (auto entry : proto.getRegions().getEntries())
{
auto regionProto = entry.getValue();
auto region = addRegionFromProto(entry.getKey().cStr(), regionProto);
// Initialize the phases for the region
std::set<UInt32> phases;
for (auto phase : regionProto.getPhases())
{
phases.insert(phase);
}
setPhases_(region, phases);
}
// Add links. Note that we can't just pass the capnp struct to Link.read
// because the linked input and output need references to the new link.
for (auto linkProto : proto.getLinks())
{
if (!regions_.contains(linkProto.getSrcRegion().cStr()))
{
NTA_THROW << "Link references unknown region: "
<< linkProto.getSrcRegion().cStr();
}
Region* srcRegion = regions_.getByName(linkProto.getSrcRegion().cStr());
Output* srcOutput = srcRegion->getOutput(linkProto.getSrcOutput().cStr());
if (srcOutput == nullptr)
{
NTA_THROW << "Link references unknown source output: "
<< linkProto.getSrcOutput().cStr();
}
if (!regions_.contains(linkProto.getDestRegion().cStr()))
{
NTA_THROW << "Link references unknown region: "
<< linkProto.getDestRegion().cStr();
}
Region* destRegion = regions_.getByName(linkProto.getDestRegion().cStr());
Input* destInput = destRegion->getInput(linkProto.getDestInput().cStr());
if (destInput == nullptr)
{
NTA_THROW << "Link references unknown destination input: "
<< linkProto.getDestInput().cStr();
}
// Actually create the link
destInput->addLink(
linkProto.getType().cStr(), linkProto.getParams().cStr(), srcOutput);
}
initialized_ = false;
}