diff --git a/doc/sphinx/source/markup.py b/doc/sphinx/source/markup.py index 16599faf..43d271b3 100644 --- a/doc/sphinx/source/markup.py +++ b/doc/sphinx/source/markup.py @@ -113,7 +113,7 @@ def mark_solvers(): elif solver[1] == "DAE_OVER": file.write(' mod = '+problem_name+'(res, y0, yd0, t0)\n\n') else: - print "Unknown solver type" + print("Unknown solver type") file.write('.. note::\n\n') file.write(' For complex problems, it is recommended to check the available :doc:`examples ` and the documentation in the problem class, :class:`'+problem_name+ ' `. It is also recommended to define your problem as a subclass of :class:`'+problem_name+ ' `.\n\n') file.write('.. warning::\n\n') diff --git a/setup.py b/setup.py index 28673e68..bf61545a 100644 --- a/setup.py +++ b/setup.py @@ -15,14 +15,15 @@ # You should have received a copy of the GNU Lesser General Public License # along with this program. If not, see . #from distutils.core import setup, Extension -import numpy as np import logging import sys import os -import shutil as SH +import shutil import ctypes.util import argparse from os.path import isfile, join +import numpy as np +import numpy.distutils.core as ndc def str2bool(v): return v.lower() in ("yes", "true", "t", "1") @@ -76,7 +77,7 @@ def remove_prefix(name, prefix): import numpy.distutils as nd try: - from Cython.Distutils import build_ext + # from Cython.Distutils import build_ext ## TODO: obsolete? from Cython.Build import cythonize except ImportError: msg="Please upgrade to a newer Cython version, >= 0.18." @@ -105,7 +106,7 @@ def create_dir(self,d): def copy_file(self,fi, to_dir): # copies only files not directories if not os.path.isdir(fi): - SH.copy2(fi, to_dir) + shutil.copy2(fi, to_dir) def copy_all_files(self,file_list, from_dir, to_dir): logging.debug('fromdir {} todir {}'.format(from_dir,to_dir)) for f in file_list: @@ -114,8 +115,8 @@ def copy_all_files(self,file_list, from_dir, to_dir): else: self.copy_file(f,to_dir) def __init__(self,args, thirdparty_methods): - # args[0] are optinal arguments given above - # args[1] are argumenets passed to distutils + # args[0] are optional arguments given above + # args[1] are arguments passed to distutils self.distutil_args=args[1] if args[0].prefix: self.prefix = args[0].prefix.replace('/',os.sep) # required in this way for cygwin etc. @@ -167,10 +168,11 @@ def fortran_compiler_flags(self): nd.fcompiler.intel.IntelVisualFCompiler.get_flags=fortran_compiler_flags self.platform = 'linux' - if 'win' in sys.platform: self.platform = 'win' - if 'darwin' in sys.platform: self.platform = 'mac' + if 'win' in sys.platform: + self.platform = 'win' + if 'darwin' in sys.platform: + self.platform = 'mac' - self.is_python3 = True if sys.version_info.major >= 3 else False logging.debug('Platform {}'.format(self.platform)) if args[0].sundials_home: @@ -241,8 +243,9 @@ def create_assimulo_dirs_and_populate(self): for f in self.filelist_thirdparty.items(): logging.debug('Thirdparty method {} file {} copied'.format(f[0],f[1])) self.copy_all_files(f[1],os.path.join("thirdparty", f[0]), self.desThirdParty[f[0]]) + license_name = f[0].upper() if f[0].upper() != "RADAU5" else "HAIRER" try: - SH.copy2(os.path.join("thirdparty",f[0],"LICENSE_{}".format(f[0].upper())),self.desLib) + shutil.copy2(os.path.join("thirdparty", f[0], "LICENSE_{}".format(license_name)), self.desLib) except IOError: logging.warning('No license file {} found.'.format("LICENSE_{}".format(f[0].upper()))) @@ -262,8 +265,8 @@ def create_assimulo_dirs_and_populate(self): if self.extra_fortran_link_files: for extra_fortran_lib in self.extra_fortran_link_files: path_extra_fortran_lib = ctypes.util.find_library(extra_fortran_lib) - if path_extra_fortran_lib != None: - SH.copy2(path_extra_fortran_lib,self.desSrc) + if path_extra_fortran_lib is not None: + shutil.copy2(path_extra_fortran_lib,self.desSrc) else: logging.debug("Could not find Fortran link file: "+str(extra_fortran_lib)) @@ -469,18 +472,24 @@ def cython_extensionlists(self): # Cythonize main modules ext_list = cythonize([os.path.join("assimulo", "explicit_ode.pyx")], - include_path=[".", "assimulo"], force = True) + include_path=[".", "assimulo"], + force = True, + compiler_directives={'language_level' : "3str"}) ext_list[-1].include_dirs += ["assimulo", self.incdirs] ext_list[-1].sources += [os.path.join("assimulo", "ode_event_locator.c")] remaining_pyx = ["algebraic", "implicit_ode", "ode", "problem", "special_systems", "support"] ext_list += cythonize([os.path.join("assimulo", "{}.pyx".format(x)) for x in remaining_pyx], - include_path=[".", "assimulo"], force = True) + include_path=[".", "assimulo"], + force = True, + compiler_directives={'language_level' : "3str"}) # Cythonize Solvers # Euler ext_list += cythonize([os.path.join("assimulo", "solvers", "euler.pyx")], - include_path=[".", "assimulo", os.path.join("assimulo", "solvers")], force = True) + include_path=[".", "assimulo", os.path.join("assimulo", "solvers")], + force = True, + compiler_directives={'language_level' : "3str"},) # SUNDIALS if self.with_SUNDIALS: @@ -491,7 +500,9 @@ def cython_extensionlists(self): #CVode and IDA ext_list += cythonize(["assimulo" + os.path.sep + "solvers" + os.path.sep + "sundials.pyx"], include_path=[".","assimulo","assimulo" + os.sep + "lib"], - compile_time_env=compile_time_env, force=True) + compile_time_env=compile_time_env, + force=True, + compiler_directives={'language_level' : "3str"}) ext_list[-1].include_dirs = [np.get_include(), "assimulo","assimulo"+os.sep+"lib", self.incdirs] ext_list[-1].library_dirs = [self.libdirs] @@ -510,7 +521,9 @@ def cython_extensionlists(self): #Kinsol ext_list += cythonize(["assimulo"+os.path.sep+"solvers"+os.path.sep+"kinsol.pyx"], include_path=[".","assimulo","assimulo"+os.sep+"lib"], - compile_time_env=compile_time_env, force=True) + compile_time_env=compile_time_env, + force=True, + compiler_directives={'language_level' : "3str"}) ext_list[-1].include_dirs = [np.get_include(), "assimulo","assimulo"+os.sep+"lib", self.incdirs] ext_list[-1].library_dirs = [self.libdirs] ext_list[-1].libraries = ["sundials_kinsol", "sundials_nvecserial"] @@ -523,7 +536,8 @@ def cython_extensionlists(self): ## Radau5 ext_list += cythonize([os.path.join("assimulo","thirdparty","radau5","radau5ode.pyx")], include_path=[".", "assimulo", os.path.join("assimulo", "lib")], - force = True) + force = True, + compiler_directives={'language_level' : "3str"}) ext_list[-1].include_dirs = [np.get_include(), "assimulo", os.path.join("assimulo", "lib"), os.path.join("assimulo","thirdparty","radau5"), self.incdirs] @@ -573,8 +587,7 @@ def cython_extensionlists(self): el.extra_compile_args += self.flag_32bit + self.extra_c_flags for el in ext_list: - if self.is_python3: - el.cython_directives = {"language_level": 3} + # el.cython_directives = {"language_level": "3str"} ## TODO: Redundant? el.extra_link_args += extra_link_flags return ext_list @@ -718,7 +731,6 @@ def fortran_extensionlists(self): for pck in thirdparty_methods for place in ['thirdparty','lib']] logging.debug(license_info) -import numpy.distutils.core as ndc ndc.setup(name=NAME, version=VERSION, license=LICENSE, @@ -741,4 +753,3 @@ def fortran_extensionlists(self): if change_dir: os.chdir(curr_dir) #Change back to original directory - diff --git a/src/__init__.py b/src/__init__.py index 105fcf13..2e8794cd 100644 --- a/src/__init__.py +++ b/src/__init__.py @@ -30,7 +30,7 @@ def wrap(func): try: import os - curr_dir = os.path.dirname(os.path.abspath(__file__)); + curr_dir = os.path.dirname(os.path.abspath(__file__)) _fpath=os.path.join(curr_dir,'version.txt') with open(_fpath, 'r') as f: __version__=f.readline().strip() diff --git a/src/algebraic.pyx b/src/algebraic.pyx index 1181abdb..e8d33ddf 100644 --- a/src/algebraic.pyx +++ b/src/algebraic.pyx @@ -15,6 +15,8 @@ # You should have received a copy of the GNU Lesser General Public License # along with this program. If not, see . +# distutils: define_macros=NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION + import numpy as N cimport numpy as N from timeit import default_timer as timer diff --git a/src/explicit_ode.pyx b/src/explicit_ode.pyx index 741ccc7b..4881c18f 100644 --- a/src/explicit_ode.pyx +++ b/src/explicit_ode.pyx @@ -15,6 +15,8 @@ # You should have received a copy of the GNU Lesser General Public License # along with this program. If not, see . +# distutils: define_macros=NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION + from ode cimport ODE from problem import Explicit_Problem, Delay_Explicit_Problem, SingPerturbed_Problem, cExplicit_Problem @@ -48,7 +50,7 @@ cdef void c2py_d(N.ndarray[double, ndim=1, mode='c'] dest, double* source, int d """Copy (double *) C vector to 1D numpy array.""" memcpy(N.PyArray_DATA(dest), source, dim*sizeof(double)) -cdef int callback_event(int n_y, int n_g, double t, double* y_in, double* g_out, void* f_event_EXT): +cdef int callback_event(int n_y, int n_g, double t, double* y_in, double* g_out, void* f_event_EXT) noexcept: """Event indicator callback function to event_locator.c""" cdef N.ndarray[double, ndim=1, mode="c"]y_py = N.empty(n_y, dtype = N.double) c2py_d(y_py, y_in, n_y) @@ -58,7 +60,7 @@ cdef int callback_event(int n_y, int n_g, double t, double* y_in, double* g_out, py2c_d(g_out, g_high, n_g) return ret -cdef int callback_interp(int n, double t, double* y_out, void* f_interp_EXT): +cdef int callback_interp(int n, double t, double* y_out, void* f_interp_EXT) noexcept: """Interpolation callback function to event_locator.c""" y_interp = (f_interp_EXT)(t) py2c_d(y_out, y_interp, n) diff --git a/src/implicit_ode.pyx b/src/implicit_ode.pyx index e22b26f7..bfee9af7 100644 --- a/src/implicit_ode.pyx +++ b/src/implicit_ode.pyx @@ -15,6 +15,8 @@ # You should have received a copy of the GNU Lesser General Public License # along with this program. If not, see . +# distutils: define_macros=NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION + from ode cimport ODE from problem import Implicit_Problem, cImplicit_Problem, Overdetermined_Problem from problem import cExplicit_Problem diff --git a/src/lib/sundials_callbacks_ida_cvode.pxi b/src/lib/sundials_callbacks_ida_cvode.pxi index 366c3e24..b9a07820 100644 --- a/src/lib/sundials_callbacks_ida_cvode.pxi +++ b/src/lib/sundials_callbacks_ida_cvode.pxi @@ -16,6 +16,7 @@ # along with this program. If not, see . import cython +import traceback from assimulo.exception import AssimuloRecoverableError cdef int cv_rhs(realtype t, N_Vector yv, N_Vector yvdot, void* problem_data): @@ -750,11 +751,11 @@ cdef void cv_err(int error_code, const char *module, const char *function, char cdef ProblemData pData = problem_data if error_code > 0 and pData.verbose > 0: #Warning - print '[CVode Warning]', msg + print('[CVode Warning]', msg) if pData.verbose > 2: #Verbosity is greater than NORMAL, print warnings and errors if error_code < 0: #Error - print '[CVode Error]', msg + print('[CVode Error]', msg) cdef void ida_err(int error_code, const char *module, const char *function, char *msg, void *problem_data): """ @@ -763,11 +764,11 @@ cdef void ida_err(int error_code, const char *module, const char *function, char cdef ProblemData pData = problem_data if error_code > 0 and pData.verbose > 0: #Warning - print '[IDA Warning]', msg + print('[IDA Warning]', msg) if pData.verbose > 2: #Verbosity is greater than NORMAL, print warnings and errors if error_code < 0: #Error - print '[IDA Error]', msg + print('[IDA Error]', msg) cdef class ProblemData: diff --git a/src/lib/sundials_callbacks_kinsol.pxi b/src/lib/sundials_callbacks_kinsol.pxi index fc730356..db2a17d1 100644 --- a/src/lib/sundials_callbacks_kinsol.pxi +++ b/src/lib/sundials_callbacks_kinsol.pxi @@ -16,6 +16,7 @@ # along with this program. If not, see . import cython +import traceback from assimulo.exception import AssimuloRecoverableError IF SUNDIALS_VERSION >= (3,0,0): @@ -229,9 +230,9 @@ cdef void kin_err(int err_code, const char *module, const char *function, char * else: category = 0 - print "Error occured in ."%function - print ""%msg - #print ""%(fnorm, snorm, pData.TOL) + print("Error occured in ."%function) + print(""%msg) + #print(""%(fnorm, snorm, pData.TOL)) cdef void kin_info(const char *module, const char *function, char *msg, void *eh_data): @@ -246,8 +247,8 @@ cdef void kin_info(const char *module, const char *function, char *msg, void *eh pData.log.append([module, function, msg]) - #print "KinsolInfo "%function - #print ""%msg + #print("KinsolInfo "%function) + #print(""%msg) """ # Get the number of iterations KINGetNumNonlinSolvIters(kin_mem, &nniters) @@ -262,9 +263,9 @@ cdef void kin_info(const char *module, const char *function, char *msg, void *eh if ("KINSolInit" in function or "KINSol" in function) and "nni" in msg: - print ""%nniters - print "ivs", N_VGetArrayPointer(kin_mem->kin_uu), block->n); - print "", kin_mem->kin_fnorm); + print(""%nniters) + print("ivs", N_VGetArrayPointer(kin_mem->kin_uu), block->n)) + print("", kin_mem->kin_fnorm)) print "residuals", realtype* f = N_VGetArrayPointer(kin_mem->kin_fval); f[i]*residual_scaling_factors[i] diff --git a/src/ode.pyx b/src/ode.pyx index 8bd333fb..915a9224 100644 --- a/src/ode.pyx +++ b/src/ode.pyx @@ -15,6 +15,8 @@ # You should have received a copy of the GNU Lesser General Public License # along with this program. If not, see . +# distutils: define_macros=NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION + import numpy as N cimport numpy as N from timeit import default_timer as timer @@ -555,9 +557,9 @@ cdef class ODE: """ cdef i = 0 for i in self.event_data: - print 'Time, t = %e'%i[0] - print ' Event info, ', i[1] - print 'Number of events: ', len(self.event_data) + print('Time, t = %e'%i[0]) + print('Event info, ', i[1]) + print('Number of events: ', len(self.event_data)) def print_statistics(self, verbose=NORMAL): """ diff --git a/src/problem.pyx b/src/problem.pyx index 45572267..a65ac01f 100644 --- a/src/problem.pyx +++ b/src/problem.pyx @@ -15,6 +15,8 @@ # You should have received a copy of the GNU Lesser General Public License # along with this program. If not, see . +# distutils: define_macros=NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION + import numpy as N cimport numpy as N diff --git a/src/solvers/euler.pyx b/src/solvers/euler.pyx index 6f7e0c5f..7f696b69 100644 --- a/src/solvers/euler.pyx +++ b/src/solvers/euler.pyx @@ -15,6 +15,8 @@ # You should have received a copy of the GNU Lesser General Public License # along with this program. If not, see . +# distutils: define_macros=NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION + cimport numpy as N import numpy as N import numpy.linalg as LIN @@ -363,7 +365,8 @@ cdef class ImplicitEuler(Explicit_ODE): """ This calculates the next step in the integration. """ - cdef double new_norm, old_norm + cdef double new_norm = 0 + cdef double old_norm = 0 cdef double tn1 = t+h cdef N.ndarray yn = y.copy() #Old y #cdef N.ndarray yn1 = y.copy() #First newton guess diff --git a/src/solvers/kinsol.pyx b/src/solvers/kinsol.pyx index c0dbaac5..11bc7c46 100644 --- a/src/solvers/kinsol.pyx +++ b/src/solvers/kinsol.pyx @@ -423,7 +423,7 @@ cdef class KINSOL(Algebraic): if flag < 0: raise KINSOLError(flag) if flag == KIN_STEP_LT_STPTOL: - print 'Scaled step length too small. Either an approximate solution or a local minimum is reached. Check value of residual.' + print('Scaled step length too small. Either an approximate solution or a local minimum is reached. Check value of residual.') self.store_statistics() diff --git a/src/solvers/odepack.py b/src/solvers/odepack.py index 8dc25fef..ff6c175e 100644 --- a/src/solvers/odepack.py +++ b/src/solvers/odepack.py @@ -186,7 +186,7 @@ def integrate_start(self, t, y): """ Helper program for the initialization of LSODAR """ - #print ' We have rkstarter {} and rkstarter_active {}'.format(self.rkstarter, self._rkstarter_active) + #print('We have rkstarter {} and rkstarter_active {}'.format(self.rkstarter, self._rkstarter_active)) if not(self.rkstarter>1 and self._rkstarter_active): # first call or classical restart after a discontinuity ISTATE=1 @@ -409,7 +409,7 @@ def state_events(t,y): opts["output_index"] = output_index # deciding on restarting options self._rkstarter_active = True if ISTATE == 3 and self.rkstarter > 1 else False - #print 'rkstarter_active set to {} and ISTATE={}'.format(self._rkstarter_active, ISTATE) + #print('rkstarter_active set to {} and ISTATE={}'.format(self._rkstarter_active, ISTATE)) #Retrieving statistics self.statistics["nstatefcns"] += IWORK[9] diff --git a/src/solvers/radar5.py b/src/solvers/radar5.py index da52c56a..7f2f10e5 100644 --- a/src/solvers/radar5.py +++ b/src/solvers/radar5.py @@ -113,9 +113,9 @@ def _solout(self,nr, told, t, hold, y, cont,irtrn): """ This method is called after every successful step taken by Radar5 """ - #print "SOLOUT:", told, t, hold, y, cont -# print cont -# print told, t, told + hold + # print("SOLOUT:", told, t, hold, y, cont) + # print(cont) + # print(told, t, told + hold) if self._opts["output_list"] is None: self._tlist.append(t) self._ylist.append(y.copy()) @@ -207,7 +207,7 @@ def compute_ydelay(self, t, y, past, ipast): return ydelay def F(self, t, y, past, ipast): - #print 'F:', t, y, past, ipast + #print('F:', t, y, past, ipast) # First find the correct place in the past vector for each time-lag # then evaluate all required solution components at that point @@ -277,8 +277,8 @@ def integrate(self, t, y, tf, opts): #Store the opts self._opts = opts - #print "INIT", t,y,tf,self.inith, self.problem.ipast - #print "GRID", self.problem.grid, self.problem.ngrid + #print("INIT", t,y,tf,self.inith, self.problem.ipast) + #print("GRID", self.problem.grid, self.problem.ngrid) #t, y, h, iwork, flag, past = radar5.assimulo_radar5(self.F, \ a = radar5.assimulo_radar5(self.F, \ self.problem.phi, \ diff --git a/src/solvers/sdirk_dae.pyx b/src/solvers/sdirk_dae.pyx index 5e748f31..67f6c9ae 100644 --- a/src/solvers/sdirk_dae.pyx +++ b/src/solvers/sdirk_dae.pyx @@ -154,7 +154,7 @@ class SDIRK_DAE(Implicit_ODE): f_extra_args = rhs_extra_args, g_extra_args = g_extra_args) hu, nqu ,nq ,nyh, nqnyh = get_lsod_common() - #print 't= {}, tN={}, y={}, ns={}, hu={}'.format(t , RWORK[12], y, RWORK[nordsieck_start_index],hu) + #print('t= {}, tN={}, y={}, ns={}, hu={}'.format(t , RWORK[12], y, RWORK[nordsieck_start_index],hu)) self._nordsieck_array = \ RWORK[nordsieck_start_index:nordsieck_start_index+(nq+1)*nyh].reshape((nyh,-1),order='F') self._nyh = nyh @@ -212,7 +212,7 @@ class SDIRK_DAE(Implicit_ODE): opts["output_index"] = output_index # deciding on restarting options self._rkstarter_active = True if ISTATE == 3 and self.rkstarter > 1 else False - #print 'rkstarter_active set to {} and ISTATE={}'.format(self._rkstarter_active, ISTATE) + #print('rkstarter_active set to {} and ISTATE={}'.format(self._rkstarter_active, ISTATE)) #Retrieving statistics self.statistics["ng"] += IWORK[9] diff --git a/src/solvers/sundials.pyx b/src/solvers/sundials.pyx index 85aa459b..8b0743d2 100644 --- a/src/solvers/sundials.pyx +++ b/src/solvers/sundials.pyx @@ -15,14 +15,14 @@ # You should have received a copy of the GNU Lesser General Public License # along with this program. If not, see . +# distutils: define_macros=NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION + import numpy as N cimport numpy as N from numpy cimport PyArray_DATA N.import_array() -import numpy.linalg -import traceback import scipy.sparse as sparse from assimulo.exception import AssimuloException diff --git a/src/special_systems.pyx b/src/special_systems.pyx index 0dd2815a..24f52853 100644 --- a/src/special_systems.pyx +++ b/src/special_systems.pyx @@ -15,6 +15,8 @@ # You should have received a copy of the GNU Lesser General Public License # along with this program. If not, see . +# distutils: define_macros=NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION + import assimulo.problem as ap from assimulo.support import set_type_shape_array import numpy as N diff --git a/src/support.pyx b/src/support.pyx index 6d5c96c2..04d20716 100644 --- a/src/support.pyx +++ b/src/support.pyx @@ -15,6 +15,8 @@ # You should have received a copy of the GNU Lesser General Public License # along with this program. If not, see . +# distutils: define_macros=NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION + import numpy as N cimport numpy as N diff --git a/thirdparty/radau5/radau5ode.pxd b/thirdparty/radau5/radau5ode.pxd index e89e1277..8fd607de 100644 --- a/thirdparty/radau5/radau5ode.pxd +++ b/thirdparty/radau5/radau5ode.pxd @@ -20,10 +20,10 @@ cdef extern from "string.h": cdef extern from "radau5_impl.h": ## FunctionPointer_CallBack - ctypedef int (*FP_CB_f)(int, double, double*, double*, void*) - ctypedef int (*FP_CB_jac)(int, double, double*, double*, void*) - ctypedef int (*FP_CB_solout)(int, double, double*, double*, double*, int, void*) - ctypedef int (*FP_CB_jac_sparse)(int, double, double*, int*, double*, int*, int*, void*) + ctypedef int (*FP_CB_f)(int, double, double*, double*, void*) except? -1 + ctypedef int (*FP_CB_jac)(int, double, double*, double*, void*) except? -1 + ctypedef int (*FP_CB_solout)(int, double, double*, double*, double*, int, void*) except? -1 + ctypedef int (*FP_CB_jac_sparse)(int, double, double*, int*, double*, int*, int*, void*) except? -1 int RADAU_OK int RADAU_ERROR_CALLBACK_RECOVERABLE diff --git a/thirdparty/radau5/radau5ode.pyx b/thirdparty/radau5/radau5ode.pyx index bb5cfab0..56c90e50 100644 --- a/thirdparty/radau5/radau5ode.pyx +++ b/thirdparty/radau5/radau5ode.pyx @@ -15,6 +15,8 @@ # You should have received a copy of the GNU Lesser General Public License # along with this program. If not, see . +# distutils: define_macros=NPY_NO_DEPRECATED_API=NPY_1_7_API_VERSION + cimport radau5ode # .pxd cimport cython @@ -26,7 +28,7 @@ from numpy cimport PyArray_DATA @cython.boundscheck(False) @cython.wraparound(False) -cdef void py2c_d(double* dest, object source, int dim): +cdef void py2c_d(double* dest, object source, int dim) noexcept: """ Copy 1D numpy (double) array to (double *) C vector """ @@ -37,7 +39,7 @@ cdef void py2c_d(double* dest, object source, int dim): @cython.boundscheck(False) @cython.wraparound(False) -cdef void py2c_d_matrix_flat_F(double* dest, object source, int nrow, int ncol): +cdef void py2c_d_matrix_flat_F(double* dest, object source, int nrow, int ncol) noexcept: """ Copy (square) 2D numpy array (order = c) to (double *) C matrix (with Fortran-style column major ordering) """ @@ -48,7 +50,7 @@ cdef void py2c_d_matrix_flat_F(double* dest, object source, int nrow, int ncol): @cython.boundscheck(False) @cython.wraparound(False) -cdef void c2py_d(np.ndarray[double, ndim=1, mode='c'] dest, double* source, int dim): +cdef void c2py_d(np.ndarray[double, ndim=1, mode='c'] dest, double* source, int dim) noexcept: """ Copy (double *) C vector to 1D numpy array """ @@ -56,7 +58,7 @@ cdef void c2py_d(np.ndarray[double, ndim=1, mode='c'] dest, double* source, int @cython.boundscheck(False) @cython.wraparound(False) -cdef void py2c_i(int* dest, object source, int dim): +cdef void py2c_i(int* dest, object source, int dim) noexcept: """ Copy 1D numpy (int) array to (int *) C vector """ @@ -65,7 +67,7 @@ cdef void py2c_i(int* dest, object source, int dim): assert source.size >= dim, "The dimension of the vector is {} and not equal to the problem dimension {}. Please verify the output vectors from the min/max/nominal/evalute methods in the Problem class.".format(source.size, dim) memcpy(dest, PyArray_DATA(source), dim*sizeof(int)) -cdef int callback_fcn(int n, double x, double* y_in, double* y_out, void* fcn_PY): +cdef int callback_fcn(int n, double x, double* y_in, double* y_out, void* fcn_PY) except? -1: """ Internal callback function to enable call to Python based rhs function from C """ @@ -77,7 +79,7 @@ cdef int callback_fcn(int n, double x, double* y_in, double* y_out, void* fcn_PY return ret[0] -cdef int callback_jac(int n, double x, double* y, double* fjac, void* jac_PY): +cdef int callback_jac(int n, double x, double* y, double* fjac, void* jac_PY) except? -1: """ Internal callback function to enable call to Python based Jacobian function from C """ @@ -92,7 +94,7 @@ cdef int callback_jac(int n, double x, double* y, double* fjac, void* jac_PY): return RADAU_OK cdef int callback_solout(int nrsol, double xosol, double *xsol, double* y, - double* werr, int n, void* solout_PY): + double* werr, int n, void* solout_PY) except? -1: """ Internal callback function to enable call to Python based solution output function from C """ @@ -105,7 +107,7 @@ cdef int callback_solout(int nrsol, double xosol, double *xsol, double* y, cdef int callback_jac_sparse(int n, double x, double *y, int *nnz, double *data, int *indices, int *indptr, - void* jac_PY): + void* jac_PY) except? -1: """Internal callback function to enable call to Python based evaluation of sparse (csc) jacobians.""" cdef np.ndarray[double, ndim=1, mode="c"]y_py = np.empty(n, dtype = np.double) c2py_d(y_py, y, n)