Make fillsinks memory-order agnostic #125
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This represents one way that we might make our interface with libtopotoolbox agnostic to the memory order of our underlying numpy arrays. I have added a property
dims
toGridObject
, which reverses the order of the dimensions if the array is in row-major layout.GridObject.shape
still returns(rows, columns)
. If we passself.dims
instead ofself.shape
to thefillsinks
wrapper, we will now get the same, correct, answer if theGridObject.z
array is column- or row-major. There is also a test that confirms this behavior.I did notice some unexpected changes in performance after implementing this. I thought it would tend to speed
fillsinks
up when using row-major data by avoiding the unnecessary copy to column major. However, this was not the case when applyingfillsinks
to the Big Tujunga data, loaded in row-major format. It takes around 25 ms on my machine to runfillsinks
on the column-major data and 33 ms on the row-major data.I believe that this is not a problem with our implementation, but instead dependent on the data.
fillsinks
is a global computation, and the amount of work it has to do depends on the orientation of features in the image. The Taiwan DEM performs better in row-major layout, and if I transpose the Big Tujunga DEM, the performance numbers swap: row-major takes around 33 ms and column-major takes around 25 ms.