<s> import errno <EOL> import os <EOL> import sys <EOL> from theano . compat import PY3 <EOL> from theano . gof . compilelock import get_lock , release_lock <EOL> from theano import config <EOL> from . import cmodule <EOL> if os . path . exists ( os . path . join ( config . compiledir , '<STR_LIT>' ) ) : <EOL> os . remove ( os . path . join ( config . compiledir , '<STR_LIT>' ) ) <EOL> def compile_cutils_code ( ) : <EOL> types = [ '<STR_LIT>' + t for t in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ] ] <EOL> complex_types = [ '<STR_LIT>' + t for t in [ '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ] ] <EOL> inplace_map_template = """<STR_LIT>""" <EOL> floatadd = ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> complexadd = """<STR_LIT>""" <EOL> fns = '<STR_LIT>' . join ( [ inplace_map_template % { '<STR_LIT:type>' : t , '<STR_LIT>' : t . upper ( ) , <EOL> '<STR_LIT>' : floatadd % { '<STR_LIT:type>' : t } } <EOL> for t in types ] + <EOL> [ inplace_map_template % { '<STR_LIT:type>' : t , '<STR_LIT>' : t . upper ( ) , <EOL> '<STR_LIT>' : complexadd % { '<STR_LIT:type>' : t } } <EOL> for t in complex_types ] ) <EOL> def gen_binop ( type , typen ) : <EOL> return """<STR_LIT>""" % dict ( type = type , typen = typen ) <EOL> fn_array = ( "<STR_LIT>" + <EOL> '<STR_LIT>' . join ( [ gen_binop ( type = t , typen = t . upper ( ) ) <EOL> for t in types + complex_types ] ) + "<STR_LIT>" ) <EOL> def gen_num ( typen ) : <EOL> return """<STR_LIT>""" % dict ( type = type , typen = typen ) <EOL> type_number_array = ( "<STR_LIT>" + <EOL> '<STR_LIT>' . join ( [ gen_num ( typen = t . upper ( ) ) <EOL> for t in types + complex_types ] ) + "<STR_LIT>" ) <EOL> code = ( """<STR_LIT>""" + fns + fn_array + type_number_array + """<STR_LIT>""" ) <EOL> return code <EOL> def compile_cutils ( ) : <EOL> """<STR_LIT>""" <EOL> code = ( """<STR_LIT>""" ) <EOL> code += compile_cutils_code ( ) <EOL> code += ( """<STR_LIT>""" ) <EOL> if PY3 : <EOL> code = code . replace ( "<STR_LIT>" , '<STR_LIT>' , <NUM_LIT:1> ) <EOL> code = code . replace ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> code += """<STR_LIT>""" <EOL> else : <EOL> code += """<STR_LIT>""" <EOL> loc = os . path . join ( config . compiledir , '<STR_LIT>' ) <EOL> if not os . path . exists ( loc ) : <EOL> try : <EOL> os . mkdir ( loc ) <EOL> except OSError as e : <EOL> assert e . errno == errno . EEXIST <EOL> assert os . path . exists ( loc ) , loc <EOL> args = cmodule . GCC_compiler . compile_args ( ) <EOL> cmodule . GCC_compiler . compile_str ( '<STR_LIT>' , code , location = loc , <EOL> preargs = args ) <EOL> try : <EOL> sys . path . insert ( <NUM_LIT:0> , config . compiledir ) <EOL> location = os . path . join ( config . compiledir , '<STR_LIT>' ) <EOL> if not os . path . exists ( location ) : <EOL> try : <EOL> os . mkdir ( location ) <EOL> except OSError as e : <EOL> assert e . errno == errno . EEXIST <EOL> assert os . path . exists ( location ) , location <EOL> if not os . path . exists ( os . path . join ( location , '<STR_LIT>' ) ) : <EOL> open ( os . path . join ( location , '<STR_LIT>' ) , '<STR_LIT:w>' ) . close ( ) <EOL> try : <EOL> from cutils_ext . cutils_ext import * <EOL> except ImportError : <EOL> get_lock ( ) <EOL> try : <EOL> try : <EOL> from cutils_ext . cutils_ext import * <EOL> except ImportError : <EOL> compile_cutils ( ) <EOL> from cutils_ext . cutils_ext import * <EOL> finally : <EOL> release_lock ( ) <EOL> finally : <EOL> if sys . path [ <NUM_LIT:0> ] == config . compiledir : <EOL> del sys . path [ <NUM_LIT:0> ] </s>
