stefmolin / data-morph

Morph an input dataset of 2D points into select shapes, while preserving the summary statistics to a given number of decimal points through simulated annealing. It is intended to be used as a teaching tool to illustrate the importance of data visualization.
https://stefaniemolin.com/data-morph/
MIT License
71 stars 20 forks source link

Optimize distance calculations #203

Closed JCGoran closed 3 months ago

JCGoran commented 3 months ago

Fixes #202

Describe your changes

I've benchmarked the above 2 on the bullseye and rings shapes, and the results are nice:

# bullseye on main
218292773 function calls (215844061 primitive calls) in 85.438 seconds
# bullseye w/ this PR
211510859 function calls (209069591 primitive calls) in 82.753 seconds
# rings on main
224466386 function calls (222017681 primitive calls) in 86.428 seconds
# rings w/ this PR
210318700 function calls (207877434 primitive calls) in 82.098 seconds

While the relative performance improvement appears marginal, it only appears that way due to Pandas-related operations being the bottleneck, and for bullseye we get 6.7M less function calls, while for rings we get 14.1M less function calls in total.

Note that no changes were made to the public API.

Checklist

codecov[bot] commented 3 months ago

Codecov Report

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

Project coverage is 98.41%. Comparing base (51b8d26) to head (244db0a). Report is 9 commits behind head on main.

Additional details and impacted files [![Impacted file tree graph](https://app.codecov.io/gh/stefmolin/data-morph/pull/203/graphs/tree.svg?width=650&height=150&src=pr&token=3SEEG9SZQO&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Stefanie+Molin)](https://app.codecov.io/gh/stefmolin/data-morph/pull/203?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Stefanie+Molin) ```diff @@ Coverage Diff @@ ## main #203 +/- ## ========================================== - Coverage 98.42% 98.41% -0.01% ========================================== Files 43 43 Lines 1775 1772 -3 Branches 358 357 -1 ========================================== - Hits 1747 1744 -3 Misses 25 25 Partials 3 3 ``` | [Files](https://app.codecov.io/gh/stefmolin/data-morph/pull/203?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Stefanie+Molin) | Coverage Δ | | |---|---|---| | [src/data\_morph/shapes/bases/line\_collection.py](https://app.codecov.io/gh/stefmolin/data-morph/pull/203?src=pr&el=tree&filepath=src%2Fdata_morph%2Fshapes%2Fbases%2Fline_collection.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Stefanie+Molin#diff-c3JjL2RhdGFfbW9ycGgvc2hhcGVzL2Jhc2VzL2xpbmVfY29sbGVjdGlvbi5weQ==) | `92.68% <100.00%> (+0.37%)` | :arrow_up: | | [src/data\_morph/shapes/bases/shape.py](https://app.codecov.io/gh/stefmolin/data-morph/pull/203?src=pr&el=tree&filepath=src%2Fdata_morph%2Fshapes%2Fbases%2Fshape.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Stefanie+Molin#diff-c3JjL2RhdGFfbW9ycGgvc2hhcGVzL2Jhc2VzL3NoYXBlLnB5) | `100.00% <100.00%> (ø)` | | | [src/data\_morph/shapes/circles.py](https://app.codecov.io/gh/stefmolin/data-morph/pull/203?src=pr&el=tree&filepath=src%2Fdata_morph%2Fshapes%2Fcircles.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Stefanie+Molin#diff-c3JjL2RhdGFfbW9ycGgvc2hhcGVzL2NpcmNsZXMucHk=) | `94.33% <100.00%> (+0.46%)` | :arrow_up: | ... and [4 files with indirect coverage changes](https://app.codecov.io/gh/stefmolin/data-morph/pull/203/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Stefanie+Molin)