def __configure_sealed(self, controller): global _seq2arr w_buffer_arg = controller.find_wrapper_arg( self.buffer_arg.name ) w_buffer_arg.type = declarations.dummy_type_t( "boost::python::object" ) controller.remove_wrapper_arg( self.size_arg.name ) size_var = controller.declare_variable( declarations.remove_const( self.size_arg.type ) , self.size_arg.name , ' = boost::python::len(%s)' % w_buffer_arg.name ) # Declare a variable that will hold the C array... buffer_var = controller.declare_variable( declarations.dummy_type_t( "std::vector< %s >" % self.buffer_item_type.decl_string ) , "native_" + self.buffer_arg.name ) controller.add_pre_call_code( '%s.reserve( %s );' % ( buffer_var, size_var ) ) copy_pylist2arr = _seq2vector.substitute( type=self.buffer_item_type , pylist=w_buffer_arg.name , native_array=buffer_var ) controller.add_pre_call_code( copy_pylist2arr ) controller.modify_arg_expression( self.buffer_arg_index, '&%s[0]' % buffer_var ) controller.modify_arg_expression( self.size_arg_index, '%s' % size_var )
def __configure_sealed(self, controller): global _seq2arr w_buffer_arg = controller.find_wrapper_arg(self.buffer_arg.name) w_buffer_arg.type = declarations.dummy_type_t("boost::python::object") controller.remove_wrapper_arg(self.size_arg.name) size_var = controller.declare_variable( declarations.remove_const(self.size_arg.type), self.size_arg.name, ' = boost::python::len(%s)' % w_buffer_arg.name) # Declare a variable that will hold the C array... buffer_var = controller.declare_variable( declarations.dummy_type_t("std::vector< %s >" % self.buffer_item_type.decl_string), "native_" + self.buffer_arg.name) controller.add_pre_call_code('%s.reserve( %s );' % (buffer_var, size_var)) copy_pylist2arr = _seq2vector.substitute(type=self.buffer_item_type, pylist=w_buffer_arg.name, native_array=buffer_var) controller.add_pre_call_code(copy_pylist2arr) controller.modify_arg_expression(self.buffer_arg_index, '&%s[0]' % buffer_var) controller.modify_arg_expression(self.size_arg_index, '%s' % size_var)
def __configure_sealed(self, controller): global _seq2arr global _arr2seq w_arg = controller.find_wrapper_arg(self.arg.name) w_arg.type = declarations.dummy_type_t("boost::python::object") # Declare a variable that will hold the C array... native_array = controller.declare_variable(self.array_item_type, "native_" + self.arg.name, '[%d]' % self.array_size) copy_pylist2arr = _seq2arr.substitute(type=self.array_item_type, pylist=w_arg.name, array_size=self.array_size, native_array=native_array) controller.add_pre_call_code(copy_pylist2arr) controller.modify_arg_expression(self.arg_index, native_array) # Declare a Python list which will receive the output... pylist = controller.declare_variable( declarations.dummy_type_t("boost::python::list"), 'py_' + self.arg.name) copy_arr2pylist = _arr2seq.substitute(native_array=native_array, array_size=self.array_size, pylist=pylist) controller.add_post_call_code(copy_arr2pylist) #adding the variable to return variables list controller.return_variable(pylist)
def __configure_sealed(self, controller): global _seq2arr global _arr2seq w_arg = controller.find_wrapper_arg( self.arg.name ) w_arg.type = declarations.dummy_type_t( "boost::python::object" ) # Declare a variable that will hold the C array... native_array = controller.declare_variable( self.array_item_type , "native_" + self.arg.name , '[%d]' % self.array_size ) copy_pylist2arr = _seq2arr.substitute( type=self.array_item_type , pylist=w_arg.name , array_size=self.array_size , native_array=native_array ) controller.add_pre_call_code( copy_pylist2arr ) controller.modify_arg_expression( self.arg_index, native_array ) # Declare a Python list which will receive the output... pylist = controller.declare_variable( declarations.dummy_type_t( "boost::python::list" ) , 'py_' + self.arg.name ) copy_arr2pylist = _arr2seq.substitute( native_array=native_array , array_size=self.array_size , pylist=pylist ) controller.add_post_call_code( copy_arr2pylist ) #adding the variable to return variables list controller.return_variable( pylist )
def wrapper_return_type( self ): return_vars_count = len( self.return_variables ) if not declarations.is_void( self.function.return_type ): return_vars_count += 1 if 0 == return_vars_count: return self.function.return_type #return type is void elif 1 == return_vars_count: return declarations.dummy_type_t( 'boost::python::object' ) else: return declarations.dummy_type_t( 'boost::python::tuple' )
def wrapper_return_type(self): return_vars_count = len(self.return_variables) if not declarations.is_void(self.function.return_type): return_vars_count += 1 if 0 == return_vars_count: return self.function.return_type #return type is void elif 1 == return_vars_count: return declarations.dummy_type_t('boost::python::object') else: return declarations.dummy_type_t('boost::python::tuple')
def __configure_sealed(self, controller): global _cmatrix2pymatrix #removing arg from the function wrapper definition controller.remove_wrapper_arg(self.arg.name) # Declare a variable that will hold the C matrix... native_matrix = controller.declare_variable( self.matrix_item_type, "native_" + self.arg.name, '[%d][%d]' % (self.rows, self.columns)) #adding just declared variable to the original function call expression controller.modify_arg_expression(self.arg_index, native_matrix) # Declare a Python list which will receive the output... pymatrix = controller.declare_variable( declarations.dummy_type_t("boost::python::list"), 'py_' + self.arg.name) conversion_code = _cmatrix2pymatrix.substitute( pymatrix=pymatrix, columns='%d' % self.columns, row=controller.register_variable_name("row"), pyrow=controller.register_variable_name("pyrow"), rows='%d' % self.rows, native_matrix=native_matrix) controller.add_post_call_code(conversion_code) #adding the variable to return variables list controller.return_variable(pymatrix)
def __configure_sealed(self, controller): global _cmatrix2pymatrix #removing arg from the function wrapper definition controller.remove_wrapper_arg( self.arg.name ) # Declare a variable that will hold the C matrix... native_matrix = controller.declare_variable( self.matrix_item_type , "native_" + self.arg.name , '[%d][%d]' % (self.rows, self.columns ) ) #adding just declared variable to the original function call expression controller.modify_arg_expression( self.arg_index, native_matrix ) # Declare a Python list which will receive the output... pymatrix = controller.declare_variable( declarations.dummy_type_t( "boost::python::list" ) , 'py_' + self.arg.name ) conversion_code = _cmatrix2pymatrix.substitute( pymatrix=pymatrix , columns='%d' % self.columns , row=controller.register_variable_name( "row" ) , pyrow=controller.register_variable_name( "pyrow" ) , rows='%d' % self.rows , native_matrix=native_matrix ) controller.add_post_call_code( conversion_code ) #adding the variable to return variables list controller.return_variable( pymatrix )
def __configure_sealed(self, controller): global _arr2seq #removing arg from the function wrapper definition controller.remove_wrapper_arg( self.arg.name ) # Declare a variable that will hold the C array... native_array = controller.declare_variable( self.array_item_type , "native_" + self.arg.name , '[%d]' % self.array_size ) #adding just declared variable to the original function call expression controller.modify_arg_expression( self.arg_index, native_array ) # Declare a Python list which will receive the output... pylist = controller.declare_variable( declarations.dummy_type_t( "boost::python::list" ) , 'py_' + self.arg.name ) copy_arr2pylist = _arr2seq.substitute( native_array=native_array , array_size=self.array_size , pylist=pylist ) controller.add_post_call_code( copy_arr2pylist ) #adding the variable to return variables list controller.return_variable( pylist )
def __configure_sealed(self, controller): global _arr2seq #removing arg from the function wrapper definition controller.remove_wrapper_arg(self.arg.name) # Declare a variable that will hold the C array... native_array = controller.declare_variable(self.array_item_type, "native_" + self.arg.name, '[%d]' % self.array_size) #adding just declared variable to the original function call expression controller.modify_arg_expression(self.arg_index, native_array) # Declare a Python list which will receive the output... pylist = controller.declare_variable( declarations.dummy_type_t("boost::python::list"), 'py_' + self.arg.name) copy_arr2pylist = _arr2seq.substitute(native_array=native_array, array_size=self.array_size, pylist=pylist) controller.add_post_call_code(copy_arr2pylist) #adding the variable to return variables list controller.return_variable(pylist)
def __configure_v_mem_fun_override(self, controller): global _arr2seq pylist = controller.declare_py_variable(declarations.dummy_type_t("boost::python::list"), "py_" + self.arg.name) copy_arr2pylist = _arr2seq.substitute(native_array=self.arg.name, array_size=self.array_size, pylist=pylist) controller.add_py_pre_call_code(copy_arr2pylist)
def __configure_sealed(self, controller): w_arg = controller.find_wrapper_arg(self.arg.name) naked_type = declarations.remove_pointer(self.arg.type) naked_type = declarations.remove_declarated(naked_type) w_arg.type = declarations.dummy_type_t('std::auto_ptr< %s >' % naked_type.decl_string) controller.modify_arg_expression(self.arg_index, w_arg.name + '.release()')
def cpp_build_opttypes(cpp): opttypes = {} tdefs = declarations.find_all_declarations(cpp, type=declarations.typedef_t) for t in tdefs: if len(t.decl_string) < len(t.type.decl_string): opttypes[t.type] = declarations.dummy_type_t(t.decl_string) return opttypes
def __configure_v_mem_fun_override(self, controller): global _mat2seq pylist = controller.declare_py_variable(declarations.dummy_type_t("boost::python::list"), "py_" + self.arg.name) copy_mat2pylist = _mat2seq.substitute( native_matrix=self.arg.name, rows=self.rows, columns=self.columns, pylist=pylist ) controller.add_py_pre_call_code(copy_arr2pylist)
def __configure_v_mem_fun_override( self, controller ): global _arr2seq pylist = controller.declare_py_variable( declarations.dummy_type_t( 'boost::python::list' ) , 'py_' + self.arg.name ) copy_arr2pylist = _arr2seq.substitute( native_array=self.arg.name , array_size=self.array_size , pylist=pylist ) controller.add_py_pre_call_code( copy_arr2pylist )
def __configure_sealed(self, controller): global _pymatrix2cmatrix global _cmatrix2pymatrix w_arg = controller.find_wrapper_arg(self.arg.name) w_arg.type = declarations.dummy_type_t("boost::python::object") # Declare a variable that will hold the C matrix... native_matrix = controller.declare_variable( self.matrix_item_type, "native_" + self.arg.name, "[%d][%d]" % (self.rows, self.columns) ) conversion_code = _pymatrix2cmatrix.substitute( type=self.matrix_item_type, pymatrix=w_arg.name, columns="%d" % self.columns, row=controller.register_variable_name("row"), rows="%d" % self.rows, native_matrix=native_matrix, ) controller.add_pre_call_code(conversion_code) controller.modify_arg_expression(self.arg_index, native_matrix) # adding just declared variable to the original function call expression controller.modify_arg_expression(self.arg_index, native_matrix) # Declare a Python list which will receive the output... pymatrix = controller.declare_variable(declarations.dummy_type_t("boost::python::list"), "py_" + self.arg.name) conversion_code = _cmatrix2pymatrix.substitute( pymatrix=pymatrix, columns="%d" % self.columns, row=controller.register_variable_name("row"), pyrow=controller.register_variable_name("pyrow"), rows="%d" % self.rows, native_matrix=native_matrix, ) controller.add_post_call_code(conversion_code) # adding the variable to return variables list controller.return_variable(pymatrix)
def __configure_v_mem_fun_override(self, controller): global _arr2seq pylist = controller.declare_py_variable(declarations.dummy_type_t("boost::python::list"), "py_" + self.arg.name) # TODO: may be a better idea is move this loop to the generated code. for i in range(0, self.rows): copy_arr2pylist = _arr2seq.substitute( native_array=self.arg.name + "[%d]" % i, array_size=self.columns, pylist=pylist ) controller.add_py_pre_call_code(copy_arr2pylist)
def __configure_v_mem_fun_override( self, controller ): global _mat2seq pylist = controller.declare_py_variable( declarations.dummy_type_t( 'boost::python::list' ) , 'py_' + self.arg.name ) copy_mat2pylist = _mat2seq.substitute( native_matrix=self.arg.name , rows=self.rows , columns=self.columns , pylist=pylist ) controller.add_py_pre_call_code( copy_arr2pylist )
def __init__( self, function ): controller_base_t.__init__( self, function ) self.__py_vars_manager = create_variables_manager( function ) self.__py_function_var \ = self.__py_vars_manager.register_name( 'func_' + function.alias ) self.__py_pre_call = [] self.__py_post_call = [] self.__py_result_var = variable_t( declarations.dummy_type_t( 'boost::python::object' ) , self.register_py_variable_name( 'py_result' ) ) self.__py_arg_expressions = [ arg.name for arg in function.arguments ]
def __configure_v_mem_fun_override(self, controller): global _seq2arr seq = controller.declare_py_variable(declarations.dummy_type_t("boost::python::object"), "py_" + self.arg.name) controller.remove_py_arg(self.arg_index) tmpl = string.Template('$seq = pyplus_conv::get_out_argument( $py_result, "$name" );') get_ref_to_seq = tmpl.substitute(seq=seq, py_result=controller.py_result_variable.name, name=self.arg.name) controller.add_py_post_call_code(get_ref_to_seq) copy_pylist2arr = _seq2arr.substitute( type=self.array_item_type, pylist=seq, array_size=self.array_size, native_array=self.arg.name ) controller.add_py_post_call_code(copy_pylist2arr)
def __configure_v_mem_fun_override( self, controller ): global _arr2seq pylist = controller.declare_py_variable( declarations.dummy_type_t( 'boost::python::list' ) , 'py_' + self.arg.name ) #TODO: may be a better idea is move this loop to the generated code. for i in range(0, self.rows): copy_arr2pylist = _arr2seq.substitute( native_array=self.arg.name+'[%d]'%i , array_size=self.columns , pylist=pylist ) controller.add_py_pre_call_code( copy_arr2pylist )
def wrapper_type( self ): tmpl = "%(namespace)s::%(constness)sarray_1_t< %(item_type)s, %(array_size)d>" constness = '' if declarations.is_const( self.declaration.type ): constness = 'const_' result = tmpl % { 'namespace' : code_repository.array_1.namespace , 'constness' : constness , 'item_type' : declarations.array_item_type( self.declaration.type ).decl_string , 'array_size': declarations.array_size( self.declaration.type ) } return declarations.dummy_type_t( result )
def __configure_v_mem_fun_override(self, controller): global _seq2arr seq = controller.declare_py_variable(declarations.dummy_type_t("boost::python::object"), "py_" + self.arg.name) controller.remove_py_arg(self.arg_index) tmpl = string.Template('$seq = pyplus_conv::get_out_argument( $py_result, "$name" );') get_ref_to_seq = tmpl.substiture(seq=seq, py_result=controller.py_result_variable_name, name=self.arg.name) controller.add_py_post_call_code(get_ref_to_seq) # TODO: may be a better idea is move this loop to the generated code. for i in range(0, self.rows): copy_pylist2arr = _seq2arr.substitute( type=self.matrix_item_type, pylist=seq, array_size=self.columns, native_array=self.arg.name + "[%d]" % i ) controller.add_py_post_call_code(copy_pylist2arr)
def __init__(self, function, arg_ref): """Constructor. The specified argument must be a reference or a pointer. :param arg_ref: Index of the argument that is an output value :type arg_ref: int """ modifier = lambda type_: declarations.dummy_type_t('size_t') type_modifier_t.__init__( self, function, arg_ref, modifier ) if not is_ptr_or_array( self.arg.type ): raise ValueError( '%s\nin order to use "from_address_t" transformation, argument %s type must be a pointer or a array (got %s).' ) \ % ( function, self.arg_ref.name, arg.type)
def __init__(self, function, arg_ref): """Constructor. The specified argument must be a reference or a pointer. :param arg_ref: Index of the argument that is an output value :type arg_ref: int """ modifier = lambda type_: declarations.dummy_type_t('size_t') type_modifier_t.__init__(self, function, arg_ref, modifier) if not is_ptr_or_array(self.arg.type): raise ValueError( '%s\nin order to use "from_address_t" transformation, argument %s type must be a pointer or a array (got %s).' ) \ % ( function, self.arg_ref.name, arg.type)
def _get_wrapper_type( self ): ns_name = code_repository.array_1.namespace if declarations.is_const( self.declaration.type ): class_name = 'const_array_1_t' else: class_name = 'array_1_t' decl_string = declarations.templates.join( '::'.join( [ns_name, class_name] ) , [ declarations.array_item_type( self.declaration.type ).decl_string , str( declarations.array_size( self.declaration.type ) ) ]) return declarations.dummy_type_t( decl_string )
def __configure_v_mem_fun_override( self, controller ): global _seq2arr seq = controller.declare_py_variable( declarations.dummy_type_t( 'boost::python::object' ) , 'py_' + self.arg.name ) controller.remove_py_arg( self.arg_index ) tmpl = string.Template( '$seq = pyplus_conv::get_out_argument( $py_result, "$name" );' ) get_ref_to_seq = tmpl.substitute( seq=seq , py_result=controller.py_result_variable.name , name=self.arg.name ) controller.add_py_post_call_code( get_ref_to_seq ) copy_pylist2arr = _seq2arr.substitute( type=self.array_item_type , pylist=seq , array_size=self.array_size , native_array=self.arg.name ) controller.add_py_post_call_code( copy_pylist2arr )
def wrapper_type( self ): tmpl = "%(namespace)s::%(constness)sarray_1_t< %(item_type)s, %(array_size)d>" item_type = declarations.array_item_type(self.declaration.decl_type) is_noncopyable = not declarations.is_fundamental(item_type) and \ declarations.is_noncopyable(item_type) constness = '' if declarations.is_const(self.declaration.decl_type) or is_noncopyable: constness = 'const_' result = tmpl % { 'namespace' : code_repository.array_1.namespace , 'constness' : constness , 'item_type' : declarations.array_item_type( self.declaration.decl_type ).decl_string , 'array_size': declarations.array_size( self.declaration.decl_type ) } return declarations.dummy_type_t( result )
def __configure_sealed(self, controller): global _seq2arr w_arg = controller.find_wrapper_arg(self.arg.name) w_arg.type = declarations.dummy_type_t("boost::python::object") # Declare a variable that will hold the C array... native_array = controller.declare_variable( self.array_item_type, "native_" + self.arg.name, "[%d]" % self.array_size ) copy_pylist2arr = _seq2arr.substitute( type=self.array_item_type, pylist=w_arg.name, array_size=self.array_size, native_array=native_array ) controller.add_pre_call_code(copy_pylist2arr) controller.modify_arg_expression(self.arg_index, native_array)
def __configure_sealed(self, controller): global _seq2arr w_arg = controller.find_wrapper_arg(self.arg.name) w_arg.type = declarations.dummy_type_t("boost::python::object") # Declare a variable that will hold the C array... native_array = controller.declare_variable(self.array_item_type, "native_" + self.arg.name, '[%d]' % self.array_size) copy_pylist2arr = _seq2arr.substitute(type=self.array_item_type, pylist=w_arg.name, array_size=self.array_size, native_array=native_array) controller.add_pre_call_code(copy_pylist2arr) controller.modify_arg_expression(self.arg_index, native_array)
def __configure_v_mem_fun_override( self, controller ): global _seq2arr seq = controller.declare_py_variable( declarations.dummy_type_t( 'boost::python::object' ) , 'py_' + self.arg.name ) controller.remove_py_arg( self.arg_index ) tmpl = string.Template( '$seq = pyplus_conv::get_out_argument( $py_result, "$name" );' ) get_ref_to_seq = tmpl.substiture( seq=seq , py_result=controller.py_result_variable_name , name=self.arg.name ) controller.add_py_post_call_code( get_ref_to_seq ) #TODO: may be a better idea is move this loop to the generated code. for i in range(0, self.rows): copy_pylist2arr = _seq2arr.substitute( type=self.matrix_item_type , pylist=seq , array_size=self.columns , native_array=self.arg.name+'[%d]'%i ) controller.add_py_post_call_code( copy_pylist2arr )
def __configure_sealed(self, controller): global _pymatrix2cmatrix w_arg = controller.find_wrapper_arg( self.arg.name ) w_arg.type = declarations.dummy_type_t( "boost::python::object" ) # Declare a variable that will hold the C matrix... native_matrix = controller.declare_variable( self.matrix_item_type , "native_" + self.arg.name , '[%d][%d]' % (self.rows, self.columns) ) conversion_code = _pymatrix2cmatrix.substitute( type=self.matrix_item_type , pymatrix=w_arg.name , columns='%d' % self.columns , row=controller.register_variable_name( "row" ) , rows='%d' % self.rows , native_matrix=native_matrix ) controller.add_pre_call_code( conversion_code ) controller.modify_arg_expression( self.arg_index, native_matrix )
def cpp_opt_type(tnode): opt_decl_string = tnode.decl_string try: p = None n = tnode while n: opt = opttypes.get(n, None) if opt and p: # change the base and rebuild the tnode super parent ... p.base = opt opt_decl_string = tnode.build_decl_string() break if opt: opt_decl_string = opt.decl_string break p = n n = p.base except AttributeError: pass opttypes[tnode] = declarations.dummy_type_t(opt_decl_string) return opt_decl_string
def __configure_sealed(self, controller): global _seq2arr, _cleanUp w_arg = controller.find_wrapper_arg( self.arg.name ) w_arg.type = declarations.dummy_type_t( "boost::python::str" ) # Declare a variable that will hold the C array... native_pointer = controller.declare_variable( self.array_item_rawtype , "native_" + self.arg.name , '' ) copy_pylist2arr = _seq2arr.substitute( type=self.array_item_type , pylist=w_arg.name , max_size=self.max_size , native_pointer=native_pointer ) cleanUp = _cleanUp.substitute ( native_name = "native_" + self.arg.name ) controller.add_pre_call_code( copy_pylist2arr ) controller.add_post_call_code ( cleanUp ) controller.modify_arg_expression( self.arg_index, native_pointer )
# checkRange for z in sb.mb.free_funs('checkRange'): z.include() z._transformer_creators.append(FT.output_type1(2)) z._transformer_kwds['alias'] = 'checkRange' # kmeans z = sb.mb.free_fun('kmeans') z.include() z._transformer_creators.append(FT.output_type1('centers')) # calcCovarMatrix for z in sb.mb.free_funs('calcCovarMatrix'): z.include() if z.arguments[0].type == D.dummy_type_t('::cv::Mat const *'): z._transformer_creators.append(FT.input_array1d('samples', 'nsamples')) z._transformer_kwds['alias'] = 'calcCovarMatrix' # theRNG z = sb.mb.free_fun('theRNG') z.include() z.call_policies = CP.return_value_policy(CP.reference_existing_object) # fillConvexPoly z = sb.mb.free_fun('fillConvexPoly') z.include() z._transformer_creators.append(FT.input_array1d('pts', 'npts')) # fillPoly for t in ('fillPoly', 'polylines'):
def __configure_sealed( self, controller ): w_arg = controller.find_wrapper_arg( self.arg.name ) naked_type = declarations.remove_pointer( self.arg.type ) naked_type = declarations.remove_declarated( naked_type ) w_arg.type = declarations.dummy_type_t( 'std::auto_ptr< %s >' % naked_type.decl_string ) controller.modify_arg_expression(self.arg_index, w_arg.name + '.release()' )