From 2db6182ef8dd49ac6f46d7a3279fa5d6e8b4b6be Mon Sep 17 00:00:00 2001 From: Felix Schindler <felix.schindler@wwu.de> Date: Tue, 11 Jun 2019 13:23:45 +0200 Subject: [PATCH] [python|gamm...] add some guards --- .../gdt/gamm-2019-talk-on-conservative-rb.cc | 37 +++++++++++-------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/python/dune/gdt/gamm-2019-talk-on-conservative-rb.cc b/python/dune/gdt/gamm-2019-talk-on-conservative-rb.cc index 9198204cd..29704a65d 100644 --- a/python/dune/gdt/gamm-2019-talk-on-conservative-rb.cc +++ b/python/dune/gdt/gamm-2019-talk-on-conservative-rb.cc @@ -323,22 +323,27 @@ PYBIND11_MODULE(gamm_2019_talk_on_conservative_rb, m) "lower_left"_a, "upper_right"_a); - py::class_<XT::Functions::FunctionAsGridFunctionWrapper<E, 1, 1, double>, - XT::Functions::GridFunctionInterface<E, 1, 1, double>> - scalar_wrapper(m, "ScalarFunctionAsGridFunctionWrapper", "ScalarFunctionAsGridFunctionWrapper"); - scalar_wrapper.def(py::init([](const XT::Functions::FunctionInterface<d>& func) { - return new XT::Functions::FunctionAsGridFunctionWrapper<E, 1, 1, double>(func); - }), - py::keep_alive<1, 2>(), - "scalar_function"_a); - py::class_<XT::Functions::FunctionAsGridFunctionWrapper<E, d, d, double>, - XT::Functions::GridFunctionInterface<E, d, d, double>> - matrix_wrapper(m, "MatrixFunctionAsGridFunctionWrapper", "MatrixFunctionAsGridFunctionWrapper"); - matrix_wrapper.def(py::init([](const XT::Functions::FunctionInterface<d, d, d>& func) { - return new XT::Functions::FunctionAsGridFunctionWrapper<E, d, d, double>(func); - }), - py::keep_alive<1, 2>(), - "matrix_function"_a); + // these might already be defined + XT::Common::bindings::try_register(m, [](auto& m_) { + py::class_<XT::Functions::FunctionAsGridFunctionWrapper<E, 1, 1, double>, + XT::Functions::GridFunctionInterface<E, 1, 1, double>> + scalar_wrapper(m_, "ScalarFunctionAsGridFunctionWrapper", "ScalarFunctionAsGridFunctionWrapper"); + scalar_wrapper.def(py::init([](const XT::Functions::FunctionInterface<d>& func) { + return new XT::Functions::FunctionAsGridFunctionWrapper<E, 1, 1, double>(func); + }), + py::keep_alive<1, 2>(), + "scalar_function"_a); + }); + XT::Common::bindings::try_register(m, [](auto& m_) { + py::class_<XT::Functions::FunctionAsGridFunctionWrapper<E, d, d, double>, + XT::Functions::GridFunctionInterface<E, d, d, double>> + matrix_wrapper(m_, "MatrixFunctionAsGridFunctionWrapper", "MatrixFunctionAsGridFunctionWrapper"); + matrix_wrapper.def(py::init([](const XT::Functions::FunctionInterface<d, d, d>& func) { + return new XT::Functions::FunctionAsGridFunctionWrapper<E, d, d, double>(func); + }), + py::keep_alive<1, 2>(), + "matrix_function"_a); + }); m.def("function_to_grid_function", [](XT::Functions::FunctionInterface<d>& func) { -- GitLab