MCPcopy Create free account
hub / github.com/pybind/pybind11 / ReturnTester

Class ReturnTester

tests/test_eigen_matrix.cpp:235–269  ·  view source on GitHub ↗

test_eigen_return_references, test_eigen_keepalive return value referencing/copying tests:

Source from the content-addressed store, hash-verified

233 // test_eigen_return_references, test_eigen_keepalive
234 // return value referencing/copying tests:
235 class ReturnTester {
236 Eigen::MatrixXd mat = create();
237
238 public:
239 ReturnTester() { print_created(this); }
240 ReturnTester(const ReturnTester &) = default;
241 ~ReturnTester() { print_destroyed(this); }
242 static Eigen::MatrixXd create() { return Eigen::MatrixXd::Ones(10, 10); }
243 // NOLINTNEXTLINE(readability-const-return-type)
244 static const Eigen::MatrixXd createConst() { return Eigen::MatrixXd::Ones(10, 10); }
245 Eigen::MatrixXd &get() { return mat; }
246 Eigen::MatrixXd *getPtr() { return &mat; }
247 const Eigen::MatrixXd &view() { return mat; }
248 const Eigen::MatrixXd *viewPtr() { return &mat; }
249 Eigen::Ref<Eigen::MatrixXd> ref() { return mat; }
250 Eigen::Ref<const Eigen::MatrixXd> refConst() { return mat; }
251 Eigen::Block<Eigen::MatrixXd> block(int r, int c, int nrow, int ncol) {
252 return mat.block(r, c, nrow, ncol);
253 }
254 Eigen::Block<const Eigen::MatrixXd> blockConst(int r, int c, int nrow, int ncol) const {
255 return mat.block(r, c, nrow, ncol);
256 }
257 py::EigenDMap<Eigen::Matrix2d> corners() {
258 return py::EigenDMap<Eigen::Matrix2d>(
259 mat.data(),
260 py::EigenDStride(mat.outerStride() * (mat.outerSize() - 1),
261 mat.innerStride() * (mat.innerSize() - 1)));
262 }
263 py::EigenDMap<const Eigen::Matrix2d> cornersConst() const {
264 return py::EigenDMap<const Eigen::Matrix2d>(
265 mat.data(),
266 py::EigenDStride(mat.outerStride() * (mat.outerSize() - 1),
267 mat.innerStride() * (mat.innerSize() - 1)));
268 }
269 };
270 using rvp = py::return_value_policy;
271 py::class_<ReturnTester>(m, "ReturnTester")
272 .def(py::init<>())

Callers

nothing calls this directly

Calls 1

createFunction · 0.85

Tested by

no test coverage detected