def _set_tolerances(self, atol=None, rtol=None): atol = np.array(atol) rtol = np.array(rtol) if atol.ndim == 1 and rtol.ndim == 0: atol = sunode.from_numpy(atol) check(lib.CVodeSVtolerances(self._ode, rtol, atol.c_ptr)) elif atol.ndim == 0 and rtol.ndim == 0: check(lib.CVodeSStolerances(self._ode, rtol, atol)) else: raise ValueError('Invalid tolerance.') self._atol = atol self._rtol = rtol
def tolerance(self, rtol: float, atol: Union[np.ndarray, float]) -> None: self.mark_changed() self._atol = np.array(atol) self._rtol = rtol if self._atol.ndim == 1: if not hasattr(self, '_atol_buffer'): self._atol_buffer = sunode.from_numpy(atol) self.borrow(self._atol_buffer) self._atol_buffer.data[:] = atol check( lib.CVodeSVtolerances(self.c_ptr, self._rtol, self._atol_buffer.c_ptr)) elif self._atol.ndim == 0: check(lib.CVodeSStolerances(self.c_ptr, self._rtol, self._atol)) else: raise ValueError('Invalid absolute tolerances.')