pysal / momepy

Urban Morphology Measuring Toolkit
https://docs.momepy.org
BSD 3-Clause "New" or "Revised" License
478 stars 58 forks source link

ENH: mean_interbuilding_distance and building_adjacency #556

Closed martinfleis closed 6 months ago

martinfleis commented 7 months ago

Gosh I spent way too much time on this...

mean_interbuilding_distance:

35s new
57s old

Given my first attempt took 5mins, I call this a victory.

building_adjacency:

 old: 251 ms ± 14.6 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)
 new: 422 ms ± 12.3 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)

of which 330 ms is assign_self_weight which will be used in other functions so I'm wondering if it is worth adding a keyword self_weighted=True to skip this. In practice it is nearly negligible difference though...

These two functions also quite significantly change the API compared to the original. @jGaboardi can you give it a thought whether it makes sense in this way? I think it does and it is more flexible than before but it is different.

codecov[bot] commented 7 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 97.6%. Comparing base (4037c70) to head (399cf39). Report is 6 commits behind head on main.

Additional details and impacted files [![Impacted file tree graph](https://app.codecov.io/gh/pysal/momepy/pull/556/graphs/tree.svg?width=650&height=150&src=pr&token=VNn0WR5JWT&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pysal)](https://app.codecov.io/gh/pysal/momepy/pull/556?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pysal) ```diff @@ Coverage Diff @@ ## main #556 +/- ## ======================================= + Coverage 97.4% 97.6% +0.3% ======================================= Files 26 30 +4 Lines 4328 4796 +468 ======================================= + Hits 4214 4682 +468 Misses 114 114 ``` | [Files](https://app.codecov.io/gh/pysal/momepy/pull/556?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pysal) | Coverage Δ | | |---|---|---| | [momepy/functional/\_distribution.py](https://app.codecov.io/gh/pysal/momepy/pull/556?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pysal#diff-bW9tZXB5L2Z1bmN0aW9uYWwvX2Rpc3RyaWJ1dGlvbi5weQ==) | `100.0% <100.0%> (ø)` | | | [momepy/functional/tests/test\_distribution.py](https://app.codecov.io/gh/pysal/momepy/pull/556?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pysal#diff-bW9tZXB5L2Z1bmN0aW9uYWwvdGVzdHMvdGVzdF9kaXN0cmlidXRpb24ucHk=) | `100.0% <100.0%> (ø)` | | | [momepy/functional/tests/test\_shape.py](https://app.codecov.io/gh/pysal/momepy/pull/556?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pysal#diff-bW9tZXB5L2Z1bmN0aW9uYWwvdGVzdHMvdGVzdF9zaGFwZS5weQ==) | `100.0% <100.0%> (ø)` | |
jGaboardi commented 7 months ago

These two functions also quite significantly change the API compared to the original. @jGaboardi can you give it a thought whether it makes sense in this way? I think it does and it is more flexible than before but it is different.

I think it makes sense, cleaner and more efficient for sure.

martinfleis commented 6 months ago

of which 330 ms is assign_self_weight which will be used in other functions so I'm wondering if it is worth adding a keyword self_weighted=True to skip this. In practice it is nearly negligible difference though...

Solved in 0d897cc by cheaply (10ms) checking if the graph already has self-weights and assigning only if they do not. Which means that if you pass self-weighted graph, the new implementation takes about half the time compared to the original.