[pygccxml-commit] SF.net SVN: pygccxml:[1796] pyplusplus_dev
Brought to you by:
mbaas,
roman_yakovenko
From: <rom...@us...> - 2010-01-13 09:02:29
|
Revision: 1796 http://pygccxml.svn.sourceforge.net/pygccxml/?rev=1796&view=rev Author: roman_yakovenko Date: 2010-01-13 09:02:23 +0000 (Wed, 13 Jan 2010) Log Message: ----------- integrate input_static_matrix Modified Paths: -------------- pyplusplus_dev/docs/documentation/functions/transformation/input_static_array.rest pyplusplus_dev/docs/documentation/functions/transformation/transformation.rest pyplusplus_dev/pyplusplus/function_transformers/transformers.py pyplusplus_dev/unittests/ft_input_static_matrix_tester.py Added Paths: ----------- pyplusplus_dev/docs/documentation/functions/transformation/input_static_matrix.rest Modified: pyplusplus_dev/docs/documentation/functions/transformation/input_static_array.rest =================================================================== --- pyplusplus_dev/docs/documentation/functions/transformation/input_static_array.rest 2010-01-13 08:02:50 UTC (rev 1795) +++ pyplusplus_dev/docs/documentation/functions/transformation/input_static_array.rest 2010-01-13 09:02:23 UTC (rev 1796) @@ -12,7 +12,7 @@ "input_static_array" transformer takes as first argument name or index of the original function argument. The argument should have "array" or "pointer" type. -The second argument should an integer value, which represents array size. +The second argument should be an integer value, which represents array size. ------- Example Added: pyplusplus_dev/docs/documentation/functions/transformation/input_static_matrix.rest =================================================================== --- pyplusplus_dev/docs/documentation/functions/transformation/input_static_matrix.rest (rev 0) +++ pyplusplus_dev/docs/documentation/functions/transformation/input_static_matrix.rest 2010-01-13 09:02:23 UTC (rev 1796) @@ -0,0 +1,90 @@ +================================== +``input_static_matrix`` transformer +================================== + +---------- +Definition +---------- + +"input_static_matrix" transformer works on native static 2D arrays. It +handles the translation between `Python`_ object, passed as argument +that represent a sequence of sequences, and the matrix. The number of rows +and columns should be known in advance. + +"input_static_matrix" transformer takes as first argument name or index of the +original function argument. The argument should have "array" or "pointer" type. +The second and the third arguments specfies rows and columns size. + +----------- +Limitations +----------- + +This transformer could not be applied on virtual functions. + +------- +Example +------- + +.. code-block:: c++ + + template< int rows, int columns > + int sum_impl( const int m[rows][columns] ){ + int result = 0; + for( int r = 0; r < rows; ++r ){ + for( int c = 0; c < columns; ++c ){ + result += m[r][c]; + } + } + return result; + } + + int sum( int m[2][3]){ + return sum_impl<2, 3>( m ); + } + + +In order to expose ``sum`` function we need to create small wrapper: +The following :doc:`Py++ <../../../pyplusplus>` code does it for you: + + .. code-block:: python + + from pyplusplus import module_builder + from pyplusplus import function_transformers as FT + + mb = module_builder.module_builder_t( ... ) + sum = mb.free_fun( 'sum' ) + sum.add_transformation( FT.input_static_matrix('m', rows=2, columns=3) ) + +What you see below is the relevant pieces of generated code: + + .. code-block:: c++ + + #include "__convenience.pypp.hpp" //Py++ header file, which contains few convenience function + + namespace bp = boost::python; + + static boost::python::object sum_d4475c1b6a0ff117f0754ec5ecacdda3( boost::python::object m ){ + int native_m[2][3]; + pyplus_conv::ensure_uniform_sequence< boost::python::list >( m, 2 ); + for( size_t row = 0; row < 2; ++row ){ + pyplus_conv::ensure_uniform_sequence< int >( m[row], 3 ); + pyplus_conv::copy_sequence( m[row], pyplus_conv::array_inserter( native_m[row], 3 ) ); + } + int result = ::ft::sum(native_m); + return bp::object( result ); + } + + BOOST_PYTHON_MODULE(...){ + ... + typedef boost::python::object ( *sum_function_type )( boost::python::object ); + + bp::def( + "sum" + , sum_function_type( &sum_d4475c1b6a0ff117f0754ec5ecacdda3 ) + , ( bp::arg("m") ) ); + } + +.. _`Boost.Python`: http://www.boost.org/libs/python/doc/index.html +.. _`Python`: http://www.python.org +.. _`GCC-XML`: http://www.gccxml.org + Modified: pyplusplus_dev/docs/documentation/functions/transformation/transformation.rest =================================================================== --- pyplusplus_dev/docs/documentation/functions/transformation/transformation.rest 2010-01-13 08:02:50 UTC (rev 1795) +++ pyplusplus_dev/docs/documentation/functions/transformation/transformation.rest 2010-01-13 09:02:23 UTC (rev 1796) @@ -95,6 +95,7 @@ transfer_ownership.rest input_c_buffer.rest from_address.rest + input_static_matrix.rest Modified: pyplusplus_dev/pyplusplus/function_transformers/transformers.py =================================================================== --- pyplusplus_dev/pyplusplus/function_transformers/transformers.py 2010-01-13 08:02:50 UTC (rev 1795) +++ pyplusplus_dev/pyplusplus/function_transformers/transformers.py 2010-01-13 09:02:23 UTC (rev 1796) @@ -612,8 +612,9 @@ self.__configure_sealed( controller ) def configure_virtual_mem_fun( self, controller ): - self.__configure_v_mem_fun_override( controller.override_controller ) - self.__configure_v_mem_fun_default( controller.default_controller ) + raise RuntimeError( '"input_static_matrix" transformation does not support virtual functions yet.' ) + #self.__configure_v_mem_fun_override( controller.override_controller ) + #self.__configure_v_mem_fun_default( controller.default_controller ) # output_static_matrix_t class output_static_matrix_t(transformer.transformer_t): Modified: pyplusplus_dev/unittests/ft_input_static_matrix_tester.py =================================================================== --- pyplusplus_dev/unittests/ft_input_static_matrix_tester.py 2010-01-13 08:02:50 UTC (rev 1795) +++ pyplusplus_dev/unittests/ft_input_static_matrix_tester.py 2010-01-13 09:02:23 UTC (rev 1796) @@ -31,8 +31,8 @@ sum = mb.free_funs( lambda d: d.name in ('sum', 'sum_const' ) ) sum.add_transformation( ft.input_static_matrix('m', rows=2, columns=3) ) - calculate = mb.mem_fun( 'calculate' ) - calculate.add_transformation( ft.input_static_matrix('m', rows=3, columns=5) ) + #calculate = mb.mem_fun( 'calculate' ) + #calculate.add_transformation( ft.input_static_matrix('m', rows=3, columns=5) ) def run_tests(self, module): """Run the actual unit tests""" This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |