From b46c4a85f9a0e440c5df0ed17e68a0bb5df2b788 Mon Sep 17 00:00:00 2001 From: dokester Date: Tue, 5 Nov 2024 14:52:47 +0100 Subject: [PATCH] Adapt to Numpy2.0 etc --- BayesicFitting/source/BaseFitter.py | 4 ++-- BayesicFitting/source/Prior.py | 8 ++++---- BayesicFitting/source/RepeatingModel.py | 11 ++++++----- BayesicFitting/source/Tools.py | 25 ++++++++++++------------- README.md | 18 +++++------------- setup.py | 2 +- 6 files changed, 30 insertions(+), 38 deletions(-) diff --git a/BayesicFitting/source/BaseFitter.py b/BayesicFitting/source/BaseFitter.py index 1df7145..4082a88 100644 --- a/BayesicFitting/source/BaseFitter.py +++ b/BayesicFitting/source/BaseFitter.py @@ -14,7 +14,7 @@ __author__ = "Do Kester" __year__ = 2023 __license__ = "GPL3" -__version__ = "3.2.0" +__version__ = "3.2.2" __url__ = "https://www.bayesicfitting.nl" __status__ = "Perpetual Beta" @@ -334,7 +334,7 @@ def insertParameters( self, fitpar, index=None, into=None ) : if index is None : index = self.fitIndex - fitpar = numpy.array( fitpar, dtype=float, copy=False, ndmin=1 ) + fitpar = numpy.array( fitpar, dtype=float, ndmin=1 ) if index is None or len( fitpar ) == len( self.model.parameters ) : return fitpar diff --git a/BayesicFitting/source/Prior.py b/BayesicFitting/source/Prior.py index ca742f6..c910226 100644 --- a/BayesicFitting/source/Prior.py +++ b/BayesicFitting/source/Prior.py @@ -8,7 +8,7 @@ __author__ = "Do Kester" __year__ = 2024 __license__ = "GPL3" -__version__ = "3.2.1" +__version__ = "3.2.2" __url__ = "https://www.bayesicfitting.nl" __status__ = "Perpetual Beta" @@ -194,7 +194,7 @@ def setLimits( self, limits=None ): umax = self.domain2Unit( self.highLimit ) self._umin = self.domain2Unit( self.lowLimit ) self._urng = umax - self._umin - except : + except Exception : self._urng = math.inf # print( "Prior 3 ", self._umin, self._urng ) @@ -395,7 +395,7 @@ def hasLimits( self ): def getLimits( self ): """ Return the limits. """ - return numpy.array( [ self.lowLimit, self.highLimit ] ) + return numpy.asarray( [ self.lowLimit, self.highLimit ] ) def getIntegral( self ) : """ @@ -474,7 +474,7 @@ def logResult( self, p ) : """ try : return numpy.log( self.result( p ) ) - except : + except Exception : return -math.inf def numPartialDomain2Unit( self, dval ): diff --git a/BayesicFitting/source/RepeatingModel.py b/BayesicFitting/source/RepeatingModel.py index e22945a..d26922f 100644 --- a/BayesicFitting/source/RepeatingModel.py +++ b/BayesicFitting/source/RepeatingModel.py @@ -14,7 +14,7 @@ __author__ = "Do Kester" __year__ = 2024 __license__ = "GPL" -__version__ = "3.2.1" +__version__ = "3.2.2" __url__ = "https://www.bayesicfitting.nl" __status__ = "Perpetual Beta" @@ -204,9 +204,9 @@ def setSame( self, same ) : index = [] for k in range( self.model.npbase ) : - if not k in self.same : + if k not in self.same : index += [k] - self.index = numpy.array( index, dtype=int ) + self.index = numpy.asarray( index, dtype=int ) def grow( self, offset=0, rng=None, **kwargs ): """ @@ -348,7 +348,8 @@ def baseResult( self, xdata, params ): values for the parameters """ - result = numpy.zeros( Tools.length( xdata ), dtype=float ) +# result = numpy.zeros( Tools.length( xdata ), dtype=float ) + result = 0.0 if self.ncomp == 0 : return result @@ -499,7 +500,7 @@ def baseParameterName( self, k ): """ i,k = self.par2model( k ) return ( self.model.getParameterName( i ) + - ( "_%d" % k if not i in self.same else "" ) ) + ( "_%d" % k if i not in self.same else "" ) ) def baseParameterUnit( self, k ): """ diff --git a/BayesicFitting/source/Tools.py b/BayesicFitting/source/Tools.py index 52f4459..3511acd 100644 --- a/BayesicFitting/source/Tools.py +++ b/BayesicFitting/source/Tools.py @@ -13,7 +13,7 @@ __author__ = "Do Kester" __year__ = 2024 __license__ = "GPL3" -__version__ = "3.2.1" +__version__ = "3.2.2" __url__ = "https://www.bayesicfitting.nl" __status__ = "Perpetual Beta" @@ -257,14 +257,14 @@ def makeNext( x, k ) : """ try : _xnext = x[-1] - except : + except Exception : _xnext = x while True : try : _xnext = x[k] yield _xnext k += 1 - except : + except Exception : yield _xnext @@ -276,7 +276,7 @@ def length( x ) : return 0 try : return len( x ) - except : + except Exception : return 1 def toArray( x, ndim=1, dtype=None ) : @@ -295,7 +295,7 @@ def toArray( x, ndim=1, dtype=None ) : """ if isinstance( x, Table ) : return x - return numpy.array( x, dtype=dtype, copy=False, ndmin=min( ndim, 2 ) ) + return numpy.array( x, dtype=dtype, ndmin=min( ndim, 2 ) ) def isList( item, cls ) : """ @@ -352,7 +352,7 @@ def decorate( src, des, copy=True ) : if copy : try : value = value.copy() - except : + except Exception : pass object.__setattr__( des, key, value ) @@ -371,13 +371,13 @@ def subclassof( sub, cls ) : if not inspect.isclass( sub ) : return False - while sub != cls and sub != object : + while sub != cls and sub is not object : tre = inspect.getclasstree( [sub], unique=True ) sub = tre[0][0] return sub is cls -def printclass( cls, nitems=8 ) : +def printclass( cls, nitems=8, printId=False ) : """ Print the attributes of a class. """ @@ -388,8 +388,7 @@ def printclass( cls, nitems=8 ) : from .Problem import Problem print( "+++++++++++++++++++++++++++++++++++++++++++++++++++++++" ) -# print( cls, " at ", id( cls ) ) - print( cls ) + print( cls, " at ", id( cls ) ) if printId else print( cls ) print( "+++++++++++++++++++++++++++++++++++++++++++++++++++++++" ) atr = vars( cls ) ld = list( atr.keys() ) @@ -398,7 +397,7 @@ def printclass( cls, nitems=8 ) : print( "%-15.15s "%key, end="" ) val = atr[key] if isinstance( val, (list,numpy.ndarray) ) : - printlist( val ) + printlist( val, nitems=nitems ) elif isinstance( val, str ) : print( shortName( val ) ) elif isinstance( val, ( Model, Problem ) ) : @@ -414,7 +413,7 @@ def printclass( cls, nitems=8 ) : print( valstr.split()[0].split( '.' )[-1] ) else : print( valstr ) - except : + except Exception : print( val ) print( "+++++++++++++++++++++++++++++++++++++++++++++++++++++++" ) @@ -436,7 +435,7 @@ def printlist( val, nitems=8 ) : for k in range( min( nv, nitems ) ) : try : print( "%s%s"%(sep, val[k].__name__ ), end="" ) - except : + except Exception : print( "%s%s"%(sep, shortName( str( val[k] ) ) ), end="" ) sep = " " print( "%s" % ( ( "... ] %d" % nv ) if nitems < nv else "]" ) ) diff --git a/README.md b/README.md index 2f4eaee..719e149 100644 --- a/README.md +++ b/README.md @@ -1,24 +1,13 @@ --- --- -