def get_jac(self): """ Return the jacobian of the expressions """ if self._jac is True: if self.band is None: f = self.be.Matrix(self.nf, 1, self.exprs) _x = self.be.Matrix(self.nx, 1, self.x) return f.jacobian(_x) else: # Banded return self.be.Matrix( banded_jacobian(self.exprs, self.x, *self.band)) elif self._jac is False: return False else: return self._jac
def get_jac(self): """ Return the jacobian of the expressions """ if self._jac is True: if self.band is None: f = self.be.Matrix(self.nf, 1, self.exprs) _x = self.be.Matrix(self.nx, 1, self.x) return f.jacobian(_x) else: # Banded return self.be.Matrix(banded_jacobian( self.exprs, self.x, *self.band)) elif self._jac is False: return False else: return self._jac
def banded_jac(self, t, y, Jout): from sym.util import banded_jacobian jac = banded_jacobian(self._f, self._y, self.n*self.n_jac_diags, self.n*self.n_jac_diags) width = 2*self.n*self.n_jac_diags + 1 if Jout.shape[0] == width: pad = 0 elif Jout.shape[0] == 3*self.n*self.n_jac_diags + 1: pad = self.n*self.n_jac_diags else: raise ValueError("Ill-shaped Jout") subsd = dict(zip(self._y, y)) for ri, ci in product(range(width), range(self.n*self.N)): Jout[ri + pad, ci] = sp.S(jac[ri, ci]).xreplace(subsd)