Skip to content

Commit

Permalink
Adapt to Numpy2.0 etc
Browse files Browse the repository at this point in the history
  • Loading branch information
dokester committed Nov 5, 2024
1 parent 59d4792 commit b46c4a8
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 38 deletions.
4 changes: 2 additions & 2 deletions BayesicFitting/source/BaseFitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions BayesicFitting/source/Prior.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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 )
Expand Down Expand Up @@ -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 ) :
"""
Expand Down Expand Up @@ -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 ):
Expand Down
11 changes: 6 additions & 5 deletions BayesicFitting/source/RepeatingModel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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 ):
"""
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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 ):
"""
Expand Down
25 changes: 12 additions & 13 deletions BayesicFitting/source/Tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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


Expand All @@ -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 ) :
Expand All @@ -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 ) :
"""
Expand Down Expand Up @@ -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 )

Expand All @@ -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.
"""
Expand All @@ -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() )
Expand All @@ -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 ) ) :
Expand All @@ -414,7 +413,7 @@ def printclass( cls, nitems=8 ) :
print( valstr.split()[0].split( '.' )[-1] )
else :
print( valstr )
except :
except Exception :
print( val )
print( "+++++++++++++++++++++++++++++++++++++++++++++++++++++++" )

Expand All @@ -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 "]" ) )
Expand Down
18 changes: 5 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,13 @@
---
---
<!--
## Navigation
| Content | Global | Documentation |
| :- | :- | :- |
| 1. [History](#history) | [Home](./index.md) | [Manual](./docs/manual.md) |
| 2. [Setup](#setup) | [Readme](./README.md) | [Glossary](./docs/glossary.md) |
| 3. [Structure](#structure) | [Notes](./docs/notes.md) | [Design](./docs/design.md) |
| 4. [Status](#status) | [Examples][exlink] | [Trouble](./docs/troubles.md) |
| 5. [Versions](#versions) | | |
-->

<div class="dropdown2">
<span style="background-color: DodgerBlue; color: White; border:5px
solid DodgerBlue">Contents</span>
<div class="dropdown-content">

| Content |
| :- |
| Contents |
| :-: |
| 1. [History](#history) |
| 2. [Setup](#setup) |
| 3. [Structure](#structure) |
Expand Down Expand Up @@ -51,6 +40,9 @@ DOI: 10.5281/zenodo.2597200

## What's new.

+ 05 Nov 2024 version 3.2.2<br>
Adapt to numpy-2 and pertaining Scipy, Astropy and MatplotLib

+ 27 March 2024 version 3.2.1<br>
A lot of fairly small stuff.
* \_\_status\_\_ changed to Alpha for some newer additions
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from setuptools import setup, find_packages

__version__ = '3.2.1'
__version__ = '3.2.2'

with open("README.md", "r") as fh:
long_description = fh.read()
Expand Down

0 comments on commit b46c4a8

Please sign in to comment.