-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Add GDALRasterComputeMinMaxLocation / GDALRasterBand::ComputeMinMaxLocation, and map it to SWIG #11200
Add GDALRasterComputeMinMaxLocation / GDALRasterBand::ComputeMinMaxLocation, and map it to SWIG #11200
Conversation
… to find the min/max elements in a buffer Refs qgis/QGIS#59285 NaN values are taken into account for float/double Contains a SSE2 optimized version for int8/uint8/int16/uint16/int32/uint32/float/double in the no-nodata case (also taking into account NaN)
dc1a0ee
to
505660f
Compare
#ifdef NOT_EFFICIENT | ||
|
||
/************************************************************************/ | ||
/* minmax_element() */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So there are algorithms for finding both the min and max element of a list of numbers at the same time that beat the speed of iterating the list and checking each number versus min and each numeber versus mac and updating the min and max as you go. You can do less comparisons by pulling out two numbers at a time, comparing them to each other, and checking the min one to overall min and the max one versus overall max. I think this ends up doing 3/4's the number of overall comparisons than the naive approach. I have lost the reference for this but I coded it in my java library. See here; https://github.com/bdezonia/zorbage/blob/master/src/main/java/nom/bdezonia/zorbage/algorithm/MinMaxElement.java
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the suggestion but saving 1/4 of operations isn't going to improve performance in a significant way.
Current timings are for a Byte vector of 10 millions elements (lower is better):
- using std::minmax_element(): 15,062,444
- using NOT_EFFICIENT code path: 9,625,260
- using SSE2 optimized gdal::min_element() + gdal::max_element() (enabled currently): 1,341,901
So your suggestion would perhaps reduce NOT_EFFICIENT code path timing, but it would be still far away from the twice repeated SSE2 optimized code paths. Actually I've just tested it and it results in... 50% slower code than the naive version... Presumably due to degraded pipelining
…6, int16, uint32, int32, float and double nodata cases
505660f
to
9a9ffc3
Compare
…the non-SSE2 case, as it turns out at least on Apple Silicon that our 'optimized' version is generally slower
…cation, and map it to SWIG and add a gdal_minmax_location.py script: ``` $ python ../swig/python/gdal-utils/osgeo_utils/samples/gdal_minmax_location.py byte.tif Minimum=74.0 at (col,line)=(9,17), (X,Y)_georef=(441290.0,3750270.0), (long,lat)_WGS84=(-117.6358076,33.8929309) Maximum=255.0 at (col,line)=(2,18), (X,Y)_georef=(440870.0,3750210.0), (long,lat)_WGS84=(-117.6403456,33.8923662) ```
9a9ffc3
to
58d4d3e
Compare
The gdal-dev version from OSGeo4W installed today shows version Should I wait for new nightly builds, or could there be something wrong in the OSGeo4W? |
@jef-n Is the date of the system where OSGeo4W is build up-to-date ?
yes, it should be available. Commit d9b65d7 is the merge request from yesterday, so it must include GDALRasterComputeMinMaxLocation. Are you sure your PYTHONPATH is correctly set to point to the updated GDAL python bindings? |
My fault. I have learned to activate gdal-dev in OSGeo4W by running command gdal_minmax_location.py runs without issues. Very fast. Everything is obvious when one reads the contents of the gdal-dev-py-env.bat file, but I explain it shortly so I can give a link for the next user who will have the same problem. If the OSGeo4W root directory is at |
and add a gdal_minmax_location.py script:
(on top of PR #11199)