Mentions légales du service

Skip to content
Snippets Groups Projects
Commit 0622c996 authored by Mathieu Faverge's avatar Mathieu Faverge
Browse files

Add a preliminary pass on mixed precision files

parent becf28f4
No related branches found
No related tags found
No related merge requests found
......@@ -181,7 +181,46 @@ class SourceFile( object ):
# --------------------
def _substitute( self, text, precision ):
'''Apply substitutions to text for given precision.'''
'''Apply substitutions to text for given precision.
If we use mixed precision algrotihm as input and output, we
apply a first pass from single precision, and then the mixed
one.
'''
if self._src[0] == 'x' and precision[0] == 'x':
precfrom = self._src[1]
precto = precision[1]
try:
# Get substitution table based on self._table
subs_o = self._subs.subs[ self._table ] # original
subs_s = self._subs.subs_search[ self._table ] # compiled as search regexp
subs_r = self._subs.subs_replace[ self._table ] # with regexp removed for replacement
# Get which column is from and to.
header = subs_o[0]
jfrom = header.index( precfrom )
jto = header.index( precto )
except Exception as err:
print( "Error: bad table or precision in '%s', @precisions %s %s -> %s:" %
(self._filename, self._table, precfrom, self._dsts), file=sys.stderr )
traceback.print_exc()
exit(1)
# Apply substitutions
try:
line = 0
for (orig, search, replace) in zip( subs_o[1:], subs_s[1:], subs_r[1:] ):
line += 1
if search[jfrom] is None:
search[jfrom] = re.compile( orig[jfrom] )
text = re.sub( search[jfrom], replace[jto], text )
# end
except Exception as err:
print( "Error: in row %d of substitution table '%s': %s" %
(line, self._table, subs_o[line]), file=sys.stderr )
traceback.print_exc()
exit(1)
try:
# Get substitution table based on self._table
subs_o = self._subs.subs[ self._table ] # original
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment