Zdot.set([2 * x * xdot + ydot, y * xdot + x * ydot]) def adj(self, (X, ), (Y, ), seeds, sens): assert (max_adj) x = X[0] y = X[1] Y.set([x**2 + y, x * y]) for ((Y_bar, ), (X_bar, )) in zip(seeds, sens): xb = Y_bar[0] yb = Y_bar[1] X_bar.set([2 * x * xb + y * yb, xb + x * yb]) c = PyFunction(Squares(), [Sparsity.dense(2, 1)], [Sparsity.dense(2, 1)]) if max_fwd and max_adj: c.setOption("ad_mode", "automatic") elif max_adj: c.setOption("ad_mode", "reverse") elif max_fwd: c.setOption("ad_mode", "forward") c.init() if not indirect: c.setInput([0.2, 0.6], 0) return c f = MXFunction([x], c.call([x])) f.init() f.setInput([0.2, 0.6], 0)
ydot = Xdot[1] Zdot.set([2*x*xdot+ydot,y*xdot+x*ydot]) def adj(self,(X,),(Y,),seeds,sens): assert(max_adj) x = X[0] y = X[1] Y.set([x**2+y,x*y]) for ((Y_bar,),(X_bar,)) in zip(seeds,sens): xb = Y_bar[0] yb = Y_bar[1] X_bar.set([2*x*xb+y*yb,xb+x*yb]) c = PyFunction(Squares(),[Sparsity.dense(2,1)], [Sparsity.dense(2,1)]) if max_adj and not max_fwd: c.setOption("ad_weight", 1) elif max_fwd and not max_adj: c.setOption("ad_weight", 0) c.init() if not indirect: c.setInput([0.2,0.6],0) return c f = MXFunction([x],c.call([x])) f.init() f.setInput([0.2,0.6],0) return f
ydot = Xdot[1] Zdot.set([2*x*xdot+ydot,y*xdot+x*ydot]) def adj(self,(X,),(Y,),seeds,sens): assert(max_adj) x = X[0] y = X[1] Y.set([x**2+y,x*y]) for ((Y_bar,),(X_bar,)) in zip(seeds,sens): xb = Y_bar[0] yb = Y_bar[1] X_bar.set([2*x*xb+y*yb,xb+x*yb]) c = PyFunction(Squares(),[Sparsity.dense(2,1)], [Sparsity.dense(2,1)]) if max_fwd and max_adj: c.setOption("ad_mode","automatic") elif max_adj: c.setOption("ad_mode","reverse") elif max_fwd: c.setOption("ad_mode","forward") c.init() if not indirect: c.setInput([0.2,0.6],0) return c f = MXFunction([x],c.call([x])) f.init() f.setInput([0.2,0.6],0)