8 #include "ArborList.hpp" 9 #include "columns/HyPerCol.hpp" 10 #include "components/ConnectionData.hpp" 11 #include "layers/HyPerLayer.hpp" 12 #include "utils/MapLookupByType.hpp" 16 ArborList::ArborList(
char const *name, HyPerCol *hc) { initialize(name, hc); }
18 ArborList::ArborList() {}
20 ArborList::~ArborList() { free(mDelaysParams); }
22 int ArborList::initialize(
char const *name, HyPerCol *hc) {
23 return BaseObject::initialize(name, hc);
26 void ArborList::setObjectType() { mObjectType =
"ArborList"; }
35 parent->parameters()->ioParamValue(
36 ioFlag, this->getName(),
"numAxonalArbors", &mNumAxonalArbors, mNumAxonalArbors);
37 if (ioFlag == PARAMS_IO_READ) {
40 "Connection %s: Variable numAxonalArbors is set to 0. " 41 "No connections will be made.\n",
50 parent->parameters()->ioParamArray(ioFlag, getName(),
"delay", &mDelaysParams, &mNumDelays);
51 if (ioFlag == PARAMS_IO_READ && mNumDelays == 0) {
52 assert(mDelaysParams ==
nullptr);
53 mDelaysParams = (
double *)pvMallocError(
55 "%s: unable to set default delay: %s\n",
56 this->getDescription_c(),
58 *mDelaysParams = 0.0f;
60 if (parent->getCommunicator()->globalCommRank() == 0) {
61 InfoLog().printf(
"%s: Using default value of zero for delay.\n", this->getDescription_c());
67 ArborList::communicateInitInfo(std::shared_ptr<CommunicateInitInfoMessage const> message) {
69 mapLookupByType<ConnectionData>(message->mHierarchy, getDescription());
71 connectionData ==
nullptr,
72 "%s received CommunicateInitInfo message without a ConnectionData component.\n",
76 if (parent->getCommunicator()->globalCommRank() == 0) {
78 "%s must wait until the ConnectionData component has finished its " 79 "communicateInitInfo stage.\n",
82 return Response::POSTPONE;
87 int maxDelay = maxDelaySteps();
88 int allowedDelay = preLayer->increaseDelayLevels(maxDelay);
89 if (allowedDelay < maxDelay) {
90 if (parent->getCommunicator()->globalCommRank() == 0) {
92 "%s: attempt to set delay to %d, but the maximum " 93 "allowed delay is %d. Exiting\n",
98 MPI_Barrier(parent->getCommunicator()->globalCommunicator());
102 return Response::SUCCESS;
105 void ArborList::initializeDelays() {
106 assert(!parent->parameters()->presentAndNotBeenRead(this->getName(),
"numAxonalArbors"));
111 for (
int arborId = 0; arborId < (int)mDelay.size(); arborId++) {
112 if (mNumDelays == 0) {
114 setDelay(arborId, 0.0);
116 else if (mNumDelays == 1) {
117 setDelay(arborId, mDelaysParams[0]);
120 setDelay(arborId, mDelaysParams[arborId]);
124 "Delay must be either a single value or the same length " 125 "as the number of arbors\n");
130 void ArborList::setDelay(
int arborId,
double delay) {
132 int intDelay = (int)std::nearbyint(delay / parent->getDeltaTime());
133 if (std::fmod(delay, parent->getDeltaTime()) != 0) {
134 double actualDelay = intDelay * parent->getDeltaTime();
135 WarnLog() << getName() <<
": A delay of " << delay <<
" will be rounded to " << actualDelay
138 mDelay[arborId] = intDelay;
141 int ArborList::maxDelaySteps() {
144 for (
auto &d : mDelay) {
virtual void ioParam_delay(enum ParamsIOFlag ioFlag)
delay: Specifies delay(s) which the post layer will receive data
virtual void ioParam_numAxonalArbors(enum ParamsIOFlag ioFlag)
numAxonalArbors: Specifies the number of arbors to use in the connection
int getNumAxonalArbors() const
virtual int ioParamsFillGroup(enum ParamsIOFlag ioFlag) override
bool getInitInfoCommunicatedFlag() const