Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SP: optimize using minmax_element 25% faster #1326

Merged
merged 2 commits into from
Jun 8, 2017
Merged
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
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());
Copy link
Contributor

Choose a reason for hiding this comment

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

Whitespace cleanup: put a space after the comma.

UInt rowSpan = *minmaxRows.second /*max*/ - *minmaxRows.first /*min*/ +1;
Copy link
Contributor

Choose a reason for hiding this comment

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

Whitespace cleanup: put a space after the +.


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

Choose a reason for hiding this comment

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

Whitespace cleanup: put a space after the comma.

UInt colSpan = *minmaxCols.second - *minmaxCols.first +1;
Copy link
Contributor

Choose a reason for hiding this comment

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

Whitespace cleanup: put a space after the +.


return (rowSpan + colSpan) / 2.0;

Expand Down