Skip to content

Commit 86fed93

Browse files
committed
Clarifying
1 parent 9cf06f1 commit 86fed93

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

stan/math/rev/constraint/sum_to_zero_constrain.hpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,15 @@ inline auto sum_to_zero_constrain(const T& y) {
4444
for (int i = 0; i < N; ++i) {
4545
double n = i + 1;
4646

47-
double u_adj = arena_z.adj()(i);
48-
sum_u_adj += u_adj;
47+
// adjoint of the reverse cumulative sum computed in the forward mode
48+
sum_u_adj += arena_z.adj()(i);
4949

50-
double v_adj = -arena_z.adj()(i + 1);
50+
// adjoint of the offset subtraction
51+
double v_adj = -arena_z.adj()(i + 1) * n;
5152

52-
double w = (v_adj * n) + sum_u_adj;
53+
double w_adj = v_adj + sum_u_adj;
5354

54-
arena_y.adj()(i) += w / sqrt(n * (n + 1));
55+
arena_y.adj()(i) += w_adj / sqrt(n * (n + 1));
5556
}
5657
});
5758

0 commit comments

Comments
 (0)