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

SP: optimize using minmax_element 25% faster #1326

Merged
merged 2 commits into from
Jun 8, 2017

Conversation

breznak
Copy link
Member

@breznak breznak commented May 24, 2017

than using both min() and max() separately

Fixes #1325

than using both min() and max() separately
@breznak
Copy link
Member Author

breznak commented May 24, 2017

@mrcslws Please see here

Copy link
Contributor

@mrcslws mrcslws left a comment

Choose a reason for hiding this comment

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

I listed some whitespace changes.

Why do you say this is 25% faster? Did you run a quick microbenchmark on these two approaches?

@@ -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 = *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;
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 = *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;
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 +.

@breznak
Copy link
Member Author

breznak commented May 25, 2017 via email

@mrcslws
Copy link
Contributor

mrcslws commented May 25, 2017

You can't really assign a number to this improvement a priori. It's doing 1 pass instead of 2, which is good, but it's hard to predict how much faster it actually is. Doing 2 passes isn't as slow as you might think, since the CPU prefetches memory during sequential lookups.

(I don't see this in any of your commit descriptions. I checked before saying anything.)

Anyway, this is still a good change.

@breznak
Copy link
Member Author

breznak commented May 25, 2017

(I don't see this in any of your commit descriptions. I checked before saying anything.)

My bad, sorry. I thought I've documented that somewhere.

Should I try some micro-benchmark, or is it ok as is? (except the whitespaces..)

@mrcslws
Copy link
Contributor

mrcslws commented May 26, 2017

This is good as-is, just fix the whitespace and I'll merge it.

@breznak
Copy link
Member Author

breznak commented Jun 8, 2017

@mrcslws Sorry for the long delay, I'm back home. Fixed the cleanup and should be ready.

@mrcslws mrcslws merged commit 8e5f2db into numenta:master Jun 8, 2017
@rhyolight
Copy link
Member

👏

@breznak breznak deleted the sp_minmax branch June 8, 2017 19:35
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants