pybind11 compiled_extension_module missing


224
views
1
8 months ago by
Nate  
Is there a pybind11-dolfin equivalent of dolfin.compiled_extension_module?

cf. demo/undocumented/compiled-extension-module/demo_compiled-extension-module.py
Community: FEniCS Project

1 Answer


3
8 months ago by
Look at the unit tests, e.g. python/test/unit/jit/test_jit.py
Also, see: python/demo/documented/tensor-weighted-poisson for an example using Expression
Thanks very much. For reference if anyone else has the same issue, here's the relevant code:

    from numpy import arange, exp
    code = """
      #include <pybind11/pybind11.h>

      #include <petscvec.h>
      #include <dolfin/la/PETScVector.h>

      void PETSc_exp(std::shared_ptr<dolfin::PETScVector> vec)
      {
        Vec x = vec->vec();
        assert(x);
        VecExp(x);
      }

    PYBIND11_MODULE(SIGNATURE, m)
    {
      m.def("PETSc_exp", &PETSc_exp);
    }
    """

    ext_module = compile_cpp_code(code)

    vec = PETScVector(mpi_comm_world(), 10)
    np_vec = vec.get_local()
    np_vec[:] = arange(len(np_vec))
    vec.set_local(np_vec)
    ext_module.PETSc_exp(vec)
    np_vec[:] = exp(np_vec)
    assert (np_vec == vec.get_local()).all()​
written 8 months ago by Nate  
Please login to add an answer/comment or follow this question.

Similar posts:
Search »