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 
14 #include <complex>
15 
17 #ifdef I
18 # undef I
19 #endif
20 
22 
23 template <typename T>
24 struct format_descriptor<std::complex<T>, detail::enable_if_t<std::is_floating_point<T>::value>> {
25  static constexpr const char c = format_descriptor<T>::c;
26  static constexpr const char value[3] = {'Z', c, '\0'};
27  static std::string format() { return std::string(value); }
28 };
29 
30 #ifndef PYBIND11_CPP17
31 
32 template <typename T>
33 constexpr const char
36 
37 #endif
38 
40 
41 template <typename T>
42 struct is_fmt_numeric<std::complex<T>, detail::enable_if_t<std::is_floating_point<T>::value>> {
43  static constexpr bool value = true;
44  static constexpr int index = is_fmt_numeric<T>::index + 3;
45 };
46 
47 template <typename T>
48 class type_caster<std::complex<T>> {
49 public:
50  bool load(handle src, bool convert) {
51  if (!src) {
52  return false;
53  }
54  if (!convert && !PyComplex_Check(src.ptr())) {
55  return false;
56  }
57  Py_complex result = PyComplex_AsCComplex(src.ptr());
58  if (result.real == -1.0 && PyErr_Occurred()) {
59  PyErr_Clear();
60  return false;
61  }
62  value = std::complex<T>((T) result.real, (T) result.imag);
63  return true;
64  }
65 
66  static handle
67  cast(const std::complex<T> &src, return_value_policy /* policy */, handle /* parent */) {
68  return PyComplex_FromDoubles((double) src.real(), (double) src.imag());
69  }
70 
71  PYBIND11_TYPE_CASTER(std::complex<T>, const_name("complex"));
72 };
static handle cast(const std::complex< T > &src, return_value_policy, handle)
Definition: complex.h:67
Scalar Scalar * c
Definition: benchVecAdd.cpp:17
Definition: BFloat16.h:88
Values result
Eigen::Triplet< double > T
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:50
PyObject * ptr() const
Return the underlying PyObject * pointer.
Definition: pytypes.h:238
constexpr descr< N - 1 > const_name(char const (&text)[N])
Definition: descr.h:60
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:82
#define PYBIND11_NAMESPACE_END(name)
static BinaryMeasurement< Rot3 > convert(const BetweenFactor< Pose3 >::shared_ptr &f)
#define PYBIND11_NAMESPACE_BEGIN(name)


gtsam
Author(s):
autogenerated on Tue Jul 4 2023 02:34:02