8 #include "WeightsPairInterface.hpp" 9 #include "columns/HyPerCol.hpp" 10 #include "utils/MapLookupByType.hpp" 14 WeightsPairInterface::WeightsPairInterface(
char const *name, HyPerCol *hc) { initialize(name, hc); }
16 WeightsPairInterface::~WeightsPairInterface() {
21 int WeightsPairInterface::initialize(
char const *name, HyPerCol *hc) {
22 return BaseObject::initialize(name, hc);
25 void WeightsPairInterface::setObjectType() { mObjectType =
"WeightsPairInterface"; }
27 Response::Status WeightsPairInterface::communicateInitInfo(
28 std::shared_ptr<CommunicateInitInfoMessage const> message) {
29 auto status = BaseObject::communicateInitInfo(message);
33 if (mConnectionData ==
nullptr) {
34 mConnectionData = mapLookupByType<ConnectionData>(message->mHierarchy, getDescription());
37 mConnectionData ==
nullptr,
38 "%s requires a ConnectionData component.\n",
42 if (parent->getCommunicator()->globalCommRank() == 0) {
44 "%s must wait until the ConnectionData component has finished its " 45 "communicateInitInfo stage.\n",
48 return Response::POSTPONE;
51 if (mPatchSize ==
nullptr) {
52 mPatchSize = mapLookupByType<PatchSize>(message->mHierarchy, getDescription());
54 FatalIf(mPatchSize ==
nullptr,
"%s requires a PatchSize component.\n", getDescription_c());
57 if (parent->getCommunicator()->globalCommRank() == 0) {
59 "%s must wait until the PatchSize component has finished its " 60 "communicateInitInfo stage.\n",
63 return Response::POSTPONE;
66 HyPerLayer *pre = mConnectionData->
getPre();
67 HyPerLayer *post = mConnectionData->
getPost();
69 PVLayerLoc const *postLoc = post->getLayerLoc();
73 int xmargin = requiredConvolveMargin(preLoc->nx, postLoc->nx, mPatchSize->getPatchSizeX());
74 int receivedxmargin = 0;
75 int statusx = pre->requireMarginWidth(xmargin, &receivedxmargin,
'x');
76 if (statusx != PV_SUCCESS) {
78 "Margin Failure for layer %s. Received x-margin is %d, but %s requires margin of at " 80 pre->getDescription_c(),
86 int ymargin = requiredConvolveMargin(preLoc->ny, postLoc->ny, mPatchSize->getPatchSizeY());
87 int receivedymargin = 0;
88 int statusy = pre->requireMarginWidth(ymargin, &receivedymargin,
'y');
89 if (statusy != PV_SUCCESS) {
91 "Margin Failure for layer %s. Received y-margin is %d, but %s requires margin of at " 93 pre->getDescription_c(),
103 return Response::SUCCESS;
108 !mInitInfoCommunicatedFlag,
109 "%s must finish CommunicateInitInfo before needPre can be called.\n",
111 if (mPreWeights ==
nullptr) {
118 !mInitInfoCommunicatedFlag,
119 "%s must finish CommunicateInitInfo before needPost can be called.\n",
121 if (mPostWeights ==
nullptr) {
122 std::string weightsName(std::string(name) +
" post-perspective");
127 Response::Status WeightsPairInterface::allocateDataStructures() {
129 allocatePreWeights();
132 allocatePostWeights();
134 return Response::SUCCESS;
137 void WeightsPairInterface::allocatePreWeights() {
139 mConnectionData->
getPre()->getLayerLoc()->halo,
140 mConnectionData->
getPost()->getLayerLoc()->halo);
144 void WeightsPairInterface::allocatePostWeights() {
146 mConnectionData->
getPost()->getLayerLoc()->halo,
147 mConnectionData->
getPre()->getLayerLoc()->halo);
void setMargins(PVHalo const &preHalo, PVHalo const &postHalo)
virtual void createPostWeights(std::string const &weightsName)=0
virtual void createPreWeights(std::string const &weightsName)=0
static bool completed(Status &a)
void allocateDataStructures()
bool getInitInfoCommunicatedFlag() const