Published September 2, 2023
| Version v0.7.0
Software
Open
ASEM000/PyTreeClass: v0.7.0
Description
Changelog v0.7
- Remove
.at
as an alias for__getitem__
when specifying a path entry for where inAtIndexer
. This leads to less verbose style.
Example:
>>> tree = {"level1_0": {"level2_0": 100, "level2_1": 200}, "level1_1": 300}
>>> tree = pytc.AtIndexer(tree)
>>> # Before:
>>> # style 1 (with at):
>>> tree.at["level1_0"].at["level2_0", "level2_1"].get()
{'level1_0': {'level2_0': 100, 'level2_1': 200}, 'level1_1': None}
>>> # style 2 (no at):
>>> tree["level1_0"]["level2_0", "level2_1"].get()
>>> # After
>>> # only style 2 is valid
>>> tree["level1_0"]["level2_0", "level2_1"].get()
For TreeClass
at
is specified once for each change
@pytc.autoinit
class Tree(pytc.TreeClass):
a: float = 1.0
b: tuple[float, float] = (2.0, 3.0)
c: jax.Array = jnp.array([4.0, 5.0, 6.0])
def __call__(self, x):
return self.a + self.b[0] + self.c + x
tree = Tree()
mask = jax.tree_map(lambda x: x > 5, tree)
tree = tree\
.at["a"].set(100.0)\
- .at["b"].at[0].set(10.0)\
+ .at["b"][0].set(10.0)\
.at[mask].set(100.0)
Files
ASEM000/PyTreeClass-v0.7.0.zip
Files
(453.4 kB)
Name | Size | Download all |
---|---|---|
md5:097883ec5e54a8c42f536b2281a2c71e
|
453.4 kB | Preview Download |
Additional details
Related works
- Is supplement to
- https://github.com/ASEM000/PyTreeClass/tree/v0.7.0 (URL)