-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheigVecCompTest.py
More file actions
88 lines (60 loc) · 2.52 KB
/
eigVecCompTest.py
File metadata and controls
88 lines (60 loc) · 2.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#To run: python eigValCompTest.py numCompar LapackEvecFilenames... pythEigvecFilenames...
import sys
import numpy as np
np.set_printoptions(threshold=10000,linewidth=2000,precision=6,suppress=False)
numComparisons = int(sys.argv[1])
for i in range(2,numComparisons+2):
LapackEvecFilename = sys.argv[i]
pythEigvecFilename = sys.argv[i+numComparisons]
pythEigvecFile = open(pythEigvecFilename, 'r')
LapackEvecFile = open(LapackEvecFilename, 'r')
pythEigvec_List = []
#Skip first three comment lines
pythEigvecFile.readline()
pythEigvecFile.readline()
pythEigvecFile.readline()
for line in pythEigvecFile:
splitLine = line.split()
strip_list = map(lambda it: it.strip(), splitLine)
pythEigvec_List.append(np.array(map(float, strip_list[1:])))
# print pythEigvec_List
# raw_input()
pythEigvec_Array = np.vstack(pythEigvec_List)
#print pythEigvec_Array
print pythEigvec_Array.shape
LapackEvec_List = []
#Skip first two comment lines
LapackEvecFile.readline()
LapackEvecFile.readline()
for line in LapackEvecFile:
splitLine = line.split()
strip_list = map(lambda it: it.strip(), splitLine)
LapackEvec_List.append(np.array(map(float, strip_list[1:])))
LapackEvec_Array = np.vstack(LapackEvec_List)
#print LapackEvec_Array
print LapackEvec_Array.shape
#Make sure all vectors have the same global phase
pythPhase = pythEigvec_Array[0,:] > 0
lapackPhase = LapackEvec_Array[0,:] > 0
phasesToChange = np.logical_xor(pythPhase,lapackPhase)
multArray = np.ones(pythEigvec_Array[0].size) - 2*phasesToChange
# print pythPhase[0:10]
# print lapackPhase[0:10]
# print phasesToChange[0:10]
# print multArray[0:10]
# print pythEigvec_Array[0:10,0:10]
# old = np.copy(pythEigvec_Array[0:10,0:10])
pythEigvec_Array = pythEigvec_Array[:] * multArray
# print pythEigvec_Array[0:10,0:10]
# print pythEigvec_Array[0:10,0:10] + old
absDiff = np.abs(pythEigvec_Array - LapackEvec_Array)
relAbsDiff = absDiff / np.abs(pythEigvec_Array)
maxRelAbsDiff = np.max(relAbsDiff)
LapackEvecFilename_short = LapackEvecFilename.split("/")[-1]
pythEigvecFilename_short = pythEigvecFilename.split("/")[-1]
print "------------------------"
print "For files {0} and {1}".format(LapackEvecFilename_short, pythEigvecFilename_short)
print "maxRelAbsDiff: ", maxRelAbsDiff
# print np.min(relAbsDiff)
pythEigvecFile.close()
LapackEvecFile.close()