braintools.tree.dot#
- braintools.tree.dot(a, b, is_leaf=<function is_quantity>)[source]#
Inner product over all leaves of two PyTrees.
For each pair of corresponding leaves, compute the elementwise product, reduce with a full sum over all axes, and then sum across leaves.
- Parameters:
- Returns:
Scalar representing the inner product across the entire PyTree.
- Return type:
Array
See also
sumSum of all elements in a PyTree.
squared_normSum of squares of all elements (i.e., dot(x, x)).
Notes
Leaf arrays must be broadcast-compatible for multiplication.
When leaves carry units (brainunit quantities), units propagate through the multiplications and sums according to quantity rules.
Examples
>>> import jax.numpy as jnp >>> import braintools >>> tree = {'a': jnp.array([1.0, 2.0]), 'b': jnp.array([3.0])} >>> other = {'a': jnp.array([10.0, 20.0]), 'b': jnp.array([30.0])} >>> float(braintools.tree.dot(tree, other)) 140.0