From c2525fe76d58768b999fbe84c5b5ad5df1961e40 Mon Sep 17 00:00:00 2001 From: Chun-Hsu Lai Date: Fri, 3 Jan 2025 00:04:24 +0800 Subject: [PATCH] add python complex interface --- cpp/modmesh/mathtype/pymod/mathtype_pymod.hpp | 1 - cpp/modmesh/mathtype/pymod/wrap_Complex.cpp | 5 ++++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/cpp/modmesh/mathtype/pymod/mathtype_pymod.hpp b/cpp/modmesh/mathtype/pymod/mathtype_pymod.hpp index 026ce50b..67ef792a 100644 --- a/cpp/modmesh/mathtype/pymod/mathtype_pymod.hpp +++ b/cpp/modmesh/mathtype/pymod/mathtype_pymod.hpp @@ -27,7 +27,6 @@ */ #include -#include #include diff --git a/cpp/modmesh/mathtype/pymod/wrap_Complex.cpp b/cpp/modmesh/mathtype/pymod/wrap_Complex.cpp index c3a58d99..78590c2c 100644 --- a/cpp/modmesh/mathtype/pymod/wrap_Complex.cpp +++ b/cpp/modmesh/mathtype/pymod/wrap_Complex.cpp @@ -74,7 +74,10 @@ class MODMESH_PYTHON_WRAPPER_VISIBILITY WrapComplex .def(py::self -= py::self) // NOLINT(misc-redundant-expression) .def_property_readonly("real", &wrapped_type::real) .def_property_readonly("imag", &wrapped_type::imag) - .def("norm", &wrapped_type::norm); + .def("norm", &wrapped_type::norm) + .def("__complex__", + [](wrapped_type const & self) + { return std::complex(self.real(), self.imag()); }); } }; /* end class WrapComplex */