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 };
format_descriptor
Definition: wrap/pybind11/include/pybind11/detail/common.h:1036
is_fmt_numeric
Definition: wrap/pybind11/include/pybind11/detail/common.h:1054
const_name
constexpr descr< N - 1 > const_name(char const (&text)[N])
Definition: descr.h:60
return_value_policy
return_value_policy
Approach used to cast a previously unknown C++ instance into a Python object.
Definition: wrap/pybind11/include/pybind11/detail/common.h:499
c
Scalar Scalar * c
Definition: benchVecAdd.cpp:17
type_caster_generic::value
void * value
Definition: type_caster_base.h:828
PYBIND11_NAMESPACE_END
#define PYBIND11_NAMESPACE_END(name)
Definition: wrap/pybind11/include/pybind11/detail/common.h:80
detail
Definition: testSerializationNonlinear.cpp:70
PYBIND11_NAMESPACE_BEGIN
#define PYBIND11_NAMESPACE_BEGIN(name)
Definition: wrap/pybind11/include/pybind11/detail/common.h:76
result
Values result
Definition: OdometryOptimize.cpp:8
is_fmt_numeric::value
static constexpr bool value
Definition: wrap/pybind11/include/pybind11/detail/common.h:1055
format_descriptor< std::complex< T >, detail::enable_if_t< std::is_floating_point< T >::value > >::format
static std::string format()
Definition: complex.h:27
handle
Definition: pytypes.h:226
type_caster
Definition: cast.h:38
PYBIND11_NAMESPACE
Definition: test_custom_type_casters.cpp:24
Eigen::Triplet< double >
PYBIND11_TYPE_CASTER
#define PYBIND11_TYPE_CASTER(type, py_name)
Definition: cast.h:87
pybind11.h
handle::ptr
PyObject * ptr() const
Return the underlying PyObject * pointer.
Definition: pytypes.h:250
std
Definition: BFloat16.h:88
type_caster< std::complex< T > >::cast
static handle cast(const std::complex< T > &src, return_value_policy, handle)
Definition: complex.h:67
gtsam::convert
static BinaryMeasurement< Rot3 > convert(const BetweenFactor< Pose3 >::shared_ptr &f)
Definition: ShonanAveraging.cpp:993
enable_if_t
typename std::enable_if< B, T >::type enable_if_t
from cpp_future import (convenient aliases from C++14/17)
Definition: wrap/pybind11/include/pybind11/detail/common.h:654
test_callbacks.value
value
Definition: test_callbacks.py:160
type_caster< std::complex< T > >::load
bool load(handle src, bool convert)
Definition: complex.h:50
complex
Definition: datatypes.h:12


gtsam
Author(s):
autogenerated on Sat Nov 16 2024 04:02:00