[Dune-devel] [GSoC2016] Junior job about the Python bindings

Michaël Sghaïer sghaier.michael at gmail.com
Wed Mar 16 18:56:51 CET 2016


I just pushed my commit [1] on my branch,

A few notes:
- you need to have python3.5m in /usr/include to compile (I used Python3).
- I created a src/ directory in dune-common/ which contains the wrapper and
the unit test in a subdirectory test/
- to run the test, run `./dune-commun/bin/dunecontrol --only=dune-commun
all` in the root directory (which contains all DUNE modules) and then
`python3 -m unittest -v test_fvector.py" in dune-common/src/test`
This should return


   1. test_constructorByCopy (test_fvector.TestWrapperDoubleFieldVector)
   ... ok
   2. test_constructorByValue (test_fvector.TestWrapperDoubleFieldVector)
   ... ok
   3. test_getItem (test_fvector.TestWrapperDoubleFieldVector) ... ok
   4. test_len (test_fvector.TestWrapperDoubleFieldVector) ... ok
   5.
   6. ----------------------------------------------------------------------
   7. Ran 4 tests in 0.001s
   8.
   9. OK


- if you want to use the wrapper in the python interpret, just run python3
in dune-common/build-cmake/src/ and then "import libfvector"

Any comment is more than welcome!

Best,
Michaël

[1]
https://gitlab.dune-project.org/michael.sghaier/dune-common/commit/f675c5a16f06c504e3c3e67c71f0706297193d34

2016-03-16 12:31 GMT-04:00 Michaël Sghaïer <sghaier.michael at gmail.com>:

> Oh, I just realized that I forgot the "this" pointer parameter for my
> function get_item... Shame on me. Whatever, I can now handle a range of
> dimensions and even several data types!
> I will now focuse on the unit test (before sending a git patch) and a
> draft for my proposal.
>
> Best,
> Michaël
>
> 2016-03-16 3:25 GMT-04:00 Michaël Sghaïer <sghaier.michael at gmail.com>:
>
>> Hi,
>>
>> I have been working on the junior job related to the Python bindings for
>> two days and I have some questions:
>>
>> 2016-03-15 14:51 GMT-04:00 Andreas Dedner:
>>
>>> Note that FieldVector derives from DenseVector and many methods that
>>> need to be wrapped are implemented there.
>>>
>>
>> Do we have to wrap the methods of DenseVector too or just the methods of
>> FieldVector?
>>
>> Until this junior job, I never used Boost.Python. Though I found it very
>> interesting and funny to play with, it's a little tricky to use. Can you
>> confirm me that we can't wrap the following constructors, due to the fact
>> that templates have to be instanciated at compile time:
>>
>>
>> template<class C>
>> FieldVector (const DenseVector<C> &x, ...)
>>
>> and
>>
>> template<class K1, int SIZE1>
>> explicit FieldVector(const FieldVector<K1, SIZE1> & x)
>>
>> ?
>>
>> (same for Base::operator= I guess)
>>
>> Last question, the junior job says that the wrapper should work with a
>> range of dimensions. I assume that means it should be easy for a user to
>> add a wrapper for a particular dimension (because templates can't be
>> specialized at runtime, through the Python interpreter, right?).
>>
>> I tried to define a template<int SIZE> struct registerFieldVector which
>> defines a static function pointer get_item to wrap operator[] but it
>> doesn't work. I have been debugging for hours now and I don't find a
>> solution.
>>
>> For example,
>>
>> static double& (*get_item) (Dune::FieldVector<double, SIZE>::size_type);
>>
>> ...
>>
>> template<>
>> double& (*RegisterFieldVector<7>::get_item) (Dune::FieldVector<double, 7>::size_type = &Dune::FieldVector<double, 7>::operator[];
>>
>> raises the error: "error: cannot declare pointer to ‘double&’ in static double& (*get_item) (Dune::FieldVector<double, SIZE>::size_type);"
>>
>>
>> Could you give me any lead?
>>
>> Best,
>> Michaël
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.dune-project.org/pipermail/dune-devel/attachments/20160316/8fd1b6cf/attachment.htm>


More information about the Dune-devel mailing list