natcap / invest

InVEST®: models that map and value the goods and services from nature that sustain and fulfill human life.
Apache License 2.0
170 stars 70 forks source link

Reimplement managed raster class in C++ #1597

Open emlys opened 4 months ago

emlys commented 4 months ago

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

emlys commented 1 week ago

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