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

Commit

Permalink
NUP-2504: fix clang link optimization issue on private template function
Browse files Browse the repository at this point in the history
  • Loading branch information
lscheinkman committed Apr 20, 2018
1 parent f5bc76b commit 42df6ca
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
9 changes: 4 additions & 5 deletions src/nupic/algorithms/SDRClassifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,15 +230,14 @@ vector<Real64> SDRClassifier::calculateError_(const vector<UInt> &bucketIdxList,
return likelihoods;
}

template <typename Iterator>
void SDRClassifier::softmax_(Iterator begin, Iterator end) {
Iterator maxItr = max_element(begin, end);
void SDRClassifier::softmax_(vector<Real64>::iterator begin,
vector<Real64>::iterator end) {
vector<Real64>::iterator maxItr = max_element(begin, end);
for (auto itr = begin; itr != end; ++itr) {
*itr -= *maxItr;
}
range_exp(1.0, begin, end);
typename std::iterator_traits<Iterator>::value_type sum =
accumulate(begin, end, 0.0);
Real64 sum = accumulate(begin, end, 0.0);
for (auto itr = begin; itr != end; ++itr) {
*itr /= sum;
}
Expand Down
2 changes: 1 addition & 1 deletion src/nupic/algorithms/SDRClassifier.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ class SDRClassifier : public Serializable<SdrClassifierProto> {
const vector<UInt> patternNZ, UInt step);

// softmax function
template <typename Iterator> void softmax_(Iterator begin, Iterator end);
void softmax_(vector<Real64>::iterator begin, vector<Real64>::iterator end);

// The list of prediction steps to learn and infer.
vector<UInt> steps_;
Expand Down
4 changes: 2 additions & 2 deletions src/test/unit/algorithms/SDRClassifierTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -432,9 +432,9 @@ TEST_F(SDRClassifierTest, WriteRead) {

TEST_F(SDRClassifierTest, testSoftmaxOverflow) {
SDRClassifier c = SDRClassifier({1}, 0.5, 0.5, 0);
std::vector<double> values = {numeric_limits<double>::max()};
std::vector<Real64> values = {numeric_limits<Real64>::max()};
softmax_(&c, values.begin(), values.end());
double result = values[0];
Real64 result = values[0];
ASSERT_FALSE(std::isnan(result));
}

Expand Down

0 comments on commit 42df6ca

Please sign in to comment.