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

Make fillsinks memory-order agnostic #125

Merged
merged 4 commits into from
Jan 16, 2025

Conversation

wkearn
Copy link
Contributor

@wkearn wkearn commented Jan 9, 2025

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 to GridObject, which reverses the order of the dimensions if the array is in row-major layout. GridObject.shape still returns (rows, columns). If we pass self.dims instead of self.shape to the fillsinks wrapper, we will now get the same, correct, answer if the GridObject.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 applying fillsinks to the Big Tujunga data, loaded in row-major format. It takes around 25 ms on my machine to run fillsinks 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.

wkearn added 4 commits January 9, 2025 11:11
This makes the comparison using array_equal and also checks to make
sure that the memory layout was not changed by fillsinks.
This now passes the test that ensures that the memory order does not
change within fillsinks, but it will fail the test that compares the
two arrays.
This should now work if the input array is row or column major.
@wkearn wkearn merged commit 84140e0 into TopoToolbox:main Jan 16, 2025
7 checks passed
wkearn added a commit to wkearn/pytopotoolbox that referenced this pull request Jan 16, 2025
The changes in TopoToolbox#125 use opensimplex directly in the tests, and I
wanted to be clear that you need opensimplex to run the tests. I left
the "opensimplex" optional dependency in there to avoid breaking
workflows and because it does provide functionality that we use
outside of the tests.

I also added pytest to the "test" dependency. I believe this is the only
other package we use directly. All of the other test dependencies are
transitive dependencies. Cleanly installing everything using `pip
install .[test]` in a new virtual environment works, and the tests are
able to run successfully.
wkearn added a commit that referenced this pull request Jan 16, 2025
The changes in #125 use opensimplex directly in the tests, and I
wanted to be clear that you need opensimplex to run the tests. I left
the "opensimplex" optional dependency in there to avoid breaking
workflows and because it does provide functionality that we use
outside of the tests.

I also added pytest to the "test" dependency. I believe this is the only
other package we use directly. All of the other test dependencies are
transitive dependencies. Cleanly installing everything using `pip
install .[test]` in a new virtual environment works, and the tests are
able to run successfully.
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.

1 participant