On Monday 16 November 2009 22:03:13 DOLFIN wrote: > One or more new changesets pushed to the primary dolfin repository. > A short summary of the last three changesets is included below. > > changeset: 7459:739b7539d6eb > tag: tip > user: "Garth N. Wells <gn...@cam.ac.uk>" > date: Mon Nov 16 21:02:54 2009 +0000 > files: dolfin/swig/numpy_typemaps.i dolfin/swig/std_vector_typemaps.i > site-packages/dolfin/expression.py description: > Get typemap(in) for std::vector working. > > Seems to work but I don't know if it's any good.
(Resending the email as I forgot to send it using the correct email adress...) I haven't got the time to look at it, but yes the provided typemaps do make a copy, which is not optimal. I have have actually been a bit worried ;) that you might change the interface of eval, and possible other methods too, from double* to std::vector. In most perspectives it is much nicer to pass a std::vector, not least for safety. However std::vector is more difficult to interact with NumPy. SWIG do provide it's own implementation of std::vector which more or less wrap the c++ interface of a vector seamless. We have used this to pass arguments of std:vector previously. However the amount of code that is produced and not used is large (~1MB for DOLFIN version < 9.2). NumPy arrays and lists are also much more convenient structures to work with in Python. I have therefore decided to remove the dependency of std_vector.i by adding our own typemaps for std::vector arguments. Each one of those typemaps do make a copy. For now we have typmaps for primitives and pointers so each copy should not be that bad. But for operations that is performed alot of times, it might be a difference. But I doubt it would for the callback functionality, as I assume just calling the python function would take most of the time. We could consider creating a NumPy array from the pointer to the first element of the vector, as I have seen you have discussed on the list previously, for other cases. We then have to consider the life time of the vector. For director typemaps that would probably be ok. For other "out" typemaps it might not be ok. Would it be an option to add, in C++, a small template wrapper class for arrays that are supposed to go back and forth to Python via NumPy arrays? Including basic operations so it will be useful also in C++. Johan > > changeset: 7458:f9d6aeab7271 > user: "Garth N. Wells <gn...@cam.ac.uk>" > date: Mon Nov 16 19:06:12 2009 +0000 > files: demo/function/eval/python/demo.py > site-packages/dolfin/expression.py description: > Comment out some dim checks in expression.py. > > > changeset: 7457:6dc505f97225 > user: "Garth N. Wells <gn...@cam.ac.uk>" > date: Mon Nov 16 15:13:08 2009 +0000 > files: demo/function/eval/python/demo.py dolfin/swig/docstrings.i > dolfin/swig/function_post.i dolfin/swig/function_pre.i > dolfin/swig/std_vector_typemaps.i description: > Add empty typemap for NumPy array to std::vector<double>. > > ---------------------------------------------------------------------- > For more details, visit http://www.fenics.org/hg/dolfin > _______________________________________________ > DOLFIN-dev mailing list > DOLFIN-dev@fenics.org > http://www.fenics.org/mailman/listinfo/dolfin-dev > _______________________________________________ DOLFIN-dev mailing list DOLFIN-dev@fenics.org http://www.fenics.org/mailman/listinfo/dolfin-dev