Hello Tarun,
AlgoPy stores the sequence of elementary functions in an instance of CGraph.
However, an if-then-else statement is **not** considered to be an elementary function.
So, AlgoPy will simply record the elementary functions that are performed when a **certain** control flow is executed.
In other words, AlgoPy won't know about the other possible control flows.
No matter what inputs you provide, cg.gradient will always execute the sequence of operations that were recorded when you traced the function.
You can output the sequence of operations by ```print cg```
Your options are:
1) use the forward mode, i.e., use the UTPM.init_jacobian and UTPM.extract_jacobian to compute the gradient. In that case, no computational graph is recorded, so the problem with the program branches does not exist.
2) Create two copies cg1, cg2, each one containing the computational graph of the particular control flow.
3) Extend AlgoPy to support control flows within the computational graph.
kind regards,
Sebastian