Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove distinction between regex and string match key #14

Merged
merged 4 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 6 additions & 24 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,6 @@

## V0.11.4

- Add an option to select which argument to broadcast to in `bcmap`

```python
import sepes as sp
def func(x, y):
return x + y
# broadcast x to y structure
# this effectively converts 1 -> [1,1,1]
sp.bcmap(func, broadcast_to="y")(x=1, y=[2,3,4]) # [3,4,5]
# broadcast x to y structure (argnum=1)
sp.bcmap(func, broadcast_to=1)(1, [2,3,4]) # [3,4,5]
```

- Add sharding info in `tree_summary`, `G` for global, `S` for sharded shape.

```python
Expand All @@ -38,23 +25,18 @@
└────┴───────────┴─────┴───────┘
```

- Reduce the API footprint by removing:
- `tree_graph` (for graphviz visualization)
- `tree_mermaid` (mermaidjs visualization)
- `Partial/partial` -> Use `jax.tree_util.Partial` instead.
- Reduce the API and remove:
- `tree_graph` (for graphviz)
- `tree_mermaid` (mermaidjs)
- `Partial/partial` -> Use `jax.tree_util.partial` instead.
- `is_tree_equal` -> Use `bcmap(numpy.testing.assert_*)(pytree1, pytree2)` instead.
- `freeze` -> Use `ft.partial(tree_mask, lambda _: True)` instead.
- `unfreeze` -> Use `tree_unmask` instead.

- Implement `__format__` for `TreeClass` for shorter syntax representation:
- `f"{tree:3r}"` is tree **r**epr of depth = 3
- `f"{tree:3s}"` is tree **s**tr of depth = 3
- `f"{tree:3d}"` is tree **d**iagram of depth = 3
- `f"{tree:3t}`" is tree summary of depth = 3

- `tree_{mask,unmask}` now accepts only callable `cond` argument.
- Rename `is_frozen` to `is_masked`
- frozen could mean non-trainable array, however the masking is not only for arrays but also for other types that will be hidden from jax transformations.
- frozen could mean non-trainable array, however the masking is not only for arrays but also for other types that will be hidden across jax transformations.
- Remove `re.compile(pattern)` to match `re.Pattern` in `where` argument in `AtIndexer`, instead use string `pattern` directly.

## V0.11.3

Expand Down
7 changes: 2 additions & 5 deletions docs/API/core.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
.. autoclass:: TreeClass
:members:
at
.. autoclass:: AtIndexer
.. autoclass:: at
:members:
get,
set,
Expand All @@ -16,10 +16,7 @@
reduce,
pluck,

.. autoclass:: at
.. autoclass:: BaseKey
:members:
__eq__
.. autoclass:: AtIndexer
.. autofunction:: autoinit
.. autofunction:: leafwise
.. autofunction:: field
Expand Down
3 changes: 1 addition & 2 deletions sepes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from sepes._src.backend import backend_context
from sepes._src.code_build import autoinit, field, fields
from sepes._src.tree_base import TreeClass
from sepes._src.tree_index import AtIndexer, BaseKey, at
from sepes._src.tree_index import AtIndexer, at
from sepes._src.tree_mask import (
is_masked,
is_nondiff,
Expand Down Expand Up @@ -53,7 +53,6 @@
# indexing utils
"AtIndexer",
"at",
"BaseKey",
# tree utils
"bcmap",
"leafwise",
Expand Down
2 changes: 0 additions & 2 deletions sepes/_src/tree_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,6 @@ def at(self) -> AtIndexer[Self]:
- ``int`` for positional indexing for sequences.
- ``...`` to select all leaves.
- a boolean mask of the same structure as the tree
- ``re.Pattern`` to index all keys matching a regex pattern.
- an instance of ``BaseKey`` with custom logic to index a pytree.
- a tuple of the above types to index multiple keys at same level.

Example:
Expand Down
Loading
Loading