Typemap problem for std::vector<Point>
There is some problem with the typemap for std::vector<Point>. For example, unit testing of ConvexTriangulation::triangulate yields
TypeError: in method 'ConvexTriangulation_triangulate', argument 1 of type 'std::vector< dolfin::Point >'
I've disabled these tests for now.
Comments (15)
-
reporter -
Is this issue still relevant? @augustjohansson @benjamik
-
reporter Yes, I think it's still a problem. At least I haven't gotten a solution into my code yet :)
-
I think @magneano did some work on typemaps for
Point
? Perhaps that could be used. -
I did some work on "out" typemaps for multimesh quadrature rule types. Those use
std::vector<double>
instead ofstd::vector<Point>
to represent sets of points.Currently there is no typemap for
Point
and creating aPoint
in the Python interface results in a swig proxy object, so I don´t think it makes sense to add an "in" typemap forstd::vector<Point>
. Instead, we could modify the Python interface for the relevant functions to handle Python list inputs. -
It should be pretty easy to make the typemaps work. Check also https://bitbucket.org/fenics-project/dolfin/src/6440f6114c3e20f6188f003bbce3b1b283fbcab5/dolfin/swig/typemaps/std_vector.i?at=master&fileviewer=file-view-default#std_vector.i-745.
Tweaking typemaps might be preferable than changing the interface.
-
The typemap indeed works. Try
from dolfin import * cpp = """ #include <vector> namespace dolfin { void foo(const std::vector<Point>& p) { info("%f", p[0].x()); }; } """ foo = compile_extension_module(cpp).foo foo([Point(666.0)])
-
reporter @blechta is of course absolutely correct. @benjamik fixed this some time ago. I think we can mark this as resolved.
-
If a large number of points is wanted, Magne is right that swig proxy object can be an issue. There's both a severe memory penalty and takes time to allocate and wrap/unwrap these objects.
-
Well, should be there
std::vector<Point>
interface on C++ side if the number is really large? -
reporter I'd guess that the size is typically less than 10. More importantly, the functions are typically not used from python at all, but internally in the C++ MultiMesh class.
-
Correct. This is mainly useful for development and unit testing of functionality implemented in Python (with the convenience of Python for doing testing and experiments).
-
I was not aware that this was fixed. Thanks Jan!
I suggested changing the interface instead of defining a typemap because it seems a little convoluted to create a list of swig proxy objects for passing to a typemap, even more so if it is typemap that is not used anywhere else. I would like to discuss when typemaps are preferable to modifying the interface, but this is probably not the right place for it.
-
Is this still an issue? @magneano @augustjohansson
-
- changed status to resolved
No longer relevant when soon moving to pybind11
- Log in to comment
The ConvexTriangulation test is in
geometry/test_intersection_construction.py
The error also causes four XDMFFile write errors in
io/test_XDMF.py.
I will disable these as well.