complex.h
Go to the documentation of this file.
1 /*
2  pybind11/complex.h: Complex number support
3 
4  Copyright (c) 2016 Wenzel Jakob <wenzel.jakob@epfl.ch>
5 
6  All rights reserved. Use of this source code is governed by a
7  BSD-style license that can be found in the LICENSE file.
8 */
9 
10 #pragma once
11 
12 #include "pybind11.h"
13 #include <complex>
14 
16 #ifdef I
17 # undef I
18 #endif
19 
21 
22 template <typename T> struct format_descriptor<std::complex<T>, detail::enable_if_t<std::is_floating_point<T>::value>> {
23  static constexpr const char c = format_descriptor<T>::c;
24  static constexpr const char value[3] = { 'Z', c, '\0' };
25  static std::string format() { return std::string(value); }
26 };
27 
28 #ifndef PYBIND11_CPP17
29 
30 template <typename T> constexpr const char format_descriptor<
32 
33 #endif
34 
36 
37 template <typename T> struct is_fmt_numeric<std::complex<T>, detail::enable_if_t<std::is_floating_point<T>::value>> {
38  static constexpr bool value = true;
39  static constexpr int index = is_fmt_numeric<T>::index + 3;
40 };
41 
42 template <typename T> class type_caster<std::complex<T>> {
43 public:
44  bool load(handle src, bool convert) {
45  if (!src)
46  return false;
47  if (!convert && !PyComplex_Check(src.ptr()))
48  return false;
49  Py_complex result = PyComplex_AsCComplex(src.ptr());
50  if (result.real == -1.0 && PyErr_Occurred()) {
51  PyErr_Clear();
52  return false;
53  }
54  value = std::complex<T>((T) result.real, (T) result.imag);
55  return true;
56  }
57 
58  static handle cast(const std::complex<T> &src, return_value_policy /* policy */, handle /* parent */) {
59  return PyComplex_FromDoubles((double) src.real(), (double) src.imag());
60  }
61 
62  PYBIND11_TYPE_CASTER(std::complex<T>, _("complex"));
63 };
static handle cast(const std::complex< T > &src, return_value_policy, handle)
Definition: complex.h:58
PyObject * ptr() const
Return the underlying PyObject * pointer.
Definition: pytypes.h:184
Scalar Scalar * c
Definition: benchVecAdd.cpp:17
Definition: Half.h:150
Values result
bool convert(const int &y)
Eigen::Triplet< double > T
void * value
Definition: cast.h:759
typename std::enable_if< B, T >::type enable_if_t
from cpp_future import (convenient aliases from C++14/17)
bool load(handle src, bool convert)
Definition: complex.h:44
return_value_policy
Approach used to cast a previously unknown C++ instance into a Python object.
#define PYBIND11_TYPE_CASTER(type, py_name)
Definition: cast.h:979
#define PYBIND11_NAMESPACE_END(name)
#define PYBIND11_NAMESPACE_BEGIN(name)


gtsam
Author(s):
autogenerated on Sat May 8 2021 02:41:48