From 4c1a2ac5ebf701b7333abe6d1b8f05bf1ee35cd3 Mon Sep 17 00:00:00 2001
From: Nicolas Marsic <marsic@temf.tu-darmstadt.de>
Date: Wed, 21 Sep 2016 14:08:22 +0000
Subject: [PATCH] getdp: pretty print

---
 beyn.py | 22 ++++------------------
 main.py | 11 ++++++++++-
 2 files changed, 14 insertions(+), 19 deletions(-)

diff --git a/beyn.py b/beyn.py
index deda9f1..1e97763 100644
--- a/beyn.py
+++ b/beyn.py
@@ -4,7 +4,7 @@ import numpy.matlib
 
 def simple(operator, radius, origin,
            nodes=100, maxIt=10, lStart=1, lStep=1, rankTol=1e-4):
-    """Solve an eigenvalue problem using Beyn's algorithm (simple version)
+    """Solves an eigenvalue problem using Beyn's algorithm (simple version)
 
     Keyword arguments:
     operator -- the solver defining the operator to use
@@ -14,6 +14,8 @@ def simple(operator, radius, origin,
     lStart -- the number of columns used for A0 when algorithm starts (optional)
     lStep -- the step used for increasing the number of columns of A0 (optional)
     rankTol -- the tolerance for the rank test
+
+    Returns the computed eigenvalues
     """
 
     # Initialise A0 search
@@ -67,11 +69,8 @@ def simple(operator, radius, origin,
     print "Solving linear EVP..."
     myLambda, QHat = numpy.linalg.eig(B)
 
-    # Display
-    display(myLambda)
-
     # Done
-    return
+    return myLambda
 
 
 ## Import only simple (other functions are just helpers)
@@ -162,19 +161,6 @@ def randomMatrix(n, m):
     return np.matlib.rand(n, m) + np.matlib.rand(n, m) * 1j
 
 
-def display(v):
-    """Displays the eigenvalues given in the array v"""
-    size = v.shape[0]
-    print "Eigenvalues:"
-    print "----------- "
-    for i in range(size):
-        print "(" + format(np.real(v[i]).tolist(), '+e') + ")",
-        print "+",
-        print "(" + format(np.imag(v[i]).tolist(), '+e') + ")*j"
-    print "----------- "
-    print "Found: " + str(size)
-
-
 def zeroRankErrorStr():
     """Returns a string explaining the probable reason of a zero rank"""
     return ("Found a rank of zero: " +
diff --git a/main.py b/main.py
index 3ce0a18..96c9833 100644
--- a/main.py
+++ b/main.py
@@ -11,4 +11,13 @@ resolution = "Maxwell"
 operator = Solver.GetDPWave(pro, mesh, resolution)
 
 # Compute
-Beyn.simple(operator, 1e8, complex(9e8, 0))
+v = Beyn.simple(operator, 1e8, complex(9e8, 0))
+
+print "Eigenvalues:"
+print "----------- "
+for i in range(v.shape[0]):
+    print "(" + format(np.real(v[i]).tolist(), '+e') + ")",
+    print "+",
+    print "(" + format(np.imag(v[i]).tolist(), '+e') + ")*j"
+print "----------- "
+print "Found: " + str(v.shape[0])
-- 
GitLab