braintools.tree.add

Contents

braintools.tree.add#

braintools.tree.add(tree1, tree2, is_leaf=<function is_quantity>)[source]#

Elementwise addition of PyTrees or a PyTree and a value.

Parameters:
  • tree1 (Quantity]) – Left operand.

  • tree2 (Quantity] | Array | ndarray | bool | number | bool | int | float | complex | Quantity) – Right operand. If a PyTree, its structure must match tree1 and corresponding leaves are added elementwise. If a value (scalar/array_like), it is broadcast to each leaf of tree1.

  • is_leaf (Callable[[Any], bool] | None) – Predicate to treat a node as a leaf during traversal. Defaults to u.math.is_quantity.

Returns:

PyTree with elementwise sums.

Return type:

PyTree

See also

sub

Elementwise subtraction of PyTrees.

mul

Elementwise multiplication.

shift

Add a single value to every leaf.