Skip to content

Commit

Permalink
Check numpy version to determine rcond value
Browse files Browse the repository at this point in the history
Prior to numpy 1.14, numpy.linag.lstsq does not accept rcond=None
and will raise a TypeError.

In numpy 1.14 and after, None requests the new default behavior.
  • Loading branch information
mliu49 committed Jul 28, 2019
1 parent 6250cbf commit 7966b16
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 8 deletions.
9 changes: 6 additions & 3 deletions rmgpy/data/kinetics/groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@
from rmgpy.quantity import constants
from rmgpy.exceptions import KineticsError, UndeterminableKineticsError, DatabaseError

# Prior to numpy 1.14, `numpy.linalg.lstsq` does not accept None as a value
RCOND = -1 if int(numpy.__version__.split('.')[1]) < 14 else None

################################################################################

class KineticsGroups(Database):
Expand Down Expand Up @@ -409,7 +412,7 @@ def generateGroupAdditivityValues(self, trainingSet, kunits, method='Arrhenius')
b = numpy.array(b)
kdata = numpy.array(kdata)

x, residues, rank, s = numpy.linalg.lstsq(A, b, rcond=None)
x, residues, rank, s = numpy.linalg.lstsq(A, b, rcond=RCOND)

for t, T in enumerate(Tdata):

Expand Down Expand Up @@ -513,7 +516,7 @@ def generateGroupAdditivityValues(self, trainingSet, kunits, method='Arrhenius')
b = numpy.array(b)
kdata = numpy.array(kdata)

x, residues, rank, s = numpy.linalg.lstsq(A, b, rcond=None)
x, residues, rank, s = numpy.linalg.lstsq(A, b, rcond=RCOND)

# Store the results
self.top[0].data = Arrhenius(
Expand Down Expand Up @@ -564,7 +567,7 @@ def generateGroupAdditivityValues(self, trainingSet, kunits, method='Arrhenius')
A = numpy.array(A)
b = numpy.array(b)

x, residues, rank, s = numpy.linalg.lstsq(A, b, rcond=None)
x, residues, rank, s = numpy.linalg.lstsq(A, b, rcond=RCOND)

# Store the results
self.top[0].data = Arrhenius(
Expand Down
6 changes: 5 additions & 1 deletion rmgpy/kinetics/arrhenius.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ cimport rmgpy.constants as constants
import rmgpy.quantity as quantity
from rmgpy.exceptions import KineticsError
from rmgpy.kinetics.uncertainies import rank_accuracy_map

# Prior to numpy 1.14, `numpy.linalg.lstsq` does not accept None as a value
RCOND = -1 if int(numpy.__version__.split('.')[1]) < 14 else None

################################################################################

cdef class Arrhenius(KineticsModel):
Expand Down Expand Up @@ -162,7 +166,7 @@ cdef class Arrhenius(KineticsModel):
for n in range(b.size):
A[n,:] *= weights[n]
b[n] *= weights[n]
x, residues, rank, s = numpy.linalg.lstsq(A, b, rcond=None)
x, residues, rank, s = numpy.linalg.lstsq(A, b, rcond=RCOND)

# Determine covarianace matrix to obtain parameter uncertainties
count = klist.size
Expand Down
6 changes: 5 additions & 1 deletion rmgpy/kinetics/chebyshev.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ cimport rmgpy.constants as constants
import rmgpy.quantity as quantity
import logging
from rmgpy.exceptions import KineticsError

# Prior to numpy 1.14, `numpy.linalg.lstsq` does not accept None as a value
RCOND = -1 if int(numpy.__version__.split('.')[1]) < 14 else None

################################################################################

cdef class Chebyshev(PDepKineticsModel):
Expand Down Expand Up @@ -217,7 +221,7 @@ cdef class Chebyshev(PDepKineticsModel):
b[p1*nT+t1] = log10(K[t1,p1])

# Do linear least-squares fit to get coefficients
x, residues, rank, s = numpy.linalg.lstsq(A, b, rcond=None)
x, residues, rank, s = numpy.linalg.lstsq(A, b, rcond=RCOND)

# Extract coefficients
coeffs = numpy.zeros((degreeT,degreeP), numpy.float64)
Expand Down
5 changes: 4 additions & 1 deletion rmgpy/kinetics/surface.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ cimport rmgpy.constants as constants
import rmgpy.quantity as quantity
from rmgpy.exceptions import KineticsError

# Prior to numpy 1.14, `numpy.linalg.lstsq` does not accept None as a value
RCOND = -1 if int(numpy.__version__.split('.')[1]) < 14 else None

################################################################################

cdef class StickingCoefficient(KineticsModel):
Expand Down Expand Up @@ -157,7 +160,7 @@ cdef class StickingCoefficient(KineticsModel):
for n in range(b.size):
A[n, :] *= weights[n]
b[n] *= weights[n]
x, residues, rank, s = numpy.linalg.lstsq(A, b, rcond=None)
x, residues, rank, s = numpy.linalg.lstsq(A, b, rcond=RCOND)

# Determine covarianace matrix to obtain parameter uncertainties
count = klist.size
Expand Down
5 changes: 4 additions & 1 deletion rmgpy/statmech/torsion.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ import rmgpy.statmech.schrodinger as schrodinger
from rmgpy.exceptions import NegativeBarrierException
import logging

# Prior to numpy 1.14, `numpy.linalg.lstsq` does not accept None as a value
RCOND = -1 if int(numpy.__version__.split('.')[1]) < 14 else None

################################################################################

cdef class Torsion(Mode):
Expand Down Expand Up @@ -539,7 +542,7 @@ cdef class HinderedRotor(Torsion):
# This row forces dV/dangle = 0 at angle = 0
for m in range(numterms):
A[N,m+numterms] = 1
x, residues, rank, s = numpy.linalg.lstsq(A, b, rcond=None)
x, residues, rank, s = numpy.linalg.lstsq(A, b, rcond=RCOND)
fit = numpy.dot(A,x)
x *= 0.001
# This checks if there are any negative values in the forier fit.
Expand Down
5 changes: 4 additions & 1 deletion rmgpy/thermo/wilhoit.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ cimport rmgpy.constants as constants
import rmgpy.quantity as quantity
import scipy.linalg

# Prior to numpy 1.14, `numpy.linalg.lstsq` does not accept None as a value
RCOND = -1 if int(numpy.__version__.split('.')[1]) < 14 else None

################################################################################

cdef class Wilhoit(HeatCapacityModel):
Expand Down Expand Up @@ -277,7 +280,7 @@ cdef class Wilhoit(HeatCapacityModel):
for j in range(4):
A[i,j] = (y*y*y - y*y) * y**j
b[i] = ((Cpdata[i] - Cp0) / (CpInf - Cp0) - y*y)
x, residues, rank, s = numpy.linalg.lstsq(A, b, rcond=None)
x, residues, rank, s = numpy.linalg.lstsq(A, b, rcond=RCOND)

self.B = (float(B),"K")
self.a0 = float(x[0])
Expand Down

0 comments on commit 7966b16

Please sign in to comment.