-
Notifications
You must be signed in to change notification settings - Fork 70
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
Reimplement managed raster class in C++ #1597
base: feature/routing-refactor
Are you sure you want to change the base?
Reimplement managed raster class in C++ #1597
Conversation
@phargogh this is finally ready for re-review! The biggest change is I figured out how to implement the iterators properly, so they can be iterated with the usual syntax, solving the issues with tracking/incrementing values properly. |
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 @emlys , this looks good to me! I had a couple of minor comments, and then I also wanted to confirm: what we have here in this PR looks to be intended for MFD routing, specifically, so is D8 routing to be added in a future PR?
include_dirs = [numpy.get_include(), 'src/natcap/invest/managed_raster'] | ||
if platform.system() == 'Windows': | ||
compiler_args = ['/std:c++20'] | ||
library_dirs = [f'{os.environ["CONDA_PREFIX"]}/Library/lib'] | ||
include_dirs.append(f'{os.environ["CONDA_PREFIX"]}/Library/include') | ||
else: | ||
library_dirs = [] | ||
compiler_args = [] | ||
compiler_and_linker_args = ['-stdlib=libc++', '-std=c++20'] | ||
library_dirs = [subprocess.run( | ||
['gdal-config', '--libs'], capture_output=True, text=True | ||
).stdout.split()[0][2:]] # get the first argument which is the library path |
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.
Since we are now building directly against gdal
, should we add the new build dependency to pyproject.toml
?
else: | ||
library_dirs = [] | ||
compiler_args = [] | ||
compiler_and_linker_args = ['-stdlib=libc++', '-std=c++20'] |
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.
Is C++20 truly the minimum language version required? I don't think this should be a huge deal since compilers seem to pretty rapidly adopt the new standards, so I think this is mostly a question of curiosity.
ManagedFlowDirRaster(char* raster_path, int band_id, bool write_mode) | ||
: ManagedRaster(raster_path, band_id, write_mode) // Call the superclass constructor in the subclass' initialization list. | ||
{ | ||
// do something with bar | ||
} |
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.
Is the plan to still do something in this constructor?
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.
Fixed in 25c954a
Description
This PR reimplements the
ManagedRaster
class in C++ for better performance. Tested withsdr.calculate_sediment_deposition
and the SDR sample data, it's now just slightly faster than the original implementation onmain
(0.59 vs 0.61 seconds), whereas the python implementation onfeature/routing-refactor
takes nearly twice as long.I'm a beginner at C++ so I'm sure I'm not always using the right conventions or design patterns, but this seems like an okay starting point. I took some guidance from the Google C++ style guide. Ignoring some guidelines that don't seem to make sense in this context. For instance, I have all the code in a header file because splitting it out into
ManagedRaster.h
andManagedRaster.cpp
significantly slowed it down.Happy to discuss and walk through this PR on a zoom call as well.
Checklist