Typemap problem for std::vector<Point>

Issue #767 resolved
August Johansson created an issue

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)

  1. August Johansson reporter

    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.

  2. August Johansson reporter

    Yes, I think it's still a problem. At least I haven't gotten a solution into my code yet :)

  3. Magne Nordaas

    I did some work on "out" typemaps for multimesh quadrature rule types. Those use std::vector<double> instead of std::vector<Point> to represent sets of points.

    Currently there is no typemap for Point and creating a Point in the Python interface results in a swig proxy object, so I don´t think it makes sense to add an "in" typemap for std::vector<Point>. Instead, we could modify the Python interface for the relevant functions to handle Python list inputs.

  4. Jan Blechta

    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)])
    
  5. August Johansson reporter

    @blechta is of course absolutely correct. @benjamik fixed this some time ago. I think we can mark this as resolved.

  6. Martin Sandve Alnæs

    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.

  7. August Johansson 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.

  8. Anders Logg (Chalmers)

    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).

  9. Magne Nordaas

    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.

  10. Log in to comment