TRIQS/TRIQS 4.0.0
Researching Interacting Quantum Systems
Loading...
Searching...
No Matches
operators_real_complex.hpp
1// Copyright (c) 2017 Commissariat à l'énergie atomique et aux énergies alternatives (CEA)
2// Copyright (c) 2017 Centre national de la recherche scientifique (CNRS)
3// Copyright (c) 2022 Simons Foundation
4//
5// This program is free software: you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// This program is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You may obtain a copy of the License at
16// https://www.gnu.org/licenses/gpl-3.0.txt
17//
18// Authors: Alexander Hampel, Olivier Parcollet
19
20#pragma once
21
22namespace cpp2py {
23
25 template <> struct py_converter<triqs::operators::many_body_operator_real> {
27 using conv_t = py_converter<triqs::operators::many_body_operator>;
28
29 static constexpr char *tp_name = "Operator";
30
31 static PyObject *c2py(c_t const &x) { return conv_t::c2py(x); }
32
33 static bool is_convertible(PyObject *ob, bool raise_exception) {
34 bool ok = conv_t::is_convertible(ob, false /* we set the error ourselves */);
35 if (ok) {
36 // check the operator is real
37 auto op = conv_t::py2c(ob);
38 for (auto const &c_m : op) ok = ok && c_m.coef.is_real();
39 if (ok) return true;
40 }
41 if (raise_exception) { PyErr_SetString(PyExc_TypeError, "Cannot convert to many_body_operator_real"); }
42 return false;
43 }
44
45 static c_t py2c(PyObject *ob) { return c_t{conv_t::py2c(ob)}; }
46 };
47
48 // ----------------------------------------------
49
51 template <> struct py_converter<triqs::operators::many_body_operator_complex> {
53 using conv_t = py_converter<triqs::operators::many_body_operator>;
54
55 static constexpr char *tp_name = "Operator";
56
57 static PyObject *c2py(c_t const &x) { return conv_t::c2py(x); }
58
59 static bool is_convertible(PyObject *ob, bool raise_exception) {
60 bool ok = conv_t::is_convertible(ob, false);
61 if (ok) return true;
62 if (raise_exception) { PyErr_SetString(PyExc_TypeError, "Cannot convert to many_body_operator_complex"); }
63 return false;
64 }
65
66 static c_t py2c(PyObject *ob) { return c_t{conv_t::py2c(ob)}; }
67 };
68} // namespace cpp2py
many_body_operator_generic< double > many_body_operator_real
Many-body operator with real coefficients (see triqs::operators::many_body_operator_generic).
many_body_operator_generic< std::complex< double > > many_body_operator_complex
Many-body operator with complex coefficients (see triqs::operators::many_body_operator_generic).
Additional converters for gf.
Additional converters for gf.