Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python3 compatibility. #85

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions gpfit/ba_init.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"Implements ba_init"
from __future__ import print_function
from numpy import ones, hstack, zeros, tile, argmin
from numpy.linalg import lstsq, matrix_rank
from numpy.random import permutation as randperm
Expand Down
5 changes: 3 additions & 2 deletions gpfit/fit_constraintset.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
" fit constraint set "
from __future__ import print_function
from numpy import amax, array, hstack, where
from gpkit import ConstraintSet
from gpkit import Variable, NomialArray, NamedVariables, VectorVariable
Expand Down Expand Up @@ -135,7 +136,7 @@ def process_result(self, result):
+ " %s bound. Solution is %.4f but"
" bound is %.4f" %
(direct, amax([num]), bnd))
print "Warning: " + msg
print("Warning: " + msg)


class XfoilFit(FitCS):
Expand Down Expand Up @@ -185,4 +186,4 @@ def process_result(self, result):
" Xfoil cd=%.6f, GP sol cd=%.6f" %
(", ".join(self.ivar.descr["models"]), err[i], re[i],
cl[i], cd[i], cdx[i]))
print "Warning: %s" % msg
print("Warning: %s" % msg)
15 changes: 8 additions & 7 deletions gpfit/levenberg_marquardt.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"Implements LM"
from __future__ import print_function
from time import time
from sys import float_info
import numpy as np
Expand Down Expand Up @@ -92,19 +93,19 @@ def levenberg_marquardt(residfun, initparams,
'Norm of \n')
print('Iter Residual optimality Lambda'
' step Jwarp \n')
print formatstr1 % (itr, rms, maxgrad)
print(formatstr1 % (itr, rms, maxgrad))

# Main Loop
while True:

if itr == maxiter:
if verbose:
print 'Reached maximum number of iterations'
print('Reached maximum number of iterations')
break

elif time() - t > maxtime:
if verbose:
print 'Reached maxtime (%s seconds)' % maxtime
print('Reached maxtime (%s seconds)' % maxtime)
break
elif (itr >= 2 and
abs(RMStraj[itr] - RMStraj[itr-2]) <
Expand Down Expand Up @@ -155,8 +156,8 @@ def levenberg_marquardt(residfun, initparams,
# dsp here so that all grad info is for updated point,
# but lambda not yet updated
if verbose:
print formatstr % (itr, trialrms, maxgrad, lamb, norm(step),
max(diagJJ)/min(diagJJ))
print(formatstr % (itr, trialrms, maxgrad, lamb, norm(step),
max(diagJJ)/min(diagJJ)))

if maxgrad < tolgrad:
if verbose:
Expand All @@ -170,8 +171,8 @@ def levenberg_marquardt(residfun, initparams,
params_updated = True
else:
if verbose:
print formatstr % (itr, trialrms, maxgrad, lamb, norm(step),
max(diagJJ)/min(diagJJ))
print(formatstr % (itr, trialrms, maxgrad, lamb, norm(step),
max(diagJJ)/min(diagJJ)))
lamb = lamb*10
prev_trial_accepted = False
params_updated = False
Expand Down
1 change: 1 addition & 0 deletions gpfit/lse_implicit.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"Implements lse_implicit"
from __future__ import print_function
from numpy import zeros, spacing, exp, log, tile


Expand Down
11 changes: 6 additions & 5 deletions gpfit/print_fit.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"Implements functions for raw fit printing from params"
from __future__ import print_function
from numpy import exp


Expand All @@ -10,7 +11,7 @@ def print_ISMA(A, B, alpha, d, K):
printString = '1 = '
for k in range(K):
if k > 0:
print printString
print(printString)
printString = ' + '

printString += '({0:.6g}/w**{1:.6g})'.format(exp(alpha[k] * B[k]), alpha[k])
Expand All @@ -20,7 +21,7 @@ def print_ISMA(A, B, alpha, d, K):

stringList[k] = printString

print printString
print(printString)
return stringList


Expand All @@ -32,7 +33,7 @@ def print_SMA(A, B, alpha, d, K):
printString = 'w**{0:.6g} = '.format(alpha)
for k in range(K):
if k > 0:
print printString
print(printString)
printString = ' + '

printString += '{0:.6g}'.format(exp(alpha * B[k]))
Expand All @@ -42,7 +43,7 @@ def print_SMA(A, B, alpha, d, K):

stringList[k] = printString

print printString
print(printString)
return stringList


Expand All @@ -58,6 +59,6 @@ def print_MA(A, B, d, K):
printString += ' * (u_{0:d})**{1:.6g}'.format(i+1, A[d*k + i])

stringList[k] = printString
print printString
print(printString)

return stringList
1 change: 1 addition & 0 deletions gpfit/softmax_affine.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"Implements SMA residual function"
from __future__ import division
from numpy import size, inf, nan, ones, hstack, dot, tile
from .lse_scaled import lse_scaled

Expand Down
5 changes: 3 additions & 2 deletions gpfit/xfoil_wrapper.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
" python wrapper to call xfoil "
from __future__ import print_function
import subprocess
import numpy as np

Expand Down Expand Up @@ -43,12 +44,12 @@ def xfoil_comparison(airfoil, Cl, Re, Cd):
try:
x = single_call(topline, cl, re, 0.0)
if "VISCAL: Convergence failed" in x:
print "Convergence Warning: %s" % failmsg
print("Convergence Warning: %s" % failmsg)
cdx = cd
else:
cdx = x[0]
except subprocess.CalledProcessError:
print "Unable to start Xfoil: %s" % failmsg
print("Unable to start Xfoil: %s" % failmsg)
cdx = cd

err.append(1 - cd/cdx)
Expand Down