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
23
24#include <c2py/converters/wrapped.hpp>
25#include <Python.h>
26
27namespace c2py {
28
30 template <> struct py_converter<triqs::operators::many_body_operator_real> {
32 using conv_t = py_converter<triqs::operators::many_body_operator>;
33
34 static constexpr const char *tp_name = "Operator";
35
36 static PyObject *c2py(c_t const &x) { return conv_t::c2py(x); }
37
38 static bool is_convertible(PyObject *ob, bool raise_exception) {
39 bool ok = conv_t::is_convertible(ob, false /* we set the error ourselves */);
40 if (ok) {
41 // check the operator is real
42 auto op = conv_t::py2c(ob);
43 for (auto const &c_m : op) ok = ok && c_m.coef.is_real();
44 if (ok) return true;
45 }
46 if (raise_exception) { PyErr_SetString(PyExc_TypeError, "Cannot convert to many_body_operator_real"); }
47 return false;
48 }
49
50 static c_t py2c(PyObject *ob) { return c_t{conv_t::py2c(ob)}; }
51 };
52
53 // ----------------------------------------------
54
56 template <> struct py_converter<triqs::operators::many_body_operator_complex> {
58 using conv_t = py_converter<triqs::operators::many_body_operator>;
59
60 static constexpr const char *tp_name = "Operator";
61
62 static PyObject *c2py(c_t const &x) { return conv_t::c2py(x); }
63
64 static bool is_convertible(PyObject *ob, bool raise_exception) {
65 bool ok = conv_t::is_convertible(ob, false);
66 if (ok) return true;
67 if (raise_exception) { PyErr_SetString(PyExc_TypeError, "Cannot convert to many_body_operator_complex"); }
68 return false;
69 }
70
71 static c_t py2c(PyObject *ob) { return c_t{conv_t::py2c(ob)}; }
72 };
73
74} // namespace c2py
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.
Provides generic many-body operators.