-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix derivative code for comma expressions in forward mode
Earlier for an expression like `(E1, E2)`, the derivative code produced `(dE1, dE2)`, thus a statement like `double temp = (++x, x*x)` produced: ```cpp double _d_temp = (_d_x, _d_x * x + x * _d_x); double temp = (++x, x*x); <--- original cloned statement ``` This meant that the execution order is `dE1 -> dE2 -> E1 -> E2` (where -> means followed by). But this doesn't seem right, as `dE2` can depend on `E1`; hence `E1` must be computed before `dE2`. So, the execution order should be `dE1 -> E1 -> dE2 -> E2`. This PR generates the derivative code as `(dE1, E1, dE2)`; the original statement is changed to just `E2`. Note that the result of both expressions is still the same as earlier (i.e. the derivative code will still have the result of `dE2`) So, the example statement of computing `(x+1)^2`, will produce: ```cpp double _d_temp = (_d_x, ++x , (_d_x * x + x * _d_x)); double temp = x*x; ``` closes #573
- Loading branch information
1 parent
702c90c
commit 8dbe639
Showing
2 changed files
with
72 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters