diff --git a/PyTAT/PyTAT.cpp b/PyTAT/PyTAT.cpp index 9f17104b2..06aa9d740 100644 --- a/PyTAT/PyTAT.cpp +++ b/PyTAT/PyTAT.cpp @@ -40,7 +40,7 @@ namespace TAT { // symmetry and edge and edge segment auto No_m = tat_m.def_submodule("No"); - dealing_symmetry(No_m, "No").def(py::init<>()); + dealing_symmetry(No_m, "No").def(py::init<>()).def(implicit_from_tuple>(), py::arg("empty_tuple")); dealing_edge(No_m, "No"); dealing_edge(No_m, "No"); @@ -48,6 +48,7 @@ namespace TAT { dealing_symmetry(Z2_m, "Z2") .def(py::init<>()) .def(implicit_init(), py::arg("z2")) + .def(implicit_from_tuple>(), py::arg("tuple_of_z2")) .def_property_readonly("z2", [](const Z2Symmetry& symmetry) { return std::get<0>(symmetry); }); dealing_edge(Z2_m, "Z2"); dealing_edge(Z2_m, "Z2"); @@ -56,6 +57,7 @@ namespace TAT { dealing_symmetry(U1_m, "U1") .def(py::init<>()) .def(implicit_init(), py::arg("u1")) + .def(implicit_from_tuple>(), py::arg("tuple_of_u1")) .def_property_readonly("u1", [](const U1Symmetry& symmetry) { return std::get<0>(symmetry); }); dealing_edge(U1_m, "U1"); dealing_edge(U1_m, "U1"); @@ -64,6 +66,7 @@ namespace TAT { dealing_symmetry(Fermi_m, "Fermi") .def(py::init<>()) .def(implicit_init(), py::arg("fermi")) + .def(implicit_from_tuple>(), py::arg("tuple_of_fermi")) .def_property_readonly("fermi", [](const FermiSymmetry& symmetry) { return std::get<0>(symmetry); }); dealing_edge(Fermi_m, "Fermi"); dealing_edge(Fermi_m, "Fermi"); @@ -72,12 +75,7 @@ namespace TAT { dealing_symmetry(FermiZ2_m, "FermiZ2") .def(py::init<>()) .def(py::init(), py::arg("fermi"), py::arg("z2")) - .def( - implicit_init&>([](const std::tuple& p) { - return std::make_from_tuple(p); - }), - py::arg("tuple_of_fermi_z2") - ) + .def(implicit_from_tuple>(), py::arg("tuple_of_fermi_z2")) .def_property_readonly("fermi", [](const FermiZ2Symmetry& symmetry) { return std::get<0>(symmetry); }) .def_property_readonly("z2", [](const FermiZ2Symmetry& symmetry) { return std::get<1>(symmetry); }); dealing_edge(FermiZ2_m, "FermiZ2"); @@ -87,12 +85,7 @@ namespace TAT { dealing_symmetry(FermiU1_m, "FermiU1") .def(py::init<>()) .def(py::init(), py::arg("fermi"), py::arg("u1")) - .def( - implicit_init&>([](const std::tuple& p) { - return std::make_from_tuple(p); - }), - py::arg("tuple_of_fermi_u1") - ) + .def(implicit_from_tuple>(), py::arg("tuple_of_fermi_u1")) .def_property_readonly("fermi", [](const FermiU1Symmetry& symmetry) { return std::get<0>(symmetry); }) .def_property_readonly("u1", [](const FermiU1Symmetry& symmetry) { return std::get<1>(symmetry); }); dealing_edge(FermiU1_m, "FermiU1"); @@ -102,6 +95,7 @@ namespace TAT { dealing_symmetry(Parity_m, "Parity") .def(py::init<>()) .def(implicit_init(), py::arg("parity")) + .def(implicit_from_tuple>(), py::arg("tuple_of_z2")) .def_property_readonly("parity", [](const ParitySymmetry& symmetry) { return std::get<0>(symmetry); }); dealing_edge(Parity_m, "Parity"); dealing_edge(Parity_m, "Parity"); @@ -110,12 +104,7 @@ namespace TAT { dealing_symmetry(FermiFermi_m, "FermiFermi") .def(py::init<>()) .def(py::init(), py::arg("fermi_0"), py::arg("fermi_1")) - .def( - implicit_init&>([](const std::tuple& p) { - return std::make_from_tuple(p); - }), - py::arg("tuple_of_fermi_0_fermi_1") - ) + .def(implicit_from_tuple>(), py::arg("tuple_of_fermi_0_fermi_1")) .def_property_readonly("fermi_0", [](const FermiFermiSymmetry& symmetry) { return std::get<0>(symmetry); }) .def_property_readonly("fermi_1", [](const FermiFermiSymmetry& symmetry) { return std::get<1>(symmetry); }); dealing_edge(FermiFermi_m, "FermiFermi"); diff --git a/PyTAT/PyTAT.hpp b/PyTAT/PyTAT.hpp index fbad84458..ea148a162 100644 --- a/PyTAT/PyTAT.hpp +++ b/PyTAT/PyTAT.hpp @@ -82,6 +82,11 @@ namespace TAT { return py::init(func); } + template + auto implicit_from_tuple() { + return implicit_init([](const Input& p) { return std::make_from_tuple(p); }); + } + // About callable module inline void set_callable(py::module_& tat_m) { auto py_type = py::module_::import("builtins").attr("type");