8 #include "CopyUpdater.hpp" 9 #include "columns/HyPerCol.hpp" 10 #include "columns/ObjectMapComponent.hpp" 11 #include "components/OriginalConnNameParam.hpp" 12 #include "connections/HyPerConn.hpp" 13 #include "utils/MapLookupByType.hpp" 14 #include "utils/TransposeWeights.hpp" 18 CopyUpdater::CopyUpdater(
char const *name, HyPerCol *hc) { initialize(name, hc); }
20 int CopyUpdater::initialize(
char const *name, HyPerCol *hc) {
21 return BaseWeightUpdater::initialize(name, hc);
24 void CopyUpdater::setObjectType() { mObjectType =
"CopyUpdater"; }
32 CopyUpdater::communicateInitInfo(std::shared_ptr<CommunicateInitInfoMessage const> message) {
33 auto componentMap = message->mHierarchy;
35 mCopyWeightsPair = mapLookupByType<CopyWeightsPair>(componentMap, getDescription());
37 mCopyWeightsPair ==
nullptr,
38 "%s requires a CopyWeightsPair component.\n",
41 return Response::POSTPONE;
45 auto *originalConnNameParam =
46 mapLookupByType<OriginalConnNameParam>(componentMap, getDescription());
48 originalConnNameParam ==
nullptr,
49 "%s requires a OriginalConnNameParam component.\n",
51 if (!originalConnNameParam->getInitInfoCommunicatedFlag()) {
52 return Response::POSTPONE;
55 char const *originalConnName = originalConnNameParam->getOriginalConnName();
56 pvAssert(originalConnName !=
nullptr and originalConnName[0] !=
'\0');
58 auto hierarchy = message->mHierarchy;
59 auto *objectMapComponent = mapLookupByType<ObjectMapComponent>(hierarchy, getDescription());
60 pvAssert(objectMapComponent);
61 HyPerConn *originalConn = objectMapComponent->lookup<
HyPerConn>(std::string(originalConnName));
62 pvAssert(originalConn);
63 auto *originalWeightUpdater = originalConn->getComponentByType<
BaseWeightUpdater>();
64 if (originalWeightUpdater and !originalWeightUpdater->getInitInfoCommunicatedFlag()) {
65 return Response::POSTPONE;
67 mPlasticityFlag = originalWeightUpdater ? originalWeightUpdater->getPlasticityFlag() :
false;
69 auto *originalWeightsPair = originalConn->getComponentByType<
WeightsPair>();
70 pvAssert(originalWeightsPair);
71 if (!originalWeightsPair->getInitInfoCommunicatedFlag()) {
72 return Response::POSTPONE;
74 originalWeightsPair->needPre();
75 mOriginalWeights = originalWeightsPair->getPreWeights();
76 pvAssert(mOriginalWeights);
78 auto status = BaseWeightUpdater::communicateInitInfo(message);
83 if (mPlasticityFlag) {
84 mCopyWeightsPair->getPreWeights()->setWeightsArePlastic();
86 mWriteCompressedCheckpoints = mCopyWeightsPair->getWriteCompressedCheckpoints();
88 return Response::SUCCESS;
91 Response::Status CopyUpdater::registerData(
Checkpointer *checkpointer) {
92 auto status = BaseWeightUpdater::registerData(checkpointer);
96 std::string nameString = std::string(name);
97 checkpointer->registerCheckpointData(
104 return Response::SUCCESS;
107 void CopyUpdater::updateState(
double simTime,
double dt) {
108 pvAssert(mCopyWeightsPair and mCopyWeightsPair->getPreWeights());
110 mCopyWeightsPair->
copy();
111 mCopyWeightsPair->getPreWeights()->
setTimestamp(simTime);
112 mLastUpdateTime = simTime;
virtual void ioParam_plasticityFlag(enum ParamsIOFlag ioFlag) override
static bool completed(Status &a)
double getTimestamp() const
void setTimestamp(double timestamp)
bool getInitInfoCommunicatedFlag() const