[Dune-devel] Fwd: [GSoC2016] Wrapper for the FieldMatrix class
Michaël Sghaïer
sghaier.michael at gmail.com
Tue Apr 5 15:16:21 CEST 2016
---------- Forwarded message ----------
From: Michaël Sghaïer <sghaier.michael at gmail.com>
Date: 2016-04-04 22:20 GMT-04:00
Subject: Re: [Dune-devel] [GSoC2016] Wrapper for the FieldMatrix class
To: Andreas Dedner <a.s.dedner at warwick.ac.uk>
Hi Andreas,
sorry for the delay, because of the university, I hadn't so much time this
week...
However, I took the time to read all the Boost.Python tutorial and thus, I
learned some interesting things.
2016-03-27 5:56 GMT-04:00 Andreas Dedner <a.s.dedner at warwick.ac.uk>:
>
> I agree that we will have to think carefully about these details during
> the course of this project. Perhaps starting out with distinguishing
> different places where the FieldMatrix/Vectors are used. For example
> they are important for the grid geometry classes (used for the
> jacobianInverseTranspose method for example). Here the most important
> cases are n x n and then perhaps 1xn, nx1 and 2xn,nx2. If we can cover
> the most important cases that would already be helpful.
>
> Btw: I just came across this
>
>
> http://www.boost.org/doc/libs/1_57_0/libs/python/doc/v2/indexing.html#vector_indexing_suite
>
> which might be of interest. I think FieldVector/Matrix do not quite
> satisfy the std::vector interface at the moment (I know for example that
> difference_t is missing) but perhaps we can add the missing items to the
> classes. This might provide quite a nice approach for the wrapping.
>
I played a little with vector_indexing_suite and I am not sure if it is
really worth. Indeed, to use it, you must have a class that basically
derives from std::vector and thus, implements methods like erase, insert or
push_back. That makes no sense because these methods modify the size of
their vector and FieldVector/FieldMatrix have constant size defined at
compile time.
But I agree with the need of "pythonic" wrappers and I gave some thoughts
about it. I realized that Python generates a default iterator when a class
implements the __getitem__ method. So that makes possible to iterate
through a FieldVector like this:
>>> v = FieldVector3(3.14)
>>> from x in v:
... print(x)
...
3.14
3.14
3.14
>>>
Moreover, I think it would be nice to allow the user to initialize/modify a
FieldVector (or a FieldMatrix) from a Python list of values. I am going to
work on that to extend my previous junior jobs, that should be interesting.
Best,
Michaël
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.dune-project.org/pipermail/dune-devel/attachments/20160405/cca661b4/attachment.htm>
More information about the Dune-devel
mailing list