Commit 8356a6b6 authored by Alexander Alekhin's avatar Alexander Alekhin

Merge pull request #11442 from cclauss:print-function

parents d1d7408a 05c1a3d1
from __future__ import print_function
import sys, os, re import sys, os, re
# #
...@@ -84,7 +85,7 @@ def readFunctionFilter(fns, fileName): ...@@ -84,7 +85,7 @@ def readFunctionFilter(fns, fileName):
try: try:
f = open(fileName, "r") f = open(fileName, "r")
except: except:
print "ERROR: Can't open filter file: %s" % fileName print("ERROR: Can't open filter file: %s" % fileName)
return 0 return 0
count = 0 count = 0
...@@ -133,8 +134,8 @@ def outputToString(f): ...@@ -133,8 +134,8 @@ def outputToString(f):
@outputToString @outputToString
def generateFilterNames(fns): def generateFilterNames(fns):
for fn in fns: for fn in fns:
print '%s%s' % ('' if fn.has_key('enabled') else '//', fn['name']) print('%s%s' % ('' if 'enabled' in fn else '//', fn['name']))
print '#total %d' % len(fns) print('#total %d' % len(fns))
callback_check = re.compile(r'([^\(]*\(.*)(\* *)(\).*\(.*\))') callback_check = re.compile(r'([^\(]*\(.*)(\* *)(\).*\(.*\))')
...@@ -145,100 +146,100 @@ def getTypeWithParam(t, p): ...@@ -145,100 +146,100 @@ def getTypeWithParam(t, p):
@outputToString @outputToString
def generateStructDefinitions(fns, lprefix='opencl_fn', enumprefix='OPENCL_FN'): def generateStructDefinitions(fns, lprefix='opencl_fn', enumprefix='OPENCL_FN'):
print '// generated by %s' % os.path.basename(sys.argv[0]) print('// generated by %s' % os.path.basename(sys.argv[0]))
for fn in fns: for fn in fns:
commentStr = '' if fn.has_key('enabled') else '//' commentStr = '' if 'enabled' in fn else '//'
decl_args = [] decl_args = []
for (i, t) in enumerate(fn['params']): for (i, t) in enumerate(fn['params']):
decl_args.append(getTypeWithParam(t, 'p%d' % (i+1))) decl_args.append(getTypeWithParam(t, 'p%d' % (i+1)))
decl_args_str = '(' + (', '.join(decl_args)) + ')' decl_args_str = '(' + (', '.join(decl_args)) + ')'
print '%s%s%d(%s_%s, %s, %s)' % \ print('%s%s%d(%s_%s, %s, %s)' % \
(commentStr, lprefix, len(fn['params']), enumprefix, fn['name'], \ (commentStr, lprefix, len(fn['params']), enumprefix, fn['name'], \
' '.join(fn['ret']), decl_args_str) ' '.join(fn['ret']), decl_args_str))
print commentStr + ('%s%s (%s *%s)(%s) =\n%s %s_%s_switch_fn;' % \ print(commentStr + ('%s%s (%s *%s)(%s) =\n%s %s_%s_switch_fn;' % \
((' '.join(fn['modifiers'] + ' ') if len(fn['modifiers']) > 0 else ''), ((' '.join(fn['modifiers'] + ' ') if len(fn['modifiers']) > 0 else ''),
' '.join(fn['ret']), ' '.join(fn['calling']), fn['name'], ', '.join(fn['params']), \ ' '.join(fn['ret']), ' '.join(fn['calling']), fn['name'], ', '.join(fn['params']), \
commentStr, enumprefix, fn['name'])) commentStr, enumprefix, fn['name'])))
print commentStr + ('static const struct DynamicFnEntry %s_definition = { "%s", (void**)&%s};' % (fn['name'], fn['name'], fn['name'])) print(commentStr + ('static const struct DynamicFnEntry %s_definition = { "%s", (void**)&%s};' % (fn['name'], fn['name'], fn['name'])))
print print()
@outputToString @outputToString
def generateStaticDefinitions(fns): def generateStaticDefinitions(fns):
print '// generated by %s' % os.path.basename(sys.argv[0]) print('// generated by %s' % os.path.basename(sys.argv[0]))
for fn in fns: for fn in fns:
commentStr = '' if fn.has_key('enabled') else '//' commentStr = '' if 'enabled' in fn else '//'
decl_args = [] decl_args = []
for (i, t) in enumerate(fn['params']): for (i, t) in enumerate(fn['params']):
decl_args.append(getTypeWithParam(t, 'p%d' % (i+1))) decl_args.append(getTypeWithParam(t, 'p%d' % (i+1)))
decl_args_str = '(' + (', '.join(decl_args)) + ')' decl_args_str = '(' + (', '.join(decl_args)) + ')'
print commentStr + ('CL_RUNTIME_EXPORT %s%s (%s *%s_pfn)(%s) = %s;' % \ print(commentStr + ('CL_RUNTIME_EXPORT %s%s (%s *%s_pfn)(%s) = %s;' % \
((' '.join(fn['modifiers'] + ' ') if len(fn['modifiers']) > 0 else ''), ((' '.join(fn['modifiers'] + ' ') if len(fn['modifiers']) > 0 else ''),
' '.join(fn['ret']), ' '.join(fn['calling']), fn['name'], ', '.join(fn['params']), \ ' '.join(fn['ret']), ' '.join(fn['calling']), fn['name'], ', '.join(fn['params']), \
fn['name'])) fn['name'])))
@outputToString @outputToString
def generateListOfDefinitions(fns, name='opencl_fn_list'): def generateListOfDefinitions(fns, name='opencl_fn_list'):
print '// generated by %s' % os.path.basename(sys.argv[0]) print('// generated by %s' % os.path.basename(sys.argv[0]))
print 'static const struct DynamicFnEntry* %s[] = {' % (name) print('static const struct DynamicFnEntry* %s[] = {' % (name))
for fn in fns: for fn in fns:
commentStr = '' if fn.has_key('enabled') else '//' commentStr = '' if 'enabled' in fn else '//'
if fn.has_key('enabled'): if 'enabled' in fn:
print ' &%s_definition,' % (fn['name']) print(' &%s_definition,' % (fn['name']))
else: else:
print ' NULL/*&%s_definition*/,' % (fn['name']) print(' NULL/*&%s_definition*/,' % (fn['name']))
first = False first = False
print '};' print('};')
@outputToString @outputToString
def generateEnums(fns, prefix='OPENCL_FN'): def generateEnums(fns, prefix='OPENCL_FN'):
print '// generated by %s' % os.path.basename(sys.argv[0]) print('// generated by %s' % os.path.basename(sys.argv[0]))
print 'enum %s_ID {' % prefix print('enum %s_ID {' % prefix)
for (i, fn) in enumerate(fns): for (i, fn) in enumerate(fns):
commentStr = '' if fn.has_key('enabled') else '//' commentStr = '' if 'enabled' in fn else '//'
print commentStr + (' %s_%s = %d,' % (prefix, fn['name'], i)) print(commentStr + (' %s_%s = %d,' % (prefix, fn['name'], i)))
print '};' print('};')
@outputToString @outputToString
def generateRemapOrigin(fns): def generateRemapOrigin(fns):
print '// generated by %s' % os.path.basename(sys.argv[0]) print('// generated by %s' % os.path.basename(sys.argv[0]))
for fn in fns: for fn in fns:
print '#define %s %s_' % (fn['name'], fn['name']) print('#define %s %s_' % (fn['name'], fn['name']))
@outputToString @outputToString
def generateRemapDynamic(fns): def generateRemapDynamic(fns):
print '// generated by %s' % os.path.basename(sys.argv[0]) print('// generated by %s' % os.path.basename(sys.argv[0]))
for fn in fns: for fn in fns:
print '#undef %s' % (fn['name']) print('#undef %s' % (fn['name']))
commentStr = '' if fn.has_key('enabled') else '//' commentStr = '' if 'enabled' in fn else '//'
print commentStr + ('#define %s %s_pfn' % (fn['name'], fn['name'])) print(commentStr + ('#define %s %s_pfn' % (fn['name'], fn['name'])))
@outputToString @outputToString
def generateFnDeclaration(fns): def generateFnDeclaration(fns):
print '// generated by %s' % os.path.basename(sys.argv[0]) print('// generated by %s' % os.path.basename(sys.argv[0]))
for fn in fns: for fn in fns:
commentStr = '' if fn.has_key('enabled') else '//' commentStr = '' if 'enabled' in fn else '//'
print commentStr + ('extern CL_RUNTIME_EXPORT %s %s (%s *%s)(%s);' % (' '.join(fn['modifiers']), ' '.join(fn['ret']), ' '.join(fn['calling']), print(commentStr + ('extern CL_RUNTIME_EXPORT %s %s (%s *%s)(%s);' % (' '.join(fn['modifiers']), ' '.join(fn['ret']), ' '.join(fn['calling']),
fn['name'], ', '.join(fn['params'] if not fn.has_key('params_full') else fn['params_full']))) fn['name'], ', '.join(fn['params'] if 'params_full' not in fn else fn['params_full']))))
@outputToString @outputToString
def generateTemplates(total, lprefix, switch_name, calling_convention=''): def generateTemplates(total, lprefix, switch_name, calling_convention=''):
print '// generated by %s' % os.path.basename(sys.argv[0]) print('// generated by %s' % os.path.basename(sys.argv[0]))
for sz in range(total): for sz in range(total):
template_params = ['ID', '_R', 'decl_args'] template_params = ['ID', '_R', 'decl_args']
params = ['p%d' % (i + 1) for i in range(0, sz)] params = ['p%d' % (i + 1) for i in range(0, sz)]
print '#define %s%d(%s) \\' % (lprefix, sz, ', '.join(template_params)) print('#define %s%d(%s) \\' % (lprefix, sz, ', '.join(template_params)))
print ' typedef _R (%s *ID##FN)decl_args; \\' % (calling_convention) print(' typedef _R (%s *ID##FN)decl_args; \\' % (calling_convention))
print ' static _R %s ID##_switch_fn decl_args \\' % (calling_convention) print(' static _R %s ID##_switch_fn decl_args \\' % (calling_convention))
print ' { return ((ID##FN)%s(ID))(%s); } \\' % (switch_name, ', '.join(params)) print(' { return ((ID##FN)%s(ID))(%s); } \\' % (switch_name, ', '.join(params)))
print '' print('')
@outputToString @outputToString
def generateInlineWrappers(fns): def generateInlineWrappers(fns):
print '// generated by %s' % os.path.basename(sys.argv[0]) print('// generated by %s' % os.path.basename(sys.argv[0]))
for fn in fns: for fn in fns:
commentStr = '' if fn.has_key('enabled') else '//' commentStr = '' if 'enabled' in fn else '//'
print '#undef %s' % (fn['name']) print('#undef %s' % (fn['name']))
print commentStr + ('#define %s %s_fn' % (fn['name'], fn['name'])) print(commentStr + ('#define %s %s_fn' % (fn['name'], fn['name'])))
params = [] params = []
call_params = [] call_params = []
for i in range(0, len(fn['params'])): for i in range(0, len(fn['params'])):
...@@ -251,23 +252,23 @@ def generateInlineWrappers(fns): ...@@ -251,23 +252,23 @@ def generateInlineWrappers(fns):
call_params.append('p%d' % (i)) call_params.append('p%d' % (i))
if len(fn['ret']) == 1 and fn['ret'][0] == 'void': if len(fn['ret']) == 1 and fn['ret'][0] == 'void':
print commentStr + ('inline void %s(%s) { %s_pfn(%s); }' \ print(commentStr + ('inline void %s(%s) { %s_pfn(%s); }' \
% (fn['name'], ', '.join(params), fn['name'], ', '.join(call_params))) % (fn['name'], ', '.join(params), fn['name'], ', '.join(call_params))))
else: else:
print commentStr + ('inline %s %s(%s) { return %s_pfn(%s); }' \ print(commentStr + ('inline %s %s(%s) { return %s_pfn(%s); }' \
% (' '.join(fn['ret']), fn['name'], ', '.join(params), fn['name'], ', '.join(call_params))) % (' '.join(fn['ret']), fn['name'], ', '.join(params), fn['name'], ', '.join(call_params))))
def ProcessTemplate(inputFile, ctx, noteLine='//\n// AUTOGENERATED, DO NOT EDIT\n//'): def ProcessTemplate(inputFile, ctx, noteLine='//\n// AUTOGENERATED, DO NOT EDIT\n//'):
f = open(inputFile, "r") f = open(inputFile, "r")
if noteLine: if noteLine:
print noteLine print(noteLine)
for line in f: for line in f:
if line.startswith('@'): if line.startswith('@'):
assert line[-1] == '\n' assert line[-1] == '\n'
line = line[:-1] # remove '\n' line = line[:-1] # remove '\n'
assert line[-1] == '@' assert line[-1] == '@'
name = line[1:-1] name = line[1:-1]
assert ctx.has_key(name), name assert name in ctx, name
line = ctx[name] + ('\n' if len(ctx[name]) > 0 and ctx[name][-1] != '\n' else '') line = ctx[name] + ('\n' if len(ctx[name]) > 0 and ctx[name][-1] != '\n' else '')
sys.stdout.write(line) sys.stdout.write(line)
f.close() f.close()
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
# usage: # usage:
# cat opencl11/cl.h | $0 cl_runtime_opencl11 # cat opencl11/cl.h | $0 cl_runtime_opencl11
# cat opencl12/cl.h | $0 cl_runtime_opencl12 # cat opencl12/cl.h | $0 cl_runtime_opencl12
from __future__ import print_function
import sys, re; import sys, re;
from common import remove_comments, getTokens, getParameters, postProcessParameters from common import remove_comments, getTokens, getParameters, postProcessParameters
...@@ -77,7 +78,7 @@ while True: ...@@ -77,7 +78,7 @@ while True:
name = parts[i]; i += 1; name = parts[i]; i += 1;
fn['name'] = name fn['name'] = name
print 'name=' + name print('name=' + name)
params = getParameters(i, parts) params = getParameters(i, parts)
...@@ -88,7 +89,7 @@ while True: ...@@ -88,7 +89,7 @@ while True:
f.close() f.close()
print 'Found %d functions' % len(fns) print('Found %d functions' % len(fns))
postProcessParameters(fns) postProcessParameters(fns)
......
#!/bin/python #!/bin/python
# usage: # usage:
# cat clAmdBlas.h | $0 # cat clAmdBlas.h | $0
from __future__ import print_function
import sys, re; import sys, re;
from common import remove_comments, getTokens, getParameters, postProcessParameters from common import remove_comments, getTokens, getParameters, postProcessParameters
...@@ -69,7 +70,7 @@ while True: ...@@ -69,7 +70,7 @@ while True:
name = parts[i]; i += 1; name = parts[i]; i += 1;
fn['name'] = name fn['name'] = name
print 'name=' + name print('name=' + name)
params = getParameters(i, parts) params = getParameters(i, parts)
...@@ -80,7 +81,7 @@ while True: ...@@ -80,7 +81,7 @@ while True:
f.close() f.close()
print 'Found %d functions' % len(fns) print('Found %d functions' % len(fns))
postProcessParameters(fns) postProcessParameters(fns)
......
#!/bin/python #!/bin/python
# usage: # usage:
# cat clAmdFft.h | $0 # cat clAmdFft.h | $0
from __future__ import print_function
import sys, re; import sys, re;
from common import remove_comments, getTokens, getParameters, postProcessParameters from common import remove_comments, getTokens, getParameters, postProcessParameters
...@@ -63,7 +64,7 @@ while True: ...@@ -63,7 +64,7 @@ while True:
name = parts[i]; i += 1; name = parts[i]; i += 1;
fn['name'] = name fn['name'] = name
print 'name=' + name print('name=' + name)
params = getParameters(i, parts) params = getParameters(i, parts)
...@@ -77,7 +78,7 @@ while True: ...@@ -77,7 +78,7 @@ while True:
f.close() f.close()
print 'Found %d functions' % len(fns) print('Found %d functions' % len(fns))
postProcessParameters(fns) postProcessParameters(fns)
......
from __future__ import print_function
import argparse import argparse
import cv2 as cv import cv2 as cv
import tensorflow as tf import tensorflow as tf
...@@ -199,8 +200,8 @@ with tf.Session() as sess: ...@@ -199,8 +200,8 @@ with tf.Session() as sess:
outDNN = cvNet.forward(out_nodes) outDNN = cvNet.forward(out_nodes)
outTF = sess.run([mbox_loc, mbox_conf_flatten], feed_dict={inp: inputData.transpose(0, 2, 3, 1)}) outTF = sess.run([mbox_loc, mbox_conf_flatten], feed_dict={inp: inputData.transpose(0, 2, 3, 1)})
print 'Max diff @ locations: %e' % np.max(np.abs(outDNN[0] - outTF[0])) print('Max diff @ locations: %e' % np.max(np.abs(outDNN[0] - outTF[0])))
print 'Max diff @ confidence: %e' % np.max(np.abs(outDNN[1] - outTF[1])) print('Max diff @ confidence: %e' % np.max(np.abs(outDNN[1] - outTF[1])))
# Save a graph # Save a graph
graph_def = sess.graph.as_graph_def() graph_def = sess.graph.as_graph_def()
......
#!/usr/bin/env python #!/usr/bin/env python
from __future__ import print_function
import sys, os, re import sys, os, re
classes_ignore_list = ( classes_ignore_list = (
...@@ -148,9 +149,9 @@ class JavaParser: ...@@ -148,9 +149,9 @@ class JavaParser:
if __name__ == '__main__': if __name__ == '__main__':
if len(sys.argv) < 2: if len(sys.argv) < 2:
print "Usage:\n", \ print("Usage:\n", \
os.path.basename(sys.argv[0]), \ os.path.basename(sys.argv[0]), \
"<Classes/Tests dir1/file1> [<Classes/Tests dir2/file2> ...]\n", "Not tested methods are loggedto stdout." "<Classes/Tests dir1/file1> [<Classes/Tests dir2/file2> ...]\n", "Not tested methods are loggedto stdout.")
exit(0) exit(0)
parser = JavaParser() parser = JavaParser()
for x in sys.argv[1:]: for x in sys.argv[1:]:
......
#!/usr/bin/env python #!/usr/bin/env python
from __future__ import print_function
import testlog_parser, sys, os, xml, glob, re import testlog_parser, sys, os, xml, glob, re
from table_formatter import * from table_formatter import *
from optparse import OptionParser from optparse import OptionParser
...@@ -154,6 +155,6 @@ if __name__ == "__main__": ...@@ -154,6 +155,6 @@ if __name__ == "__main__":
htmlPrintFooter(sys.stdout) htmlPrintFooter(sys.stdout)
else: else:
if not options.failedOnly: if not options.failedOnly:
print '\nOverall time: %.2f min\n' % overall_time print('\nOverall time: %.2f min\n' % overall_time)
tbl.consolePrintTable(sys.stdout) tbl.consolePrintTable(sys.stdout)
print 2 * '\n' print(2 * '\n')
#!/usr/bin/env python #!/usr/bin/env python
from __future__ import print_function
import sys, re, os.path, cgi, stat, math import sys, re, os.path, cgi, stat, math
from optparse import OptionParser from optparse import OptionParser
from color import getColorizer, dummyColorizer from color import getColorizer, dummyColorizer
...@@ -723,7 +724,7 @@ def formatValue(val, metric, units = None): ...@@ -723,7 +724,7 @@ def formatValue(val, metric, units = None):
if __name__ == "__main__": if __name__ == "__main__":
if len(sys.argv) < 2: if len(sys.argv) < 2:
print "Usage:\n", os.path.basename(sys.argv[0]), "<log_name>.xml" print("Usage:\n", os.path.basename(sys.argv[0]), "<log_name>.xml")
exit(0) exit(0)
parser = OptionParser() parser = OptionParser()
......
#!/usr/bin/env python #!/usr/bin/env python
from __future__ import print_function
import collections import collections
import re import re
import os.path import os.path
...@@ -108,7 +109,7 @@ class TestInfo(object): ...@@ -108,7 +109,7 @@ class TestInfo(object):
def dump(self, units="ms"): def dump(self, units="ms"):
print "%s ->\t\033[1;31m%s\033[0m = \t%.2f%s" % (str(self), self.status, self.get("gmean", units), units) print("%s ->\t\033[1;31m%s\033[0m = \t%.2f%s" % (str(self), self.status, self.get("gmean", units), units))
def getName(self): def getName(self):
...@@ -198,22 +199,22 @@ def parseLogFile(filename): ...@@ -198,22 +199,22 @@ def parseLogFile(filename):
if __name__ == "__main__": if __name__ == "__main__":
if len(sys.argv) < 2: if len(sys.argv) < 2:
print "Usage:\n", os.path.basename(sys.argv[0]), "<log_name>.xml" print("Usage:\n", os.path.basename(sys.argv[0]), "<log_name>.xml")
exit(0) exit(0)
for arg in sys.argv[1:]: for arg in sys.argv[1:]:
print "Processing {}...".format(arg) print("Processing {}...".format(arg))
run = parseLogFile(arg) run = parseLogFile(arg)
print "Properties:" print("Properties:")
for (prop_name, prop_value) in run.properties.items(): for (prop_name, prop_value) in run.properties.items():
print "\t{} = {}".format(prop_name, prop_value) print("\t{} = {}".format(prop_name, prop_value))
print "Tests:" print("Tests:")
for t in sorted(run.tests): for t in sorted(run.tests):
t.dump() t.dump()
print print()
from __future__ import print_function
import cv2 as cv import cv2 as cv
import numpy as np import numpy as np
import argparse import argparse
...@@ -43,7 +44,7 @@ while cv.waitKey(1) < 0: ...@@ -43,7 +44,7 @@ while cv.waitKey(1) < 0:
t, _ = net.getPerfProfile() t, _ = net.getPerfProfile()
freq = cv.getTickFrequency() / 1000 freq = cv.getTickFrequency() / 1000
print t / freq, 'ms' print(t / freq, 'ms')
if args.median_filter: if args.median_filter:
out = cv.medianBlur(out, args.median_filter) out = cv.medianBlur(out, args.median_filter)
......
from __future__ import print_function
# Script to evaluate MobileNet-SSD object detection model trained in TensorFlow # Script to evaluate MobileNet-SSD object detection model trained in TensorFlow
# using both TensorFlow and OpenCV. Example: # using both TensorFlow and OpenCV. Example:
# #
...@@ -115,14 +116,14 @@ pylab.rcParams['figure.figsize'] = (10.0, 8.0) ...@@ -115,14 +116,14 @@ pylab.rcParams['figure.figsize'] = (10.0, 8.0)
annType = ['segm','bbox','keypoints'] annType = ['segm','bbox','keypoints']
annType = annType[1] #specify type here annType = annType[1] #specify type here
prefix = 'person_keypoints' if annType=='keypoints' else 'instances' prefix = 'person_keypoints' if annType=='keypoints' else 'instances'
print 'Running demo for *%s* results.'%(annType) print('Running demo for *%s* results.'%(annType))
#initialize COCO ground truth api #initialize COCO ground truth api
cocoGt=COCO(args.annotations) cocoGt=COCO(args.annotations)
#initialize COCO detections api #initialize COCO detections api
for resFile in ['tf_result.json', 'cv_result.json']: for resFile in ['tf_result.json', 'cv_result.json']:
print resFile print(resFile)
cocoDt=cocoGt.loadRes(resFile) cocoDt=cocoGt.loadRes(resFile)
cocoEval = COCOeval(cocoGt,cocoDt,annType) cocoEval = COCOeval(cocoGt,cocoDt,annType)
......
from __future__ import print_function
import sys import sys
import cv2 as cv import cv2 as cv
...@@ -16,8 +17,8 @@ max_Trackbar = 5 ...@@ -16,8 +17,8 @@ max_Trackbar = 5
def main(argv): def main(argv):
if (len(sys.argv) < 3): if (len(sys.argv) < 3):
print 'Not enough parameters' print('Not enough parameters')
print 'Usage:\nmatch_template_demo.py <image_name> <template_name> [<mask_name>]' print('Usage:\nmatch_template_demo.py <image_name> <template_name> [<mask_name>]')
return -1 return -1
## [load_image] ## [load_image]
...@@ -33,7 +34,7 @@ def main(argv): ...@@ -33,7 +34,7 @@ def main(argv):
mask = cv.imread( sys.argv[3], cv.IMREAD_COLOR ) mask = cv.imread( sys.argv[3], cv.IMREAD_COLOR )
if ((img is None) or (templ is None) or (use_mask and (mask is None))): if ((img is None) or (templ is None) or (use_mask and (mask is None))):
print 'Can\'t read one of the images' print('Can\'t read one of the images')
return -1 return -1
## [load_image] ## [load_image]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment