Skip to content
This repository has been archived by the owner on Sep 1, 2023. It is now read-only.

Give clear exception when clients try to reuse ClassiferResults #1342

Merged
merged 2 commits into from
Jun 8, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions src/nupic/algorithms/ClassifierResult.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

#include <nupic/algorithms/ClassifierResult.hpp>
#include <nupic/types/Types.hpp>
#include <nupic/utils/Log.hpp>

using namespace std;

Expand All @@ -48,15 +49,11 @@ namespace nupic
vector<Real64>* ClassifierResult::createVector(Int step, UInt size,
Real64 value)
{
vector<Real64>* v;
map<Int, vector<Real64>*>::const_iterator it = result_.find(step);
if (it != result_.end())
{
v = it->second;
} else {
v = new vector<Real64>(size, value);
result_.insert(pair<Int, vector<Real64>*>(step, v));
}
NTA_CHECK(it == result_.end())
<< "The ClassifierResult cannot be reused!";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe just use

NTA_CHECK(result_.count(step) == 0);

and get rid of the iterator.

vector<Real64>* v = new vector<Real64>(size, value);
result_.insert(pair<Int, vector<Real64>*>(step, v));
return v;
}

Expand Down
3 changes: 2 additions & 1 deletion src/nupic/algorithms/SDRClassifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ namespace nupic
if (recordNum < lastRecordNum)
NTA_THROW << "the record number has to increase monotonically";
}

// update pattern history if this is a new record
if (recordNumHistory_.size() == 0 || recordNum > lastRecordNum)
{
Expand Down Expand Up @@ -127,7 +128,7 @@ namespace nupic
// if in inference mode, compute likelihood and update return value
if (infer)
{
infer_(patternNZ, actValueList, result);
infer_(patternNZ, actValueList, result);
}

// update weights if in learning mode
Expand Down