MCPcopy Create free account
hub / github.com/NGSolve/ngsolve / ExportStdMathFunction

Function ExportStdMathFunction

fem/python_fem.hpp:16–35  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

14
15 template <typename FUNC>
16 void ExportStdMathFunction(py::module &m, string name, string description)
17 {
18 static RegisterClassForArchive<cl_UnaryOpCF<FUNC>, CoefficientFunction> reguopcf;
19
20 m.def (name.c_str(), [name] (py::object x) -> py::object
21 {
22 FUNC func;
23 py::extract<double> ed(x);
24 if (ed.check()) return py::cast(func(ed()));
25 if (py::extract<Complex> (x).check())
26 return py::cast(func(py::extract<Complex> (x)()));
27 if (py::extract<shared_ptr<CoefficientFunction>>(x).check())
28 {
29 auto coef = py::extract<shared_ptr<CoefficientFunction>>(x)();
30 return py::cast(UnaryOpCF(coef, func, FUNC::Name()));
31 }
32 throw py::type_error (string("can't compute math-function, type = ")
33 + typeid(FUNC).name());
34 }, py::arg("x"), description.c_str());
35 }
36
37 template <typename FUNC>
38 void ExportStdMathFunction_(py::module &m, string name,

Callers

nothing calls this directly

Calls 4

UnaryOpCFFunction · 0.85
argFunction · 0.85
NameFunction · 0.70
checkMethod · 0.45

Tested by

no test coverage detected