Replies: 1 comment
-
Does this resolve your issue? >>> import jax
>>> x = [1, 2, 3] # original pytree
>>> const = 4
>>> y = jax.tree_map(lambda _: const, x)
>>> print(y)
[4, 4, 4]
>>> # alternate approach if you only have the treedef
>>> x_treedef = jax.tree_structure(x)
>>> y_alternate = jax.tree_unflatten(x_treedef, [const] * x_treedef.num_leaves)
>>> print(y_alternate)
[4, 4, 4] |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
What's the correct way to build a second tree that broadcasts over a target level of the treedef?
I have the following tree
I'm trying to construct a new tree using
treedef
where all of the leaves, for eachDense_x
, has a constant value. I tried the following, but it returns aValueError
.Previously, I used this tree example.
I was able to construct my desired tree with the logic I tried above
tree_2
is given byWhat am I doing wrong?
Beta Was this translation helpful? Give feedback.
All reactions