Gentoo Archives: gentoo-commits

From: "Benda XU (heroxbd)" <heroxbd@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] gentoo-x86 commit in dev-python/pyplusplus/files: pyplusplus-1.0.0_p20131206-numpy.patch
Date: Fri, 06 Dec 2013 13:35:58
Message-Id: 20131206133553.601062004E@flycatcher.gentoo.org
1 heroxbd 13/12/06 13:35:53
2
3 Added: pyplusplus-1.0.0_p20131206-numpy.patch
4 Log:
5 new snapshot with boost-numpy support.
6
7 (Portage version: 2.2.7/cvs/Linux x86_64, unsigned Manifest commit)
8
9 Revision Changes Path
10 1.1 dev-python/pyplusplus/files/pyplusplus-1.0.0_p20131206-numpy.patch
11
12 file : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/dev-python/pyplusplus/files/pyplusplus-1.0.0_p20131206-numpy.patch?rev=1.1&view=markup
13 plain: http://sources.gentoo.org/viewvc.cgi/gentoo-x86/dev-python/pyplusplus/files/pyplusplus-1.0.0_p20131206-numpy.patch?rev=1.1&content-type=text/plain
14
15 Index: pyplusplus-1.0.0_p20131206-numpy.patch
16 ===================================================================
17 Index: pyplusplus/code_creators/__init__.py
18 ===================================================================
19 --- pyplusplus/code_creators/__init__.py.orig
20 +++ pyplusplus/code_creators/__init__.py
21 @@ -110,6 +110,8 @@ from member_variable import bit_field_t
22 from member_variable import bit_field_wrapper_t
23 from member_variable import array_mv_t
24 from member_variable import array_mv_wrapper_t
25 +from member_variable import array_numpy_t
26 +from member_variable import array_numpy_wrapper_t
27 from member_variable import mem_var_ref_t
28 from member_variable import mem_var_ref_wrapper_t
29 from member_variable import member_variable_addressof_t
30 Index: pyplusplus/code_creators/code_creator.py
31 ===================================================================
32 --- pyplusplus/code_creators/code_creator.py.orig
33 +++ pyplusplus/code_creators/code_creator.py
34 @@ -126,6 +126,7 @@ class code_creator_t(object):
35 files = []
36 if self.code_generator == self.CODE_GENERATOR_TYPES.BOOST_PYTHON:
37 files.append( "boost/python.hpp" )
38 + files.append( "boost/numpy.hpp" )
39 files.append( code_repository.named_tuple.file_name )
40 else:
41 files.append( code_repository.ctypes_utils.file_name )
42 Index: pyplusplus/code_creators/member_variable.py
43 ===================================================================
44 --- pyplusplus/code_creators/member_variable.py.orig
45 +++ pyplusplus/code_creators/member_variable.py
46 @@ -507,7 +507,95 @@ class array_mv_wrapper_t( code_creator.c
47 def _get_system_files_impl( self ):
48 return [code_repository.array_1.file_name]
49
50 +class array_numpy_t( member_variable_base_t ):
51 + """
52 + Creates boost.python code that exposes array member variable via boost.numpy.
53 + """
54 + def __init__(self, variable, wrapper ):
55 + member_variable_base_t.__init__( self, variable=variable, wrapper=wrapper )
56 + self.works_on_instance = False
57 +
58 + def _create_body( self ):
59 + answer = []
60 + doc = ''
61 + if self.declaration.type_qualifiers.has_static:
62 + answer.append( self.parent.class_var_name + '.add_static_property' )
63 + else:
64 + if self.documentation:
65 + doc = self.documentation
66 + answer.append( self.parent.class_var_name + '.add_property' )
67 + answer.append('( "%s", &%s );' % (self.declaration.name, self.wrapper.wrapper_creator_full_name ))
68 + if doc:
69 + answer.append( os.linesep )
70 + answer.append( self.PARAM_SEPARATOR )
71 + answer.append( doc )
72 + return ''.join( answer )
73 +
74 + def _create_impl( self ):
75 + answer = []
76 + answer.append( '{ //%s, type=%s' % ( self.declaration, self.declaration.type ) )
77 + answer.append( os.linesep )
78 + answer.append( self.indent( self._create_body() ) )
79 + answer.append( os.linesep )
80 + answer.append( '}' )
81 + return ''.join( answer )
82 +
83 + def _get_system_files_impl( self ):
84 + return []
85
86 +class array_numpy_wrapper_t( code_creator.code_creator_t
87 + , declaration_based.declaration_based_t ):
88 + """registers array class"""
89 + def __init__(self, variable ):
90 + code_creator.code_creator_t.__init__( self )
91 + declaration_based.declaration_based_t.__init__( self, declaration=variable)
92 + self.py_class_type = declarations.reference_t(declarations.const_t(declarations.dummy_type_t( "bp::object" )))
93 +
94 + @property
95 + def wrapped_class_type( self ):
96 + wrapped_cls_type = declarations.declarated_t( self.declaration.parent )
97 + if declarations.is_const( self.declaration.type ):
98 + wrapped_cls_type = declarations.const_t( wrapped_cls_type )
99 + return declarations.reference_t( wrapped_cls_type )
100 +
101 + @property
102 + def wrapper_creator_name(self):
103 + return '_'.join( ['pyplusplus', self.declaration.name, 'wrapper'] )
104 +
105 + @property
106 + def wrapper_creator_full_name(self):
107 + return '::'.join( [self.parent.full_name, self.wrapper_creator_name] )
108 +
109 + def _create_impl( self ):
110 + if self.declaration.type_qualifiers.has_static:
111 + tmpl = [ "static %(wrapper_type)s %(wrapper_creator_name)s( ){" ]
112 + tmpl.append( self.indent( "return bn::from_data( %(parent_class_type)s::%(mem_var_ref)s," ) )
113 + owner = "bp::object()"
114 + else:
115 + tmpl = [ "static %(wrapper_type)s %(wrapper_creator_name)s( %(py_class_type)s inst ){" ]
116 + tmpl.append( self.indent( "return bn::from_data(bp::extract< %(wrapped_class_type)s >(inst)().%(mem_var_ref)s," ) )
117 + owner = "inst"
118 + tmpl.append( self.indent(self.indent("bn::dtype::get_builtin< %(item_type)s >(), bp::make_tuple(%(array_size)s),")) )
119 + tmpl.append( self.indent(self.indent("bp::make_tuple(sizeof(%(item_type)s)), %(owner)s);")) )
120 + tmpl.append( "}" )
121 +
122 + tmpl = os.linesep.join( tmpl )
123 +
124 + return tmpl % {
125 + 'wrapper_type' : "bn::ndarray"
126 + , 'parent_class_type' : self.parent.declaration.partial_decl_string
127 + , 'wrapper_creator_name' : self.wrapper_creator_name
128 + , 'wrapped_class_type' : self.wrapped_class_type.decl_string
129 + , 'mem_var_ref' : self.declaration.name
130 + , 'py_class_type' : self.py_class_type.decl_string
131 + , 'item_type' : declarations.array_item_type( self.declaration.type ).decl_string
132 + , 'array_size': declarations.array_size( self.declaration.type )
133 + , 'owner': owner
134 + }
135 +
136 + def _get_system_files_impl( self ):
137 + return []
138 +
139 class mem_var_ref_t( member_variable_base_t ):
140 """
141 creates get/set accessors for class member variable, that has type reference.
142 Index: pyplusplus/code_creators/module_body.py
143 ===================================================================
144 --- pyplusplus/code_creators/module_body.py.orig
145 +++ pyplusplus/code_creators/module_body.py
146 @@ -18,6 +18,7 @@ class module_body_t(compound.compound_t)
147 def _create_impl(self):
148 result = []
149 result.append( "BOOST_PYTHON_MODULE(%s){" % self.name )
150 + result.append( "bn::initialize();" )
151 result.append( compound.compound_t.create_internal_code( self.creators ) )
152 result.append( "}" )
153 return os.linesep.join( result )
154 Index: pyplusplus/creators_factory/bpcreator.py
155 ===================================================================
156 --- pyplusplus/creators_factory/bpcreator.py.orig
157 +++ pyplusplus/creators_factory/bpcreator.py
158 @@ -76,10 +76,14 @@ class bpcreator_t( declarations.decl_vis
159 global_ns = declarations.get_global_namespace(decls)
160
161 self.__extmodule = code_creators.bpmodule_t( global_ns )
162 - if boost_python_ns_name:
163 - bp_ns_alias = code_creators.namespace_alias_t( alias=boost_python_ns_name
164 - , full_namespace_name='::boost::python' )
165 - self.__extmodule.adopt_creator( bp_ns_alias )
166 +
167 + # alias of boost::numpy is hard-coded here, as it will be merged into boost::python.
168 + for ns_name, full_ns_name in {boost_python_ns_name: '::boost::python'
169 + , 'bn': '::boost::numpy'}.iteritems():
170 + if ns_name:
171 + ns_alias = code_creators.namespace_alias_t( alias=ns_name
172 + , full_namespace_name=full_ns_name )
173 + self.__extmodule.adopt_creator( ns_alias )
174
175 self.__module_body = code_creators.module_body_t( name=module_name )
176
177 @@ -723,8 +727,12 @@ class bpcreator_t( declarations.decl_vis
178 wrapper = code_creators.bit_field_wrapper_t( variable=self.curr_decl )
179 maker = code_creators.bit_field_t( variable=self.curr_decl, wrapper=wrapper )
180 elif declarations.is_array( self.curr_decl.type ):
181 - wrapper = code_creators.array_mv_wrapper_t( variable=self.curr_decl )
182 - maker = code_creators.array_mv_t( variable=self.curr_decl, wrapper=wrapper )
183 + if declarations.is_fundamental(declarations.array_item_type( self.curr_decl.type )):
184 + wrapper = code_creators.array_numpy_wrapper_t( variable=self.curr_decl )
185 + maker = code_creators.array_numpy_t( variable=self.curr_decl, wrapper=wrapper )
186 + else:
187 + wrapper = code_creators.array_mv_wrapper_t( variable=self.curr_decl )
188 + maker = code_creators.array_mv_t( variable=self.curr_decl, wrapper=wrapper )
189 elif declarations.is_pointer( self.curr_decl.type ):
190 wrapper = code_creators.member_variable_wrapper_t( variable=self.curr_decl )
191 maker = code_creators.member_variable_t( variable=self.curr_decl, wrapper=wrapper )