Attention une mise à jour du service Gitlab va être effectuée le mardi 18 janvier (et non lundi 17 comme annoncé précédemment) entre 18h00 et 18h30. Cette mise à jour va générer une interruption du service dont nous ne maîtrisons pas complètement la durée mais qui ne devrait pas excéder quelques minutes.

Commit 3f8c6588 authored by Mathieu Faverge's avatar Mathieu Faverge
Browse files

Make it compatible with python 3

parent 55aad73e
......@@ -129,13 +129,15 @@ class Conversion:
self.copy = [];
self.converted = [];
load = False;
if self.debug: print '|'.join(self.types), self.precision, relpath(path.join(self.file[0],self.file[1]));
if self.debug:
print( '|'.join(self.types), self.precision, relpath(path.join(self.file[0],self.file[1])) );
for precision in self.precisions:
"""For each destination precision, make the appropriate changes to the file name/data."""
new_file = self.convert(self.file[1], precision);
if self.debug: print precision,':',
if self.debug:
print(precision,':')
copy = False;
if new_file <> self.file[1] or self.prefix is not None:
if new_file != self.file[1] or self.prefix is not None:
if self.prefix is None:
"""If no prefix is specified, use the file's current folder."""
prefix = ''
......@@ -152,31 +154,38 @@ class Conversion:
if self.make:
"""If in GNU Make mode, write the rule to create the file."""
file_in = relpath(path.join(self.file[0],self.file[1]));
print file_out+':',file_in;
print "\t$(PYTHON)",path.realpath(sys.argv[0]),makeprefix,'-p',precision,"--file",file_in;
print(file_out+':',file_in);
print("\t$(PYTHON)",path.realpath(sys.argv[0]),makeprefix,'-p',precision,"--file",file_in);
self.names.append(new_file);
self.files_out.append(file_out);
self.dependencies.append( (path.join(self.file[0],self.file[1]), precision, file_out) );
if self.debug: print relpath(conversion), ':',
if self.debug:
print(relpath(conversion), ':')
try:
"""Try to emulate Make like time based dependencies."""
date = path.getmtime(conversion);
diff = self.date - date;
self.dates.append(diff);
if self.debug:
if diff > 0: print 'Old',
else: print 'Current',
print diff;
if diff > 0: load = True;
if diff > 0:
print('Old')
else:
print('Current')
print(diff);
if diff > 0:
load = True;
except:
if self.debug: print 'Missing';
if self.debug:
print('Missing');
self.dates.append(None);
load = True;
elif precision <> self.precision :
elif precision != self.precision :
"""There was no change in the file's name, thus,
no work can be done without overwriting the original."""
if self.debug: print '<No Change>',':';
else: print >> sys.stderr, new_file, 'had no change for', precision;
if self.debug:
print('<No Change>',':')
else:
print >> sys.stderr, new_file, 'had no change for', precision;
self.names.append(None);
self.dates.append(None);
self.copy.append(copy);
......@@ -238,7 +247,7 @@ class Conversion:
replace = replace.replace('\)',')');
data = re.sub(search, replace, data);
except:
print 'Bad replacement pair ',i,'in',sub_type;
print('Bad replacement pair ',i,'in',sub_type);
continue;
return data;
......@@ -258,7 +267,7 @@ class Conversion:
if sub_type == 'all': continue;
try:
data = self.substitute(sub_type, data, precision);
except Exception, e:
except Exception(e):
raise ValueError('I encountered an unrecoverable error while working in subtype:',sub_type+'.');
"""Replace the replacement keywork with one that signifies this is an output file,
to prevent multiple replacement issues if run again."""
......
......@@ -82,8 +82,8 @@ def main():
if options.make:
"""If the program should be GNU Make friendly."""
print '## Automatically generated Makefile';
print 'PYTHON ?= python';
print('## Automatically generated Makefile');
print('PYTHON ?= python');
c = Conversion(); """This initializes the variable for static member access."""
......@@ -93,23 +93,23 @@ def main():
"""Try creating and executing a converter."""
c = Conversion(tuple[0], tuple[1], tuple[2]);
c.run();
except Exception, e:
except Exception(e):
print >> sys.stderr, str(e);
continue;
if options.make:
"""If the program should be GNU Make friendly."""
print 'gen = ',' '+' '.join(c.files_out);
print 'cleangen:';
print '\trm -f $(gen)';
print 'generate: $(gen)';
print '.PHONY: cleangen generate';
print('gen = ',' '+' '.join(c.files_out));
print('cleangen:');
print('\trm -f $(gen)');
print('generate: $(gen)');
print('.PHONY: cleangen generate');
if options.in_print:
"""Should we print the input files?"""
print ' '.join(c.files_in);
print(' '.join(c.files_in));
if options.out_print:
"""Should we print the output files?"""
print ' '.join(c.files_out);
print(' '.join(c.files_out));
if options.out_clean:
"""Clean generated files"""
for file in c.files_out:
......
......@@ -77,7 +77,7 @@ class GenConversion:
for precision in self.precisions:
"""For each destination precision, make the appropriate changes to the file name/data."""
new_file = self.convert(filename, precision);
if new_file <> filename or self.prefix is not None:
if new_file != filename or self.prefix is not None:
if self.prefix is None:
"""If no prefix is specified, use the file's current folder."""
prefix = ''
......@@ -118,7 +118,7 @@ class GenConversion:
replace = replace.replace('\)',')');
data = re.sub(search, replace, data);
except:
print 'Bad replacement pair ',i,'in',sub_type;
print('Bad replacement pair ', i, 'in', sub_type);
continue;
return data;
......@@ -138,7 +138,7 @@ class GenConversion:
if sub_type == 'all': continue;
try:
data = self.substitute(sub_type, data, precision);
except Exception, e:
except Exception(e):
raise ValueError('I encountered an unrecoverable error while working in subtype:',sub_type+'.');
return data;
......@@ -201,11 +201,11 @@ def main():
try:
"""Try creating and executing a converter."""
result += c.run(file);
except Exception, e:
except Exception(e):
print >> sys.stderr, str(e);
continue;
print result;
print(result);
if __name__ == "__main__":
main();
......@@ -150,9 +150,9 @@ subs = {
('', 'thread_ps', 'thread_pd', 'thread_pc', 'thread_pz' ),
# ----- Complex numbers
# \b regexp here avoids conjugate -> conjfugate,
# \b regexp here avoids conjugate -> conjfugate => replaced by a double rule as \b was not working
# assuming we always translate from z, not to z.
('', '', '', 'conjf', 'conj\b' ),
('', '', '', 'conjf', 'conj' ),
('', 'fabsf', 'fabs', 'cabsf', 'cabs' ),
('', '', '', 'cuCrealf', 'cuCreal' ),
('', '', '', 'cuCimagf', 'cuCimag' ),
......@@ -160,6 +160,7 @@ subs = {
('', 'fabsf', 'fabs', 'cuCabsf', 'cuCabs' ),
('', '', '', 'crealf', 'creal' ),
('', 'sqrtf', 'sqrt', 'csqrtf', 'csqrt' ),
('', '', '', 'conjugate', 'conjfugate' ),
# ----- CUDA
('', 'cublasIsamax', 'cublasIdamax', 'cublasIcamax', 'cublasIzamax' ),
......
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