braintools.tree.squared_norm#
- braintools.tree.squared_norm(tree, is_leaf=<function is_quantity>)[source]#
Sum of squares of all elements in a PyTree.
- Parameters:
- Returns:
Scalar representing
sum_i sum(x_i**2)across all leaves x_i.- Return type:
Array
See also
dotInner product across leaves.
Notes
Equivalent to
dot(tree, tree).Examples
>>> import jax.numpy as jnp >>> import braintools >>> tree = {'a': jnp.array([1.0, 2.0]), 'b': jnp.array([3.0])} >>> float(braintools.tree.squared_norm(tree)) 14.0