Skip to content

Commit

Permalink
Merge pull request #1326 from breznak/sp_minmax
Browse files Browse the repository at this point in the history
SP: optimize using minmax_element
  • Loading branch information
mrcslws authored Jun 8, 2017
2 parents 049e581 + c1d2ac4 commit 8e5f2db
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/nupic/algorithms/SpatialPooler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -947,11 +947,9 @@ Real SpatialPooler::avgConnectedSpanForColumn1D_(UInt column)
vector<UInt> connectedSparse = connectedSynapses_.getSparseRow(column);
if (connectedSparse.empty())
return 0;
UInt minIndex = *min_element(connectedSparse.begin(),
auto minmax = minmax_element(connectedSparse.begin(),
connectedSparse.end());
UInt maxIndex = *max_element(connectedSparse.begin(),
connectedSparse.end());
return maxIndex - minIndex + 1;
return *minmax.second /*max*/ - *minmax.first /*min*/ + 1;
}

Real SpatialPooler::avgConnectedSpanForColumn2D_(UInt column)
Expand All @@ -978,11 +976,11 @@ Real SpatialPooler::avgConnectedSpanForColumn2D_(UInt column)
return 0;
}

UInt rowSpan = *max_element(rows.begin(),rows.end()) -
*min_element(rows.begin(),rows.end()) + 1;
auto minmaxRows = minmax_element(rows.begin(), rows.end());
UInt rowSpan = *minmaxRows.second /*max*/ - *minmaxRows.first /*min*/ + 1;

UInt colSpan = *max_element(cols.begin(),cols.end()) -
*min_element(cols.begin(),cols.end()) + 1;
auto minmaxCols = minmax_element(cols.begin(), cols.end());
UInt colSpan = *minmaxCols.second - *minmaxCols.first + 1;

return (rowSpan + colSpan) / 2.0;

Expand Down

0 comments on commit 8e5f2db

Please sign in to comment.