PetaVision  Alpha
NormalizeGroup.cpp
1 /*
2  * NormalizeGroup.cpp
3  *
4  * Created on: Jun 22, 2016
5  * Author: pschultz
6  */
7 
8 #include "normalizers/NormalizeGroup.hpp"
9 #include "columns/ObjectMapComponent.hpp"
10 #include "components/WeightsPair.hpp"
11 #include "connections/HyPerConn.hpp"
12 #include "utils/MapLookupByType.hpp"
13 
14 namespace PV {
15 
16 NormalizeGroup::NormalizeGroup(char const *name, HyPerCol *hc) { initialize(name, hc); }
17 
18 NormalizeGroup::NormalizeGroup() {}
19 
20 NormalizeGroup::~NormalizeGroup() { free(mNormalizeGroupName); }
21 
22 int NormalizeGroup::initialize(char const *name, HyPerCol *hc) {
23  int status = NormalizeBase::initialize(name, hc);
24  return status;
25 }
26 
27 int NormalizeGroup::ioParamsFillGroup(enum ParamsIOFlag ioFlag) {
28  int status = NormalizeBase::ioParamsFillGroup(ioFlag);
30  return status;
31 }
32 
33 // The NormalizeBase parameters are overridden to do nothing in NormalizeGroup.
34 void NormalizeGroup::ioParam_normalizeArborsIndividually(enum ParamsIOFlag ioFlag) {}
35 void NormalizeGroup::ioParam_normalizeOnInitialize(enum ParamsIOFlag ioFlag) {}
36 void NormalizeGroup::ioParam_normalizeOnWeightUpdate(enum ParamsIOFlag ioFlag) {}
37 
38 void NormalizeGroup::ioParam_normalizeGroupName(enum ParamsIOFlag ioFlag) {
39  parent->parameters()->ioParamStringRequired(
40  ioFlag, name, "normalizeGroupName", &mNormalizeGroupName);
41 }
42 
43 Response::Status
44 NormalizeGroup::communicateInitInfo(std::shared_ptr<CommunicateInitInfoMessage const> message) {
45  auto status = NormalizeBase::communicateInitInfo(message);
46  if (status != Response::SUCCESS) {
47  return status;
48  }
49 
50  ObjectMapComponent *objectMapComponent =
51  mapLookupByType<ObjectMapComponent>(message->mHierarchy, getDescription());
52  pvAssert(objectMapComponent);
53  HyPerConn *groupHeadConn =
54  objectMapComponent->lookup<HyPerConn>(std::string(mNormalizeGroupName));
55  mGroupHead = groupHeadConn->getComponentByType<NormalizeBase>();
56 
57  if (mGroupHead == nullptr) {
58  if (parent->getCommunicator()->globalCommRank() == 0) {
59  ErrorLog().printf(
60  "%s: normalizeGroupName \"%s\" is not a recognized normalizer.\n",
61  getDescription_c(),
62  mNormalizeGroupName);
63  }
64  MPI_Barrier(parent->getCommunicator()->globalCommunicator());
65  exit(EXIT_FAILURE);
66  }
67 
68  auto hierarchy = message->mHierarchy;
69  WeightsPair *weightsPair = mapLookupByType<WeightsPair>(hierarchy, getDescription());
70  Weights *preWeights = weightsPair->getPreWeights();
71  pvAssert(preWeights); // NormalizeBase::communicateInitInfo should have called needPre.
72  mGroupHead->addWeightsToList(preWeights);
73  return Response::SUCCESS;
74 }
75 
76 int NormalizeGroup::normalizeWeights() { return PV_SUCCESS; }
77 
78 } /* namespace PV */
virtual int normalizeWeights() override
virtual void ioParam_normalizeOnInitialize(enum ParamsIOFlag ioFlag) override
int ioParamsFillGroup(enum ParamsIOFlag ioFlag) override
virtual void ioParam_normalizeArborsIndividually(enum ParamsIOFlag ioFlag) override
virtual int ioParamsFillGroup(enum ParamsIOFlag ioFlag) override
virtual void ioParam_normalizeGroupName(enum ParamsIOFlag ioFlag)
virtual void ioParam_normalizeOnWeightUpdate(enum ParamsIOFlag ioFlag) override