<s> """<STR_LIT>""" <EOL> from __future__ import division , print_function , absolute_import <EOL> UFUNCS = """<STR_LIT>""" <EOL> EXTRA_CODE_COMMON = """<STR_LIT>""" <EOL> EXTRA_CODE = """<STR_LIT>""" <EOL> EXTRA_CODE_BOTTOM = """<STR_LIT>""" <EOL> import os <EOL> import optparse <EOL> import re <EOL> import textwrap <EOL> add_newdocs = __import__ ( '<STR_LIT>' ) <EOL> CY_TYPES = { <EOL> '<STR_LIT:f>' : '<STR_LIT:float>' , <EOL> '<STR_LIT:d>' : '<STR_LIT>' , <EOL> '<STR_LIT:g>' : '<STR_LIT>' , <EOL> '<STR_LIT:F>' : '<STR_LIT>' , <EOL> '<STR_LIT:D>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:i>' : '<STR_LIT:int>' , <EOL> '<STR_LIT:l>' : '<STR_LIT>' , <EOL> '<STR_LIT:v>' : '<STR_LIT>' , <EOL> } <EOL> C_TYPES = { <EOL> '<STR_LIT:f>' : '<STR_LIT>' , <EOL> '<STR_LIT:d>' : '<STR_LIT>' , <EOL> '<STR_LIT:g>' : '<STR_LIT>' , <EOL> '<STR_LIT:F>' : '<STR_LIT>' , <EOL> '<STR_LIT:D>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:i>' : '<STR_LIT>' , <EOL> '<STR_LIT:l>' : '<STR_LIT>' , <EOL> '<STR_LIT:v>' : '<STR_LIT>' , <EOL> } <EOL> TYPE_NAMES = { <EOL> '<STR_LIT:f>' : '<STR_LIT>' , <EOL> '<STR_LIT:d>' : '<STR_LIT>' , <EOL> '<STR_LIT:g>' : '<STR_LIT>' , <EOL> '<STR_LIT:F>' : '<STR_LIT>' , <EOL> '<STR_LIT:D>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:i>' : '<STR_LIT>' , <EOL> '<STR_LIT:l>' : '<STR_LIT>' , <EOL> } <EOL> def cast_order ( c ) : <EOL> return [ '<STR_LIT>' . index ( x ) for x in c ] <EOL> DANGEROUS_DOWNCAST = set ( [ <EOL> ( '<STR_LIT:F>' , '<STR_LIT:i>' ) , ( '<STR_LIT:F>' , '<STR_LIT:l>' ) , ( '<STR_LIT:F>' , '<STR_LIT:f>' ) , ( '<STR_LIT:F>' , '<STR_LIT:d>' ) , ( '<STR_LIT:F>' , '<STR_LIT:g>' ) , <EOL> ( '<STR_LIT:D>' , '<STR_LIT:i>' ) , ( '<STR_LIT:D>' , '<STR_LIT:l>' ) , ( '<STR_LIT:D>' , '<STR_LIT:f>' ) , ( '<STR_LIT:D>' , '<STR_LIT:d>' ) , ( '<STR_LIT:D>' , '<STR_LIT:g>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT:i>' ) , ( '<STR_LIT>' , '<STR_LIT:l>' ) , ( '<STR_LIT>' , '<STR_LIT:f>' ) , ( '<STR_LIT>' , '<STR_LIT:d>' ) , ( '<STR_LIT>' , '<STR_LIT:g>' ) , <EOL> ( '<STR_LIT:f>' , '<STR_LIT:i>' ) , ( '<STR_LIT:f>' , '<STR_LIT:l>' ) , <EOL> ( '<STR_LIT:d>' , '<STR_LIT:i>' ) , ( '<STR_LIT:d>' , '<STR_LIT:l>' ) , <EOL> ( '<STR_LIT:g>' , '<STR_LIT:i>' ) , ( '<STR_LIT:g>' , '<STR_LIT:l>' ) , <EOL> ( '<STR_LIT:l>' , '<STR_LIT:i>' ) , <EOL> ] ) <EOL> NAN_VALUE = { <EOL> '<STR_LIT:f>' : '<STR_LIT>' , <EOL> '<STR_LIT:d>' : '<STR_LIT>' , <EOL> '<STR_LIT:g>' : '<STR_LIT>' , <EOL> '<STR_LIT:F>' : '<STR_LIT>' , <EOL> '<STR_LIT:D>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:i>' : '<STR_LIT>' , <EOL> '<STR_LIT:l>' : '<STR_LIT>' , <EOL> } <EOL> def generate_loop ( func_inputs , func_outputs , func_retval , <EOL> ufunc_inputs , ufunc_outputs ) : <EOL> """<STR_LIT>""" <EOL> if len ( func_inputs ) != len ( ufunc_inputs ) : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> if len ( func_outputs ) != len ( ufunc_outputs ) and not ( <EOL> func_retval != "<STR_LIT:v>" and len ( func_outputs ) + <NUM_LIT:1> == len ( ufunc_outputs ) ) : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> name = "<STR_LIT>" % ( <EOL> func_retval , func_inputs , func_outputs , ufunc_inputs , ufunc_outputs <EOL> ) <EOL> body = "<STR_LIT>" % name <EOL> body += "<STR_LIT>" <EOL> body += "<STR_LIT>" <EOL> body += "<STR_LIT>" <EOL> for j in range ( len ( ufunc_inputs ) ) : <EOL> body += "<STR_LIT>" % ( j , j ) <EOL> for j in range ( len ( ufunc_outputs ) ) : <EOL> body += "<STR_LIT>" % ( j , j + len ( ufunc_inputs ) ) <EOL> ftypes = [ ] <EOL> fvars = [ ] <EOL> outtypecodes = [ ] <EOL> for j in range ( len ( func_inputs ) ) : <EOL> ftypes . append ( CY_TYPES [ func_inputs [ j ] ] ) <EOL> fvars . append ( "<STR_LIT>" % ( <EOL> CY_TYPES [ func_inputs [ j ] ] , <EOL> CY_TYPES [ ufunc_inputs [ j ] ] , j ) ) <EOL> if len ( func_outputs ) + <NUM_LIT:1> == len ( ufunc_outputs ) : <EOL> func_joff = <NUM_LIT:1> <EOL> outtypecodes . append ( func_retval ) <EOL> body += "<STR_LIT>" % ( CY_TYPES [ func_retval ] , ) <EOL> else : <EOL> func_joff = <NUM_LIT:0> <EOL> for j , outtype in enumerate ( func_outputs ) : <EOL> body += "<STR_LIT>" % ( CY_TYPES [ outtype ] , j + func_joff ) <EOL> ftypes . append ( "<STR_LIT>" % CY_TYPES [ outtype ] ) <EOL> fvars . append ( "<STR_LIT>" % ( j + func_joff ) ) <EOL> outtypecodes . append ( outtype ) <EOL> body += "<STR_LIT>" <EOL> if len ( func_outputs ) + <NUM_LIT:1> == len ( ufunc_outputs ) : <EOL> rv = "<STR_LIT>" <EOL> else : <EOL> rv = "<STR_LIT>" <EOL> funcall = "<STR_LIT>" % ( <EOL> rv , CY_TYPES [ func_retval ] , "<STR_LIT:U+002CU+0020>" . join ( ftypes ) , "<STR_LIT:U+002CU+0020>" . join ( fvars ) ) <EOL> input_checks = [ ] <EOL> for j in range ( len ( func_inputs ) ) : <EOL> if ( ufunc_inputs [ j ] , func_inputs [ j ] ) in DANGEROUS_DOWNCAST : <EOL> chk = "<STR_LIT>" % ( <EOL> CY_TYPES [ func_inputs [ j ] ] , CY_TYPES [ ufunc_inputs [ j ] ] , j , <EOL> CY_TYPES [ ufunc_inputs [ j ] ] , j ) <EOL> input_checks . append ( chk ) <EOL> if input_checks : <EOL> body += "<STR_LIT>" % ( "<STR_LIT>" . join ( input_checks ) ) <EOL> body += "<STR_LIT:U+0020>" + funcall <EOL> body += "<STR_LIT>" <EOL> body += "<STR_LIT>" <EOL> for j , outtype in enumerate ( outtypecodes ) : <EOL> body += "<STR_LIT>" % ( <EOL> j , CY_TYPES [ outtype ] , NAN_VALUE [ outtype ] ) <EOL> else : <EOL> body += funcall <EOL> for j , ( outtype , fouttype ) in enumerate ( zip ( ufunc_outputs , outtypecodes ) ) : <EOL> if ( fouttype , outtype ) in DANGEROUS_DOWNCAST : <EOL> body += "<STR_LIT>" % ( j , CY_TYPES [ outtype ] , j ) <EOL> body += "<STR_LIT>" % ( <EOL> CY_TYPES [ outtype ] , j , CY_TYPES [ outtype ] , j ) <EOL> body += "<STR_LIT>" <EOL> body += "<STR_LIT>" <EOL> body += "<STR_LIT>" % ( <EOL> CY_TYPES [ outtype ] , j , CY_TYPES [ outtype ] , NAN_VALUE [ outtype ] ) <EOL> else : <EOL> body += "<STR_LIT>" % ( <EOL> CY_TYPES [ outtype ] , j , CY_TYPES [ outtype ] , j ) <EOL> for j in range ( len ( ufunc_inputs ) ) : <EOL> body += "<STR_LIT>" % ( j , j ) <EOL> for j in range ( len ( ufunc_outputs ) ) : <EOL> body += "<STR_LIT>" % ( j , j + len ( ufunc_inputs ) ) <EOL> body += "<STR_LIT>" <EOL> return name , body <EOL> def iter_variants ( inputs , outputs ) : <EOL> """<STR_LIT>""" <EOL> maps = [ <EOL> ( '<STR_LIT:i>' , '<STR_LIT:l>' ) , <EOL> ] <EOL> if not ( '<STR_LIT:i>' in inputs or '<STR_LIT:l>' in inputs ) : <EOL> maps = maps + [ ( a + '<STR_LIT>' , b + '<STR_LIT>' ) for a , b in maps ] <EOL> for src , dst in maps : <EOL> new_inputs = inputs <EOL> new_outputs = outputs <EOL> for a , b in zip ( src , dst ) : <EOL> new_inputs = new_inputs . replace ( a , b ) <EOL> new_outputs = new_outputs . replace ( a , b ) <EOL> yield new_inputs , new_outputs <EOL> class Ufunc ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , name , signatures , headers ) : <EOL> self . name = name <EOL> self . signatures = self . _parse_signatures ( signatures , headers ) <EOL> self . doc = add_newdocs . get ( "<STR_LIT>" + name ) <EOL> if self . doc is None : <EOL> raise ValueError ( "<STR_LIT>" % name ) <EOL> self . doc = textwrap . dedent ( self . doc ) . strip ( ) <EOL> self . function_name_overrides = { } <EOL> def _parse_signatures ( self , sigs_str , headers_str ) : <EOL> sigs = [ x . strip ( ) for x in sigs_str . split ( "<STR_LIT:U+002C>" ) if x . strip ( ) ] <EOL> headers = [ x . strip ( ) for x in headers_str . split ( "<STR_LIT:U+002C>" ) if x . strip ( ) ] <EOL> if len ( headers ) == <NUM_LIT:1> : <EOL> headers = headers * len ( sigs ) <EOL> if len ( headers ) != len ( sigs ) : <EOL> raise ValueError ( "<STR_LIT>" % ( <EOL> self . name , sigs_str , headers_str ) ) <EOL> return [ self . _parse_signature ( x ) + ( h , ) for x , h in zip ( sigs , headers ) ] <EOL> def _parse_signature ( self , sig ) : <EOL> m = re . match ( "<STR_LIT>" , sig ) <EOL> if m : <EOL> func , inarg , outarg , ret = [ x . strip ( ) for x in m . groups ( ) ] <EOL> if ret . count ( '<STR_LIT:*>' ) > <NUM_LIT:1> : <EOL> raise ValueError ( "<STR_LIT>" % ( self . name , sig ) ) <EOL> return ( func , inarg , outarg , ret ) <EOL> m = re . match ( "<STR_LIT>" , sig ) <EOL> if m : <EOL> func , inarg , ret = [ x . strip ( ) for x in m . groups ( ) ] <EOL> return ( func , inarg , "<STR_LIT>" , ret ) <EOL> raise ValueError ( "<STR_LIT>" % ( self . name , sig ) ) <EOL> def _get_signatures_and_loops ( self , all_loops ) : <EOL> inarg_num = None <EOL> outarg_num = None <EOL> seen = set ( ) <EOL> variants = [ ] <EOL> def add_variant ( func_name , inarg , outarg , ret , inp , outp ) : <EOL> if inp in seen : <EOL> return <EOL> seen . add ( inp ) <EOL> sig = ( func_name , inp , outp ) <EOL> if "<STR_LIT:v>" in outp : <EOL> raise ValueError ( "<STR_LIT>" % ( self . name , sig ) ) <EOL> if len ( inp ) != inarg_num or len ( outp ) != outarg_num : <EOL> raise ValueError ( "<STR_LIT>" % ( <EOL> self . name , sig , <EOL> inarg_num , outarg_num ) ) <EOL> loop_name , loop = generate_loop ( inarg , outarg , ret , inp , outp ) <EOL> all_loops [ loop_name ] = loop <EOL> variants . append ( ( func_name , loop_name , inp , outp ) ) <EOL> for func_name , inarg , outarg , ret , header in self . signatures : <EOL> outp = re . sub ( r'<STR_LIT>' , '<STR_LIT>' , ret ) + outarg <EOL> ret = ret . replace ( '<STR_LIT:*>' , '<STR_LIT>' ) <EOL> if inarg_num is None : <EOL> inarg_num = len ( inarg ) <EOL> outarg_num = len ( outp ) <EOL> inp , outp = list ( iter_variants ( inarg , outp ) ) [ <NUM_LIT:0> ] <EOL> add_variant ( func_name , inarg , outarg , ret , inp , outp ) <EOL> for func_name , inarg , outarg , ret , header in self . signatures : <EOL> outp = re . sub ( r'<STR_LIT>' , '<STR_LIT>' , ret ) + outarg <EOL> ret = ret . replace ( '<STR_LIT:*>' , '<STR_LIT>' ) <EOL> for inp , outp in iter_variants ( inarg , outp ) : <EOL> add_variant ( func_name , inarg , outarg , ret , inp , outp ) <EOL> variants . sort ( key = lambda v : cast_order ( v [ <NUM_LIT:2> ] ) ) <EOL> return variants , inarg_num , outarg_num <EOL> def cython_func_name ( self , c_name , specialized = False , prefix = "<STR_LIT>" , <EOL> override = True ) : <EOL> if override and c_name in self . function_name_overrides : <EOL> c_name = self . function_name_overrides [ c_name ] <EOL> prefix = "<STR_LIT>" <EOL> m = re . match ( r'<STR_LIT>' , c_name ) <EOL> if m : <EOL> c_base_name , fused_part = m . groups ( ) <EOL> else : <EOL> c_base_name , fused_part = c_name , "<STR_LIT>" <EOL> if specialized : <EOL> return "<STR_LIT>" % ( prefix , c_base_name , fused_part . replace ( '<STR_LIT:U+0020>' , '<STR_LIT:_>' ) ) <EOL> else : <EOL> return "<STR_LIT>" % ( prefix , c_base_name , ) <EOL> def get_prototypes ( self ) : <EOL> prototypes = [ ] <EOL> for func_name , inarg , outarg , ret , header in self . signatures : <EOL> ret = ret . replace ( '<STR_LIT:*>' , '<STR_LIT>' ) <EOL> c_args = ( [ C_TYPES [ x ] for x in inarg ] <EOL> + [ C_TYPES [ x ] + '<STR_LIT>' for x in outarg ] ) <EOL> cy_args = ( [ CY_TYPES [ x ] for x in inarg ] <EOL> + [ CY_TYPES [ x ] + '<STR_LIT>' for x in outarg ] ) <EOL> c_proto = "<STR_LIT>" % ( C_TYPES [ ret ] , "<STR_LIT:U+002CU+0020>" . join ( c_args ) ) <EOL> cy_proto = "<STR_LIT>" % ( CY_TYPES [ ret ] , "<STR_LIT:U+002CU+0020>" . join ( cy_args ) ) <EOL> prototypes . append ( ( func_name , c_proto , cy_proto , header ) ) <EOL> return prototypes <EOL> def generate ( self , all_loops ) : <EOL> toplevel = "<STR_LIT>" <EOL> variants , inarg_num , outarg_num = self . _get_signatures_and_loops ( all_loops ) <EOL> loops = [ ] <EOL> funcs = [ ] <EOL> types = [ ] <EOL> for func_name , loop_name , inputs , outputs in variants : <EOL> for x in inputs : <EOL> types . append ( TYPE_NAMES [ x ] ) <EOL> for x in outputs : <EOL> types . append ( TYPE_NAMES [ x ] ) <EOL> loops . append ( loop_name ) <EOL> funcs . append ( func_name ) <EOL> toplevel += "<STR_LIT>" % ( self . name , len ( loops ) ) <EOL> toplevel += "<STR_LIT>" % ( self . name , <NUM_LIT:2> * len ( funcs ) ) <EOL> toplevel += "<STR_LIT>" % ( self . name , len ( funcs ) ) <EOL> toplevel += "<STR_LIT>" % ( self . name , len ( types ) ) <EOL> toplevel += '<STR_LIT>' % ( <EOL> self . name , <EOL> self . doc . replace ( "<STR_LIT:\\>" , "<STR_LIT>" ) . replace ( '<STR_LIT:">' , '<STR_LIT>' ) . replace ( '<STR_LIT:\n>' , '<STR_LIT>' ) <EOL> ) <EOL> for j , function in enumerate ( loops ) : <EOL> toplevel += "<STR_LIT>" % ( self . name , j , function ) <EOL> for j , type in enumerate ( types ) : <EOL> toplevel += "<STR_LIT>" % ( self . name , j , type ) <EOL> for j , func in enumerate ( funcs ) : <EOL> toplevel += "<STR_LIT>" % ( self . name , j , <EOL> self . cython_func_name ( func , specialized = True ) ) <EOL> toplevel += "<STR_LIT>" % ( self . name , j , <EOL> self . name ) <EOL> for j , func in enumerate ( funcs ) : <EOL> toplevel += "<STR_LIT>" % ( <EOL> self . name , j , self . name , j ) <EOL> toplevel += ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' % ( len ( types ) / ( inarg_num + outarg_num ) , <EOL> inarg_num , outarg_num ) <EOL> ) . replace ( '<STR_LIT:@>' , self . name ) <EOL> return toplevel <EOL> @ classmethod <EOL> def parse_all ( cls , ufunc_str ) : <EOL> ufuncs = [ ] <EOL> lines = ufunc_str . splitlines ( ) <EOL> lines . sort ( ) <EOL> for line in lines : <EOL> line = line . strip ( ) <EOL> if not line : <EOL> continue <EOL> m = re . match ( "<STR_LIT>" , line ) <EOL> if not m : <EOL> raise ValueError ( "<STR_LIT>" % line ) <EOL> ufuncs . append ( cls ( m . group ( <NUM_LIT:1> ) , m . group ( <NUM_LIT:2> ) , m . group ( <NUM_LIT:3> ) ) ) <EOL> return ufuncs <EOL> def get_declaration ( ufunc , c_name , c_proto , cy_proto , header , proto_h_filename ) : <EOL> """<STR_LIT>""" <EOL> defs = [ ] <EOL> defs_h = [ ] <EOL> var_name = c_name . replace ( '<STR_LIT:[>' , '<STR_LIT:_>' ) . replace ( '<STR_LIT:]>' , '<STR_LIT:_>' ) . replace ( '<STR_LIT:U+0020>' , '<STR_LIT:_>' ) <EOL> if header . endswith ( '<STR_LIT>' ) : <EOL> defs . append ( "<STR_LIT>" % ( <EOL> header [ : - <NUM_LIT:4> ] , ufunc . cython_func_name ( c_name , prefix = "<STR_LIT>" ) , <EOL> ufunc . cython_func_name ( c_name ) ) ) <EOL> proto_name = '<STR_LIT>' % var_name <EOL> defs . append ( "<STR_LIT>" % ( cy_proto . replace ( '<STR_LIT>' , proto_name ) ) ) <EOL> defs . append ( "<STR_LIT>" % ( <EOL> proto_name , proto_name , ufunc . cython_func_name ( c_name , specialized = True ) ) ) <EOL> else : <EOL> new_name = "<STR_LIT>" % ( ufunc . cython_func_name ( c_name ) , c_name ) <EOL> defs . append ( "<STR_LIT>" % proto_h_filename ) <EOL> defs . append ( "<STR_LIT>" % ( cy_proto . replace ( '<STR_LIT>' , new_name ) ) ) <EOL> defs_h . append ( "<STR_LIT>" % header ) <EOL> defs_h . append ( "<STR_LIT>" % ( c_proto . replace ( '<STR_LIT>' , c_name ) ) ) <EOL> return defs , defs_h , var_name <EOL> def generate ( filename , cxx_fn_prefix , ufuncs ) : <EOL> proto_h_filename = os . path . splitext ( filename ) [ <NUM_LIT:0> ] + '<STR_LIT>' <EOL> cxx_proto_h_filename = cxx_fn_prefix + '<STR_LIT>' <EOL> cxx_pyx_filename = cxx_fn_prefix + "<STR_LIT>" <EOL> cxx_pxd_filename = cxx_fn_prefix + "<STR_LIT>" <EOL> toplevel = "<STR_LIT>" <EOL> defs = [ ] <EOL> defs_h = [ ] <EOL> all_loops = { } <EOL> cxx_defs = [ ] <EOL> cxx_pxd_defs = [ "<STR_LIT>" ] <EOL> cxx_defs_h = [ ] <EOL> ufuncs . sort ( key = lambda u : u . name ) <EOL> for ufunc in ufuncs : <EOL> cfuncs = ufunc . get_prototypes ( ) <EOL> for c_name , c_proto , cy_proto , header in cfuncs : <EOL> if header . endswith ( '<STR_LIT>' ) : <EOL> header = header [ : - <NUM_LIT:2> ] <EOL> item_defs , item_defs_h , var_name = get_declaration ( ufunc , c_name , c_proto , cy_proto , <EOL> header , cxx_proto_h_filename ) <EOL> cxx_defs . extend ( item_defs ) <EOL> cxx_defs_h . extend ( item_defs_h ) <EOL> cxx_defs . append ( "<STR_LIT>" % ( <EOL> var_name , ufunc . cython_func_name ( c_name , specialized = True , override = False ) ) ) <EOL> cxx_pxd_defs . append ( "<STR_LIT>" % ( var_name , ) ) <EOL> ufunc . function_name_overrides [ c_name ] = "<STR_LIT>" + var_name <EOL> else : <EOL> item_defs , item_defs_h , _ = get_declaration ( ufunc , c_name , c_proto , cy_proto , header , <EOL> proto_h_filename ) <EOL> defs . extend ( item_defs ) <EOL> defs_h . extend ( item_defs_h ) <EOL> t = ufunc . generate ( all_loops ) <EOL> toplevel += t + "<STR_LIT:\n>" <EOL> toplevel = "<STR_LIT:\n>" . join ( list ( all_loops . values ( ) ) + defs + [ toplevel ] ) <EOL> with open ( filename , '<STR_LIT:w>' ) as f : <EOL> f . write ( EXTRA_CODE_COMMON ) <EOL> f . write ( EXTRA_CODE ) <EOL> f . write ( toplevel ) <EOL> f . write ( EXTRA_CODE_BOTTOM ) <EOL> defs_h = unique ( defs_h ) <EOL> with open ( proto_h_filename , '<STR_LIT:w>' ) as f : <EOL> f . write ( "<STR_LIT>" ) <EOL> f . write ( "<STR_LIT:\n>" . join ( defs_h ) ) <EOL> f . write ( "<STR_LIT>" ) <EOL> cxx_defs_h = unique ( cxx_defs_h ) <EOL> with open ( cxx_proto_h_filename , '<STR_LIT:w>' ) as f : <EOL> f . write ( "<STR_LIT>" ) <EOL> f . write ( "<STR_LIT:\n>" . join ( cxx_defs_h ) ) <EOL> f . write ( "<STR_LIT>" ) <EOL> with open ( cxx_pyx_filename , '<STR_LIT:w>' ) as f : <EOL> f . write ( EXTRA_CODE_COMMON ) <EOL> f . write ( "<STR_LIT:\n>" . join ( cxx_defs ) ) <EOL> f . write ( "<STR_LIT>" ) <EOL> with open ( cxx_pxd_filename , '<STR_LIT:w>' ) as f : <EOL> f . write ( "<STR_LIT:\n>" . join ( cxx_pxd_defs ) ) <EOL> def unique ( lst ) : <EOL> """<STR_LIT>""" <EOL> seen = set ( ) <EOL> new_lst = [ ] <EOL> for item in lst : <EOL> if item in seen : <EOL> continue <EOL> seen . add ( item ) <EOL> new_lst . append ( item ) <EOL> return new_lst <EOL> def main ( ) : <EOL> p = optparse . OptionParser ( usage = __doc__ . strip ( ) ) <EOL> options , args = p . parse_args ( ) <EOL> if len ( args ) != <NUM_LIT:0> : <EOL> p . error ( '<STR_LIT>' ) <EOL> ufuncs = Ufunc . parse_all ( UFUNCS ) <EOL> generate ( "<STR_LIT>" , "<STR_LIT>" , ufuncs ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> main ( ) </s>
