ASEM000 / pytreeclass

Visualize, create, and operate on pytrees in the most intuitive way possible.
https://pytreeclass.rtfd.io/en/latest
Apache License 2.0
42 stars 2 forks source link

Match named leaves with regular expressions #70

Closed ASEM000 closed 1 year ago

ASEM000 commented 1 year ago

Example:

Update all leaves starting with weight_


import pytreeclass as pytc

class Tree(pytc.TreeClass):
    weight_1: float = 1.0
    weight_2: float = 2.0
    weight_3: float = 3.0
    bias: float = 0.0

tree = Tree()

tree.at[pytc.RegexKey(r"weight_.*")].set(100.0)
# Tree(weight_1=100.0, weight_2=100.0, weight_3=100.0, bias=0.0)
codecov[bot] commented 1 year ago

Codecov Report

Patch coverage: 100.00% and project coverage change: +0.01 :tada:

Comparison is base (d6762e1) 98.17% compared to head (696d2ac) 98.18%.

:exclamation: Current head 696d2ac differs from pull request most recent head 5a43e06. Consider uploading reports for the commit 5a43e06 to get more accurate results

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #70 +/- ## ========================================== + Coverage 98.17% 98.18% +0.01% ========================================== Files 13 13 Lines 2241 2260 +19 ========================================== + Hits 2200 2219 +19 Misses 41 41 ``` | [Impacted Files](https://app.codecov.io/gh/ASEM000/PyTreeClass/pull/70?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Mahmoud+Asem) | Coverage Δ | | |---|---|---| | [pytreeclass/\_\_init\_\_.py](https://app.codecov.io/gh/ASEM000/PyTreeClass/pull/70?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Mahmoud+Asem#diff-cHl0cmVlY2xhc3MvX19pbml0X18ucHk=) | `100.00% <100.00%> (ø)` | | | [pytreeclass/\_src/tree\_base.py](https://app.codecov.io/gh/ASEM000/PyTreeClass/pull/70?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Mahmoud+Asem#diff-cHl0cmVlY2xhc3MvX3NyYy90cmVlX2Jhc2UucHk=) | `98.36% <100.00%> (ø)` | | | [pytreeclass/\_src/tree\_util.py](https://app.codecov.io/gh/ASEM000/PyTreeClass/pull/70?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Mahmoud+Asem#diff-cHl0cmVlY2xhc3MvX3NyYy90cmVlX3V0aWwucHk=) | `98.34% <100.00%> (+0.05%)` | :arrow_up: | | [tests/test\_indexing.py](https://app.codecov.io/gh/ASEM000/PyTreeClass/pull/70?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Mahmoud+Asem#diff-dGVzdHMvdGVzdF9pbmRleGluZy5weQ==) | `99.77% <100.00%> (+<0.01%)` | :arrow_up: |

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Do you have feedback about the report comment? Let us know in this issue.