pybind11_tests.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <pybind11/eval.h>
4 #include <pybind11/pybind11.h>
5 
6 namespace py = pybind11;
7 using namespace pybind11::literals;
8 
10  using Initializer = void (*)(py::module_ &);
11 
12 public:
14  test_initializer(const char *submodule_name, Initializer init);
15 };
16 
17 #define TEST_SUBMODULE(name, variable) \
18  void test_submodule_##name(py::module_ &); \
19  test_initializer name(#name, test_submodule_##name); \
20  void test_submodule_##name(py::module_ &(variable))
21 
23 struct UnregisteredType {};
24 
26 class UserType {
27 public:
28  UserType() = default;
29  explicit UserType(int i) : i(i) {}
30 
31  int value() const { return i; }
32  void set(int set) { i = set; }
33 
34 private:
35  int i = -1;
36 };
37 
39 class IncType : public UserType {
40 public:
41  using UserType::UserType;
42  IncType() = default;
43  IncType(const IncType &other) : IncType(other.value() + 1) {}
44  IncType(IncType &&) = delete;
45  IncType &operator=(const IncType &) = delete;
46  IncType &operator=(IncType &&) = delete;
47 };
48 
50 union IntFloat {
51  int i;
52  float f;
53 };
54 
57 struct RValueCaster {};
60 template <>
62 public:
65  return py::str("rvalue").release();
66  }
68  return py::str("lvalue").release();
69  }
70 };
73 
74 template <typename F>
76  py::exec(R"(
77  message = "pybind11-bound class '.+' is using an old-style placement-new '(?:__init__|__setstate__)' which has been deprecated"
78 
79  import warnings
80  with warnings.catch_warnings():
81  warnings.filterwarnings("ignore", message=message, category=FutureWarning)
82  body()
83  )",
84  py::dict(py::arg("body") = py::cpp_function(body)));
85 }
IntFloat::f
float f
Definition: pybind11_tests.h:52
IntFloat::i
int i
Definition: pybind11_tests.h:51
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:485
PYBIND11_NAMESPACE_END
#define PYBIND11_NAMESPACE_END(name)
Definition: wrap/pybind11/include/pybind11/detail/common.h:80
UserType::UserType
UserType()=default
UnregisteredType
Dummy type which is not exported anywhere – something to trigger a conversion error.
Definition: pybind11_tests.h:23
detail
Definition: testSerializationNonlinear.cpp:70
UserType::set
void set(int set)
Definition: pybind11_tests.h:32
PYBIND11_NAMESPACE_BEGIN
#define PYBIND11_NAMESPACE_BEGIN(name)
Definition: wrap/pybind11/include/pybind11/detail/common.h:76
type_caster< RValueCaster >::cast
static handle cast(RValueCaster &&, return_value_policy, handle)
Definition: pybind11_tests.h:64
IntFloat
A simple union for basic testing.
Definition: pybind11_tests.h:50
handle
Definition: pytypes.h:217
type_caster
Definition: cast.h:38
exec
void exec(const str &expr, object global=globals(), object local=object())
Definition: eval.h:88
ignoreOldStyleInitWarnings
void ignoreOldStyleInitWarnings(F &&body)
Definition: pybind11_tests.h:75
IncType::IncType
IncType()=default
RValueCaster
Definition: pybind11_tests.h:57
eval.h
test_initializer::Initializer
void(*)(py::module_ &) Initializer
Definition: pybind11_tests.h:10
IncType::IncType
IncType(const IncType &other)
Definition: pybind11_tests.h:43
arg
EIGEN_DEVICE_FUNC const EIGEN_STRONG_INLINE ArgReturnType arg() const
Definition: ArrayCwiseUnaryOps.h:66
type_caster< RValueCaster >::cast
static handle cast(const RValueCaster &, return_value_policy, handle)
Definition: pybind11_tests.h:67
gtsam::symbol_shorthand::F
Key F(std::uint64_t j)
Definition: inference/Symbol.h:153
set
void set(Container &c, Position position, const Value &value)
Definition: stdlist_overload.cpp:37
PYBIND11_TYPE_CASTER
#define PYBIND11_TYPE_CASTER(type, py_name)
Definition: cast.h:85
pybind11.h
test_initializer
Definition: pybind11_tests.h:9
UserType::value
int value() const
Definition: pybind11_tests.h:31
UserType::UserType
UserType(int i)
Definition: pybind11_tests.h:29
pybind11
Definition: wrap/pybind11/pybind11/__init__.py:1
init
Definition: TutorialInplaceLU.cpp:2
gtsam.examples.ShonanAveragingCLI.str
str
Definition: ShonanAveragingCLI.py:115
test_callbacks.value
value
Definition: test_callbacks.py:158
i
int i
Definition: BiCGSTAB_step_by_step.cpp:9
pybind_wrapper_test_script.other
other
Definition: pybind_wrapper_test_script.py:42


gtsam
Author(s):
autogenerated on Tue Jun 25 2024 03:02:24