-
Notifications
You must be signed in to change notification settings - Fork 3
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
Adaptive BAL #330
Adaptive BAL #330
Conversation
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
pre-commit.ci autofix |
if self.return_raw: | ||
if self.strategy == "raw": | ||
(gb, gw), _ = jax.tree_util.tree_flatten(g_ll) | ||
|
||
# g: n_atoms, 3, n_features | ||
g = gw[:, :, :, 0] | ||
else: | ||
g_flat = jax.tree_map( | ||
elif self.strategy == "sum": | ||
g_summed = jax.tree_map( | ||
lambda arr: jnp.reshape(jnp.sum(jnp.sum(arr, 0), 0), (-1,)), g_ll | ||
) | ||
(gb, gw), _ = jax.tree_util.tree_flatten(g_flat) | ||
(gb, gw), _ = jax.tree_util.tree_flatten(g_summed) | ||
g = [gw, gb] | ||
g = jnp.concatenate(g) | ||
|
||
elif self.strategy == "flatten": | ||
g_flat = jax.tree_map(lambda arr: jnp.reshape(arr, (-1,)), g_ll) | ||
(gb, gw), _ = jax.tree_util.tree_flatten(g_flat) | ||
g = gw | ||
else: | ||
raise ValueError(f"unknown strategy: {self.strategy}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe doing that like:
def raw():
.
.
.
strategies = {"raw": raw}
.
.
.
if strategy in strategies:
g = strategies[strategy](g_ll)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the implementations of the different options is 19 lines of code, I don't think further abstraction is required.
This PR adds a few features: