Skip to content

Commit

Permalink
Updating python interface
Browse files Browse the repository at this point in the history
  • Loading branch information
poulson committed Nov 28, 2016
1 parent acbf1e7 commit 2eec647
Show file tree
Hide file tree
Showing 67 changed files with 547 additions and 630 deletions.
4 changes: 0 additions & 4 deletions cmake/configure_files/environment.py.in
Original file line number Diff line number Diff line change
Expand Up @@ -234,10 +234,6 @@ def Initialize():
pythonapi.Py_GetArgcArgv(ctypes.byref(argc),ctypes.byref(argv))
lib.ElInitialize(pointer(argc),pointer(argv))

lib.ElFinalize.argtypes = []
def Finalize():
lib.ElFinalize()

lib.ElInitialized.argtypes = [POINTER(bType)]
def Initialized():
active = bType()
Expand Down
16 changes: 9 additions & 7 deletions examples/interface/AlgebraicRelationSearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
outputAll=False
outputCoeff=False

print "alpha=", alpha
print('alpha = {}'.format(alpha))

ctrl=El.LLLCtrl_d()
ctrl.progress = progress
Expand All @@ -31,8 +31,8 @@
for deltaLower in 0.5, 0.75, 0.95, 0.98, 0.99:
for variant in El.LLL_NORMAL, El.LLL_DEEP, El.LLL_DEEP_REDUCE:

print "variant=%d, presort=%r, smallestFirst=%r, deltaLower=%f" % \
(variant,presort,smallestFirst,deltaLower)
print('variant={}, presort={}, smallestFirst={}, deltaLower={}'.format( \
variant,presort,smallestFirst,deltaLower))

ctrl.delta = deltaLower
ctrl.variant = variant
Expand All @@ -43,12 +43,14 @@
startTime = El.mpi.Time()
numExact, B, U = El.AlgebraicRelationSearch(alpha,n,NSqrt,ctrl)
runTime = El.mpi.Time() - startTime
print " runtime: %f seconds" % runTime
print " num \"exact\": ", numExact
print(' runtime: {} seconds'.format(runTime))
print(' num \"exact\": {}'.format(numExact))
if outputAll:
El.Print( B, "B" )
El.Print( U, "U" )
elif outputCoeff:
El.Print( U[:,0], "u0" )
print "approximate zero: %e+%ei" % \
(B.GetRealPart(n,0)/NSqrt,B.GetImagPart(n,0)/NSqrt)
print('approximate zero: {}+{}i'.format( \
B.GetRealPart(n,0)/NSqrt,B.GetImagPart(n,0)/NSqrt))

El.Finalize()
9 changes: 3 additions & 6 deletions examples/interface/BP.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def ConcatFD2D(N0,N1):
x = El.BP( A, b, ctrl )
endBP = El.mpi.Time()
if worldRank == 0:
print "BP time:", endBP-startBP, "seconds"
print('BP time: {} seconds'.format(endBP-startBP))
if display:
El.Display( x, "x" )

Expand All @@ -84,10 +84,7 @@ def ConcatFD2D(N0,N1):
El.Display( e, "e" )
eTwoNorm = El.Nrm2( e )
if worldRank == 0:
print "|| x ||_1 =", xOneNorm
print "|| A x - b ||_2 =", eTwoNorm
print('|| x ||_1 = {}'.format(xOneNorm))
print('|| A x - b ||_2 = {}'.format(eTwoNorm))

# Require the user to press a button before the figures are closed
El.Finalize()
if worldSize == 1:
raw_input('Press Enter to exit')
9 changes: 3 additions & 6 deletions examples/interface/BPComplex.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def ConcatFD2D(N0,N1):
x = El.BP( A, b, ctrl )
endBP = El.mpi.Time()
if worldRank == 0:
print "BP time:", endBP-startBP, "seconds"
print('BP time: {} seconds'.format(endBP-startBP))
if display:
El.Display( x, "x" )
if output:
Expand All @@ -76,10 +76,7 @@ def ConcatFD2D(N0,N1):
( El.NORMAL, El.ComplexDouble(-1), A, x, El.ComplexDouble(1), e )
eTwoNorm = El.Nrm2( e )
if worldRank == 0:
print "|| x ||_1 =", xOneNorm
print "|| A x - b ||_2 =", eTwoNorm
print('|| x ||_1 = {}'.format(xOneNorm))
print('|| A x - b ||_2 = {}'.format(eTwoNorm))

# Require the user to press a button before the figures are closed
El.Finalize()
if worldSize == 1:
raw_input('Press Enter to exit')
9 changes: 3 additions & 6 deletions examples/interface/BPComplexDense.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def ConcatFD2D(N0,N1):
x = El.BP( A, b, ctrl )
endBP = El.mpi.Time()
if worldRank == 0:
print "BP time:", endBP-startBP, "seconds"
print('BP time: {} seconds'.format(endBP-startBP))
if display:
El.Display( x, "x" )
if output:
Expand All @@ -87,10 +87,7 @@ def ConcatFD2D(N0,N1):
El.Print( e, "e" )
eTwoNorm = El.Nrm2( e )
if worldRank == 0:
print "|| x ||_1 =", xOneNorm
print "|| A x - b ||_2 =", eTwoNorm
print('|| x ||_1 = {}'.format(xOneNorm))
print('|| A x - b ||_2 = {}'.format(eTwoNorm))

# Require the user to press a button before the figures are closed
El.Finalize()
if worldSize == 1:
raw_input('Press Enter to exit')
11 changes: 4 additions & 7 deletions examples/interface/BPDN.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,13 @@ def ConcatFD2D(N0,N1):
for j in xrange(0,numLambdas):
lambd = startLambda + j*(endLambda-startLambda)/(numLambdas-1.)
if worldRank == 0:
print "lambda =", lambd
print('lambda = {}'.format(lambd))

startBPDN = El.mpi.Time()
x = El.BPDN( A, b, lambd, ctrl )
endBPDN = El.mpi.Time()
if worldRank == 0:
print "BPDN time:", endBPDN-startBPDN, "seconds"
print('BPDN time: {} seconds'.format(endBPDN-startBPDN))
if display:
El.Display( x, "x" )

Expand All @@ -88,10 +88,7 @@ def ConcatFD2D(N0,N1):
El.Display( e, "e" )
eTwoNorm = El.Nrm2( e )
if worldRank == 0:
print "|| x ||_1 =", xOneNorm
print "|| A x - b ||_2 =", eTwoNorm
print('|| x ||_1 = {}'.format(xOneNorm))
print('|| A x - b ||_2 = {}'.format(eTwoNorm))

# Require the user to press a button before the figures are closed
El.Finalize()
if worldSize == 1:
raw_input('Press Enter to exit')
11 changes: 4 additions & 7 deletions examples/interface/BPDNDense.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ def Rectang(height,width):
for j in xrange(0,numLambdas):
lambd = startLambda + j*(endLambda-startLambda)/(numLambdas-1.)
if worldRank == 0:
print "lambda =", lambd
print('lambda = {}'.format(lambd))

startBPDN = El.mpi.Time()
x = El.BPDN( A, b, lambd, ctrl )
endBPDN = El.mpi.Time()
if worldRank == 0:
print "BPDN time:", endBPDN-startBPDN, "seconds"
print('BPDN time: {} seconds'.format(endBPDN-startBPDN))
if display:
El.Display( x, "x" )

Expand All @@ -53,10 +53,7 @@ def Rectang(height,width):
El.Display( e, "e" )
eTwoNorm = El.Nrm2( e )
if worldRank == 0:
print "|| x ||_1 =", xOneNorm
print "|| A x - b ||_2 =", eTwoNorm
print('|| x ||_1 = {}'.format(xOneNorm))
print('|| A x - b ||_2 = {}'.format(eTwoNorm))

# Require the user to press a button before the figures are closed
El.Finalize()
if worldSize == 1:
raw_input('Press Enter to exit')
9 changes: 3 additions & 6 deletions examples/interface/BPDense.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def Rectang(height,width):
x = El.BP( A, b, ctrl )
endBP = El.mpi.Time()
if worldRank == 0:
print "BP time:", endBP-startBP, "seconds"
print('BP time: {} seconds'.format(endBP-startBP))
if display:
El.Display( x, "x" )

Expand All @@ -44,10 +44,7 @@ def Rectang(height,width):
El.Display( e, "e" )
eTwoNorm = El.Nrm2( e )
if worldRank == 0:
print "|| x ||_1 =", xOneNorm
print "|| A x - b ||_2 =", eTwoNorm
print('|| x ||_1 = {}'.format(xOneNorm))
print('|| A x - b ||_2 = {}'.format(eTwoNorm))

# Require the user to press a button before the figures are closed
El.Finalize()
if worldSize == 1:
raw_input('Press Enter to exit')
19 changes: 8 additions & 11 deletions examples/interface/CP.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def StackedFD2D(N0,N1):
x = El.CP( A, b, ctrl )
endCP = El.mpi.Time()
if worldRank == 0:
print "CP time:", endCP-startCP, "seconds"
print('CP time: {} seconds'.format(endCP-startCP))
if display:
El.Display( x, "x" )

Expand All @@ -85,16 +85,16 @@ def StackedFD2D(N0,N1):
rTwoNorm = El.Nrm2( r )
rInfNorm = El.MaxNorm( r )
if worldRank == 0:
print "|| b ||_2 =", bTwoNorm
print "|| b ||_oo =", bInfNorm
print "|| A x - b ||_2 =", rTwoNorm
print "|| A x - b ||_oo =", rInfNorm
print('|| b ||_2 = {}'.format(bTwoNorm))
print('|| b ||_oo = {}'.format(bInfNorm))
print('|| A x - b ||_2 = {}'.format(rTwoNorm))
print('|| A x - b ||_oo = {}'.format(rInfNorm))

startLS = El.mpi.Time()
xLS = El.LeastSquares(A,b)
endLS = El.mpi.Time()
if worldRank == 0:
print "LS time:", endLS-startLS, "seconds"
print('LS time: {} seconds'.format(endLS-startLS))
if display:
El.Display( xLS, "x_{LS}" )
rLS = El.DistMultiVec()
Expand All @@ -105,10 +105,7 @@ def StackedFD2D(N0,N1):
rLSTwoNorm = El.Nrm2(rLS)
rLSInfNorm = El.MaxNorm(rLS)
if worldRank == 0:
print "|| A x_{LS} - b ||_2 =", rLSTwoNorm
print "|| A x_{LS} - b ||_oo =", rLSInfNorm
print('|| A x_{{LS}} - b ||_2 = {}'.format(rLSTwoNorm))
print('|| A x_{{LS}} - b ||_oo = {}'.format(rLSInfNorm))

# Require the user to press a button before the figures are closed
El.Finalize()
if worldSize == 1:
raw_input('Press Enter to exit')
19 changes: 8 additions & 11 deletions examples/interface/CPDense.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def Rectang(height,width):
x = El.CP( A, b, ctrl )
endCP = El.mpi.Time()
if worldRank == 0:
print "CP time:", endCP-startCP, "seconds"
print('CP time: {} seconds'.format(endCP-startCP))
if display:
El.Display( x, "x" )

Expand All @@ -46,16 +46,16 @@ def Rectang(height,width):
rTwoNorm = El.Nrm2( r )
rInfNorm = El.MaxNorm( r )
if worldRank == 0:
print "|| b ||_2 =", bTwoNorm
print "|| b ||_oo =", bInfNorm
print "|| A x - b ||_2 =", rTwoNorm
print "|| A x - b ||_oo =", rInfNorm
print('|| b ||_2 = {}'.format(bTwoNorm))
print('|| b ||_oo = {}'.format(bInfNorm))
print('|| A x - b ||_2 = {}'.format(rTwoNorm))
print('|| A x - b ||_oo = {}'.format(rInfNorm))

startLS = El.mpi.Time()
xLS = El.LeastSquares(A,b)
endLS = El.mpi.Time()
if worldRank == 0:
print "LS time:", endLS-startLS, "seconds"
print('LS time: {} seconds'.format(endLS-startLS))
if display:
El.Display( xLS, "x_{LS}" )
rLS = El.DistMatrix()
Expand All @@ -66,10 +66,7 @@ def Rectang(height,width):
rLSTwoNorm = El.Nrm2(rLS)
rLSInfNorm = El.MaxNorm(rLS)
if worldRank == 0:
print "|| A x_{LS} - b ||_2 =", rLSTwoNorm
print "|| A x_{LS} - b ||_oo =", rLSInfNorm
print('|| A x_{{LS}} - b ||_2 = {}'.format(rLSTwoNorm))
print('|| A x_{{LS}} - b ||_oo = {}'.format(rLSInfNorm))

# Require the user to press a button before the figures are closed
El.Finalize()
if worldSize == 1:
raw_input('Press Enter to exit')
15 changes: 6 additions & 9 deletions examples/interface/DS.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ def ConcatFD2D(N0,N1):
for j in xrange(0,numLambdas):
lambd = startLambda + j*(endLambda-startLambda)/(numLambdas-1.)
if worldRank == 0:
print "lambda =", lambd
print('lambda = {}'.format(lambd))

startDS = El.mpi.Time()
x = El.DS( A, b, lambd, ctrl )
endDS = El.mpi.Time()
if worldRank == 0:
print "DS time:", endDS-startDS, "seconds"
print('DS time: {} seconds'.format(endDS-startDS))
if display:
El.Display( x, "x" )

Expand All @@ -90,12 +90,9 @@ def ConcatFD2D(N0,N1):
El.Display( r, "r" )
El.Display( t, "t" )
if worldRank == 0:
print "|| x ||_1 =", xOneNorm
print "|| b - A x ||_2 =", rTwoNorm
print "|| A^T (b - A x) ||_2 =", tTwoNorm
print "|| A^T (b - A x) ||_oo =", tInfNorm
print('|| x ||_1 = {}'.format(xOneNorm))
print('|| b - A x ||_2 = {}'.format(rTwoNorm))
print('|| A^T (b - A x) ||_2 = {}'.format(tTwoNorm))
print('|| A^T (b - A x) ||_oo = {}'.format(tInfNorm))

# Require the user to press a button before the figures are closed
El.Finalize()
if worldSize == 1:
raw_input('Press Enter to exit')
15 changes: 6 additions & 9 deletions examples/interface/DSDense.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ def Rectang(height,width):
for j in xrange(0,numLambdas):
lambd = startLambda + j*(endLambda-startLambda)/(numLambdas-1.)
if worldRank == 0:
print "lambda =", lambd
print('lambda = {}'.format(lambd))

startDS = El.mpi.Time()
x = El.DS( A, b, lambd, ctrl )
endDS = El.mpi.Time()
if worldRank == 0:
print "DS time:", endDS-startDS, "seconds"
print('DS time: {} seconds'.format(endDS-startDS))
if display:
El.Display( x, "x" )

Expand All @@ -59,12 +59,9 @@ def Rectang(height,width):
El.Display( r, "r" )
El.Display( t, "t" )
if worldRank == 0:
print "|| x ||_1 =", xOneNorm
print "|| b - A x ||_2 =", rTwoNorm
print "|| A^T (b - A x) ||_2 =", tTwoNorm
print "|| A^T (b - A x) ||_oo =", tInfNorm
print('|| x ||_1 = {}'.format(xOneNorm))
print('|| b - A x ||_2 = {}'.format(rTwoNorm))
print('|| A^T (b - A x) ||_2 = {}'.format(tTwoNorm))
print('|| A^T (b - A x) ||_oo = {}'.format(tInfNorm))

# Require the user to press a button before the figures are closed
El.Finalize()
if worldSize == 1:
raw_input('Press Enter to exit')
4 changes: 0 additions & 4 deletions examples/interface/DruinskyToledo.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,4 @@
El.EntrywiseMap(A_LU,lambda x:math.log10(max(abs(x),1)))
El.Display(A_LU,"Logarithmically-scaled LU factors")

# Require the user to press a button before the figures are closed
worldSize = El.mpi.WorldSize()
El.Finalize()
if worldSize == 1:
raw_input('Press Enter to exit')
4 changes: 0 additions & 4 deletions examples/interface/DynamicRegCounter.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,4 @@
El.DynamicRegCounter( A, n )
El.Display( A, "A" )

# Require the user to press a button before the figures are closed
worldSize = El.mpi.WorldSize()
El.Finalize()
if worldSize == 1:
raw_input('Press Enter to exit')
Loading

0 comments on commit 2eec647

Please sign in to comment.