Skip to content

Commit

Permalink
Update ad_support.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Routhleck committed Nov 22, 2024
1 parent dba2438 commit 2d0d136
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion brainpy/_src/math/op_register/ad_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,14 @@ def _standard_jvp(jvp_rules, primitive: Primitive, primals, tangents, **params):
r = tuple(rule(t, *primals, **params))
tangents_out.append(r)
assert tree_util.tree_structure(r) == tree
return val_out, functools.reduce(_add_tangents,
try:
return val_out, functools.reduce(_add_tangents,
tangents_out,
tree_util.tree_map(lambda a: ad.Zero.from_primal_value(a), val_out))
except:
return val_out, functools.reduce(_add_tangents,
tangents_out,
tree_util.tree_map(lambda a: ad.Zero.from_value(a), val_out))


def _add_tangents(xs, ys):
Expand Down

0 comments on commit 2d0d136

Please sign in to comment.