From 3f8c65881f7f9f6788c3fb2d5d5b70914e763d64 Mon Sep 17 00:00:00 2001
From: Mathieu Faverge <mathieu.faverge@inria.fr>
Date: Fri, 16 Jun 2017 19:06:47 +0200
Subject: [PATCH] Make it compatible with python 3

---
 modules/precision_generator/Conversion.py     | 41 +++++++++++--------
 modules/precision_generator/codegen.py        | 20 ++++-----
 .../precision_generator/genDependencies.py    | 10 ++---
 modules/precision_generator/subs.py           |  5 ++-
 4 files changed, 43 insertions(+), 33 deletions(-)

diff --git a/modules/precision_generator/Conversion.py b/modules/precision_generator/Conversion.py
index 00202d7..5921fe1 100644
--- a/modules/precision_generator/Conversion.py
+++ b/modules/precision_generator/Conversion.py
@@ -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."""
diff --git a/modules/precision_generator/codegen.py b/modules/precision_generator/codegen.py
index 8b03223..5066880 100755
--- a/modules/precision_generator/codegen.py
+++ b/modules/precision_generator/codegen.py
@@ -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:
diff --git a/modules/precision_generator/genDependencies.py b/modules/precision_generator/genDependencies.py
index 973e5aa..4e6cccf 100755
--- a/modules/precision_generator/genDependencies.py
+++ b/modules/precision_generator/genDependencies.py
@@ -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();
diff --git a/modules/precision_generator/subs.py b/modules/precision_generator/subs.py
index 4d99a9d..6d23a06 100644
--- a/modules/precision_generator/subs.py
+++ b/modules/precision_generator/subs.py
@@ -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'    ),
-- 
GitLab