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

Reimplement managed raster class in C++ #1597

Open
wants to merge 84 commits into
base: feature/routing-refactor
Choose a base branch
from

Conversation

emlys
Copy link
Member

@emlys emlys commented Jul 17, 2024

Description

This PR reimplements the ManagedRaster class in C++ for better performance. Tested with sdr.calculate_sediment_deposition and the SDR sample data, it's now just slightly faster than the original implementation on main (0.59 vs 0.61 seconds), whereas the python implementation on feature/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 and ManagedRaster.cpp significantly slowed it down.

Happy to discuss and walk through this PR on a zoom call as well.

Checklist

  • Updated HISTORY.rst and link to any relevant issue (if these changes are user-facing)
  • Updated the user's guide (if needed)
  • Tested the Workbench UI (if relevant)

@emlys emlys changed the base branch from main to feature/routing-refactor July 17, 2024 18:00
@emlys
Copy link
Member Author

emlys commented Nov 5, 2024

@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.

@emlys emlys requested a review from phargogh November 5, 2024 19:46
Copy link
Member

@phargogh phargogh left a 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?

Comment on lines +23 to +34
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
Copy link
Member

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']
Copy link
Member

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.

Comment on lines 346 to 350
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
}
Copy link
Member

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?

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed in 25c954a

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants