funkelab / motile

Multi-Object Tracker using Integer Linear Equations
https://funkelab.github.io/motile/
MIT License
24 stars 5 forks source link

Fix types and linting; formalize typing of Node ids and Edge ids #28

Closed tlambert03 closed 1 year ago

tlambert03 commented 1 year ago

This elaborates on the typing of Node and Edge ids, (and the keys that are valid when indexing into a variable).

Couple specific things to pay attention to:

  1. the Variable class becomes class Variable(ABC, Mapping[_KT, int]): ... by implementing items and keys, etc... Variable was close to implementing the Mapping interface. This makes it official, and parametrizes the key type that a variable manages. All a subclass needs to do now is:
    class NodeSelected(Variable[NodeId]):
        @staticmethod
        def instantiate(solver: Solver) -> Collection[NodeId]: ...

    and then it will be clear why the index type needs to be when someone indexes later after using get_variables

  2. This slightly relaxes the return type of instantiate_constraints from list to Iterable[ilpy.LinearConstraint]... Which means that instantiate_constraints() can now yield constraints (rather than having to build its own list which will then get iterated again in Solver._add_variables
tlambert03 commented 1 year ago

ready for review @funkey

codecov-commenter commented 1 year ago

Codecov Report

Merging #28 (261df1c) into main (b61f7a1) will decrease coverage by 0.45%. The diff coverage is 75.43%.

:mega: This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

@@            Coverage Diff             @@
##             main      #28      +/-   ##
==========================================
- Coverage   77.92%   77.48%   -0.45%     
==========================================
  Files          28       28              
  Lines         761      755       -6     
==========================================
- Hits          593      585       -8     
- Misses        168      170       +2     
Impacted Files Coverage Δ
motile/_types.py 0.00% <0.00%> (ø)
motile/costs/edge_selection.py 94.11% <ø> (ø)
motile/plot.py 0.00% <0.00%> (ø)
motile/variables/edge_selected.py 80.00% <80.00%> (-8.89%) :arrow_down:
motile/variables/node_selected.py 80.00% <80.00%> (-8.89%) :arrow_down:
motile/track_graph.py 86.20% <83.33%> (-1.44%) :arrow_down:
motile/variables/node_split.py 93.54% <85.71%> (-3.33%) :arrow_down:
motile/variables/node_appear.py 95.45% <88.88%> (-2.33%) :arrow_down:
motile/variables/variable.py 65.71% <91.66%> (-0.96%) :arrow_down:

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

funkey commented 1 year ago

Thanks a lot! :)