60 outstream, details_stream):
61 """ Calculate the floating-point difference between two data files.
62 The idea is to use a looser tolerance than the UNIX diff command,
63 so that if two entries have a relative error less than the argument
64 relative_error, they are counted as the same.
66 Note that the relative error is percentage!
68 Information on pass/failure is written to outstream. Details on which
69 lines failed are written to details_stream. Warning: if run on
70 large files the details_stream may be overwhelmingly long.
72 First return value: 0 if the two files are the same, 1 if they are
73 different or 5 if the files cannot be opened.
75 Second return value: the maximum relative error.
77 Third return value: the largest entry that caused an error
78 (i.e. what "small" would need to be set as for there to be no
95 for file_length, filename
in [(len(tmpfile1), filename1), (len(tmpfile2), filename2)]:
97 details_stream.write(f
"\nWarning: file {filename} is empty and the test will therefore be treated as a FAIL\n")
106 file1 = tmpfile1; file2 = tmpfile2; n = n2
109 file1 = tmpfile2; file2 = tmpfile1; n = n1
124 details_stream.write(
"\nWarning: files have different numbers of lines")
125 details_stream.write(
"\nResults are for first %d lines of both files\n" % count)
137 fields1 = line1.split(); fields2 = line2.split()
139 nfields1 = len(fields1); nfields2 = len(fields2)
142 if nfields1 != nfields2:
143 details_stream.write(
"\n =====> line %d: different number of fields\n" \
145 details_stream.write(
"%s fields: %s" % (nfields1, line1))
146 details_stream.write(
"%s fields: %s" % (nfields2, line2))
155 outputline1 =
""; outputline2 =
""; outputline3 =
""
158 for i
in range(nfields1):
160 outputline1 += fields1[i] +
" "; outputline3 += fields2[i] +
" "
163 length1 = len(fields1[i]); length2 = len(fields2[i])
166 if length1 < length2:
167 fieldlength = length2
168 for j
in range(length2-length1):
171 fieldlength = length1
172 for j
in range(length1 - length2):
176 if fields1[i] == fields2[i]:
178 outputline2 =
stuff(outputline2,
" ",fieldlength)
189 outputline2 =
stuff(outputline2,
"*",fieldlength)
196 outputline2 =
stuff(outputline2,
"%",fieldlength)
199 x1 = float(fields1[i].
lower().replace(
"d",
"e"))
200 x2 = float(fields2[i].
lower().replace(
"d",
"e"))
203 if math.fabs(x1) <= small
and math.fabs(x2) <= small:
205 outputline2 =
stuff(outputline2,
" ",fieldlength)
211 if math.fabs(x1) > math.fabs(x2) :
212 diff = 100.0*(math.fabs(x1 - x2) / math.fabs(x1))
214 diff = 100.0*(math.fabs(x1 - x2) / math.fabs(x2))
217 if diff <= relative_error:
219 outputline2 =
stuff(outputline2,
" ",fieldlength)
225 outputline2 =
stuff(outputline2,
"-",fieldlength)
228 if diff > max_rel_diff:
231 if math.fabs(x1) > max_wrong_entry:
232 max_wrong_entry = math.fabs(x1)
233 elif math.fabs(x2) > max_wrong_entry:
234 max_wrong_entry = math.fabs(x2)
239 details_stream.write(
"\n =====> line %d\n" % (count+1))
240 details_stream.write(
"%s\n%s\n%s\n" % (outputline1, outputline2, outputline3))
244 outstream.write(
"\n In files %s %s" % (filename1, filename2))
245 outstream.write(
"\n number of lines processed: %d" % count)
246 outstream.write(
"\n number of lines containing errors: %d" % nline_error)
247 outstream.write(
"\n number of errors: %d " % nerr)
248 outstream.write(
"\n largest relative error: %g " % max_rel_diff)
249 outstream.write(
"\n largest abs value of an entry which caused an error: %g "
251 outstream.write(
"\n========================================================")
252 outstream.write(
"\n Parameters used:")
253 outstream.write(
"\n threshold for numerical zero : %g" % small)
254 outstream.write(
"\n maximum rel. difference [percent] : %g" % relative_error)
255 outstream.write(
"\n Legend: ")
256 outstream.write(
"\n ******* means differences in data type (string vs number)")
257 outstream.write(
"\n ------- means real data exceeded the relative difference maximum")
258 outstream.write(
"\n %%%%%%% means that two strings are different")
259 outstream.write(
"\n========================================================")
260 outstream.write(
"\n\n [FAILED]\n")
262 return 2, max_rel_diff, max_wrong_entry
265 outstream.write(
"\n\n In files %s %s" % (filename1, filename2))
267 "\n [OK] for fpdiff.py parameters: - max. rel. error = %g " % relative_error)
270 "\n - numerical zero = %g\n" % small)
272 return 0, max_rel_diff, max_wrong_entry
if(UPLO(*uplo)==INVALID) info
Definition: level3_impl.h:428
def stuff(string, symbol, number)
Definition: Configuration/fpdiff.py:26
def gettype(a)
Definition: Configuration/fpdiff.py:13
def read_file(filename)
Definition: Configuration/fpdiff.py:36
std::string lower(std::string s)
returns the input string after converting upper-case characters to lower case
Definition: StringHelpers.cc:11