Skip to content

Commit 2552213

Browse files
committed
TMRegion: compute all outputs
1 parent fac5da7 commit 2552213

File tree

3 files changed

+8
-21
lines changed

3 files changed

+8
-21
lines changed

src/htm/engine/RegionImpl.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,9 @@ std::shared_ptr<Input> RegionImpl::getInput(const std::string &name) const {
243243
}
244244

245245
std::shared_ptr<Output> RegionImpl::getOutput(const std::string &name) const {
246-
return region_->getOutput(name);
246+
auto out = region_->getOutput(name);
247+
NTA_CHECK(out != nullptr) << "Requested output not found: " << name;
248+
return out;
247249
}
248250
Dimensions RegionImpl::getInputDimensions(const std::string &name) const {
249251
return region_->getInputDimensions(name);

src/htm/regions/TMRegion.cpp

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -177,15 +177,6 @@ void TMRegion::initialize() {
177177
}
178178

179179

180-
bool TMRegion::isConnected_(string name) const {
181-
const auto in = getInput(name);
182-
const auto out = getOutput(name);
183-
const bool hasOutput = (out != nullptr) and out->hasOutgoingLinks();
184-
const bool hasInput = (in != nullptr) and in->hasIncomingLinks();
185-
return hasInput or hasOutput;
186-
}
187-
188-
189180
void TMRegion::compute() {
190181

191182
NTA_ASSERT(tm_) << "TM not initialized";
@@ -244,36 +235,30 @@ void TMRegion::compute() {
244235
NTA_LOG_LEVEL = htm::LogLevel::LogLevel_Verbose;
245236
NTA_CHECK(NTA_LOG_LEVEL == LogLevel::LogLevel_Verbose) << "setting Verbose failed, man";
246237
//to output the NTA_DEBUG statements below
247-
if (isConnected_("bottomUpOut") ) {
248238
SDR& sdr = out->getData().getSDR();
249239
tm_->getActiveCells(sdr); //active cells
250240
if (args_.orColumnOutputs) { //output as columns
251241
sdr = tm_->cellsToColumns(sdr);
252242
}
253243
NTA_DEBUG << "bottomUpOut " << *out << std::endl;
254-
}
244+
255245
out = getOutput("activeCells");
256-
if (isConnected_("activeCells")) {
257246
tm_->getActiveCells(out->getData().getSDR());
258247
NTA_DEBUG << "active " << *out << std::endl;
259-
}
248+
260249
out = getOutput("predictedActiveCells");
261-
if (isConnected_("predictedActiveCells") ) {
262250
tm_->activateDendrites();
263251
tm_->getWinnerCells(out->getData().getSDR());
264252
NTA_DEBUG << "winners " << *out << std::endl;
265-
}
253+
266254
out = getOutput("anomaly");
267-
if (isConnected_("anomaly") ) {
268255
Real32* buffer = reinterpret_cast<Real32*>(out->getData().getBuffer());
269256
buffer[0] = tm_->anomaly; //only the first field is valid
270257
NTA_DEBUG << "anomaly " << *out << std::endl;
271-
}
258+
272259
out = getOutput("predictiveCells");
273-
if (isConnected_("predictiveCells") ) {
274260
out->getData().getSDR() = tm_->getPredictiveCells();
275261
NTA_DEBUG << "predictive " << *out << std::endl;
276-
}
277262
}
278263

279264

src/test/unit/regions/TMRegionTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ TEST(TMRegionTest, testLinking) {
252252
// check anomaly
253253
EXPECT_FLOAT_EQ(region3->getParameterReal32("anomaly"), 1.0f);
254254
const Real32 *anomalyBuffer = reinterpret_cast<const Real32*>(region3->getOutputData("anomaly").getBuffer());
255-
EXPECT_FLOAT_EQ(anomalyBuffer[0], 0.0f); // Note: it is zero because no links are connected to this output.
255+
EXPECT_FLOAT_EQ(anomalyBuffer[0], 1.0f);
256256

257257

258258
VERBOSE << " SPRegion Output " << std::endl;

0 commit comments

Comments
 (0)