[Scipy-svn] r5588 - trunk/scipy/integrate
scipy-svn at scipy.org
scipy-svn at scipy.org
Mon Feb 23 00:02:59 EST 2009
Author: rkern
Date: 2009-02-22 23:02:34 -0600 (Sun, 22 Feb 2009)
New Revision: 5588
Modified:
trunk/scipy/integrate/ode.py
Log:
ENH: style. Use warnings instead of prints. Move up imports, unguarded by try: excepts:.
Modified: trunk/scipy/integrate/ode.py
===================================================================
--- trunk/scipy/integrate/ode.py 2009-02-22 12:34:06 UTC (rev 5587)
+++ trunk/scipy/integrate/ode.py 2009-02-23 05:02:34 UTC (rev 5588)
@@ -147,9 +147,13 @@
__version__ = "$Id$"
__docformat__ = "restructuredtext en"
+import re
+import warnings
+
from numpy import asarray, array, zeros, int32, isscalar
-import re, sys
+import vode as _vode
+
#------------------------------------------------------------------------------
# User interface
#------------------------------------------------------------------------------
@@ -232,13 +236,15 @@
----------
name : str
Name of the integrator
- integrator_params
+ integrator_params :
Additional parameters for the integrator.
"""
integrator = find_integrator(name)
if integrator is None:
- print 'No integrator name match with %s or is not available.'\
- %(`name`)
+ # FIXME: this really should be raise an exception. Will that break
+ # any code?
+ warnings.warn('No integrator name match with %r or is not '
+ 'available.' % name)
else:
self._integrator = integrator(**integrator_params)
if not len(self.y):
@@ -262,8 +268,10 @@
def successful(self):
"""Check if integration was successful."""
- try: self._integrator
- except AttributeError: self.set_integrator('')
+ try:
+ self._integrator
+ except AttributeError:
+ self.set_integrator('')
return self._integrator.success==1
def set_f_params(self,*args):
@@ -284,7 +292,7 @@
for cl in IntegratorBase.integrator_classes:
if re.match(name,cl.__name__,re.I):
return cl
- return
+ return None
class IntegratorBase(object):
@@ -322,11 +330,7 @@
#XXX: __str__ method for getting visual state of the integrator
class vode(IntegratorBase):
- try:
- import vode as _vode
- except ImportError:
- print sys.exc_value
- _vode = None
+
runner = getattr(_vode,'dvode',None)
messages = {-1:'Excess work done on this call. (Perhaps wrong MF.)',
@@ -353,9 +357,12 @@
first_step = 0.0, # determined by solver
):
- if re.match(method,r'adams',re.I): self.meth = 1
- elif re.match(method,r'bdf',re.I): self.meth = 2
- else: raise ValueError,'Unknown integration method %s'%(method)
+ if re.match(method,r'adams',re.I):
+ self.meth = 1
+ elif re.match(method,r'bdf',re.I):
+ self.meth = 2
+ else:
+ raise ValueError('Unknown integration method %s' % method)
self.with_jacobian = with_jacobian
self.rtol = rtol
self.atol = atol
@@ -409,7 +416,7 @@
elif mf in [24,25]:
lrw = 22 + 11*n + (3*self.ml+2*self.mu)*n
else:
- raise ValueError,'Unexpected mf=%s'%(mf)
+ raise ValueError('Unexpected mf=%s' % mf)
if miter in [0,3]:
liw = 30
else:
@@ -434,7 +441,7 @@
def run(self,*args):
y1,t,istate = self.runner(*(args[:5]+tuple(self.call_args)+args[5:]))
if istate <0:
- print 'vode:',self.messages.get(istate,'Unexpected istate=%s'%istate)
+ warnings.warn('vode: ' + self.messages.get(istate,'Unexpected istate=%s'%istate))
self.success = 0
else:
self.call_args[3] = 2 # upgrade istate from 1 to 2
@@ -454,16 +461,11 @@
self.call_args[2] = itask
return r
-if vode.runner:
+if vode.runner is not None:
IntegratorBase.integrator_classes.append(vode)
class zvode(vode):
- try:
- import vode as _vode
- except ImportError:
- print sys.exc_value
- _vode = None
runner = getattr(_vode,'zvode',None)
supports_run_relax = 1
@@ -553,12 +555,12 @@
def run(self,*args):
y1,t,istate = self.runner(*(args[:5]+tuple(self.call_args)+args[5:]))
if istate < 0:
- print 'zvode:', self.messages.get(istate,
- 'Unexpected istate=%s'%istate)
+ warnings.warn('zvode: ' +
+ self.messages.get(istate, 'Unexpected istate=%s'%istate))
self.success = 0
else:
self.call_args[3] = 2 # upgrade istate from 1 to 2
return y1, t
-if zvode.runner:
+if zvode.runner is not None:
IntegratorBase.integrator_classes.append(zvode)
More information about the Scipy-svn
mailing list