test_eigen.cpp (11986:c12e4625ab56) test_eigen.cpp (12037:d28054ac6ec9)
1/*
2 tests/eigen.cpp -- automatic conversion of Eigen types
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#include "pybind11_tests.h"
1/*
2 tests/eigen.cpp -- automatic conversion of Eigen types
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#include "pybind11_tests.h"
11#include "constructor_stats.h"
11#include <pybind11/eigen.h>
12#include <Eigen/Cholesky>
13
12#include <pybind11/eigen.h>
13#include <Eigen/Cholesky>
14
14Eigen::VectorXf double_col(const Eigen::VectorXf& x)
15{ return 2.0f * x; }
15using MatrixXdR = Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>;
16
16
17Eigen::RowVectorXf double_row(const Eigen::RowVectorXf& x)
18{ return 2.0f * x; }
19
17
20Eigen::MatrixXf double_mat_cm(const Eigen::MatrixXf& x)
21{ return 2.0f * x; }
22
18
23// Different ways of passing via Eigen::Ref; the first and second are the Eigen-recommended
24Eigen::MatrixXd cholesky1(Eigen::Ref<Eigen::MatrixXd> &x) { return x.llt().matrixL(); }
25Eigen::MatrixXd cholesky2(const Eigen::Ref<const Eigen::MatrixXd> &x) { return x.llt().matrixL(); }
26Eigen::MatrixXd cholesky3(const Eigen::Ref<Eigen::MatrixXd> &x) { return x.llt().matrixL(); }
27Eigen::MatrixXd cholesky4(Eigen::Ref<const Eigen::MatrixXd> &x) { return x.llt().matrixL(); }
28Eigen::MatrixXd cholesky5(Eigen::Ref<Eigen::MatrixXd> x) { return x.llt().matrixL(); }
29Eigen::MatrixXd cholesky6(Eigen::Ref<const Eigen::MatrixXd> x) { return x.llt().matrixL(); }
19// Sets/resets a testing reference matrix to have values of 10*r + c, where r and c are the
20// (1-based) row/column number.
21template <typename M> void reset_ref(M &x) {
22 for (int i = 0; i < x.rows(); i++) for (int j = 0; j < x.cols(); j++)
23 x(i, j) = 11 + 10*i + j;
24}
30
25
31typedef Eigen::Matrix<float, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor> MatrixXfRowMajor;
32MatrixXfRowMajor double_mat_rm(const MatrixXfRowMajor& x)
33{ return 2.0f * x; }
26// Returns a static, column-major matrix
27Eigen::MatrixXd &get_cm() {
28 static Eigen::MatrixXd *x;
29 if (!x) {
30 x = new Eigen::MatrixXd(3, 3);
31 reset_ref(*x);
32 }
33 return *x;
34}
35// Likewise, but row-major
36MatrixXdR &get_rm() {
37 static MatrixXdR *x;
38 if (!x) {
39 x = new MatrixXdR(3, 3);
40 reset_ref(*x);
41 }
42 return *x;
43}
44// Resets the values of the static matrices returned by get_cm()/get_rm()
45void reset_refs() {
46 reset_ref(get_cm());
47 reset_ref(get_rm());
48}
34
49
50// Returns element 2,1 from a matrix (used to test copy/nocopy)
51double get_elem(Eigen::Ref<const Eigen::MatrixXd> m) { return m(2, 1); };
52
53
54// Returns a matrix with 10*r + 100*c added to each matrix element (to help test that the matrix
55// reference is referencing rows/columns correctly).
56template <typename MatrixArgType> Eigen::MatrixXd adjust_matrix(MatrixArgType m) {
57 Eigen::MatrixXd ret(m);
58 for (int c = 0; c < m.cols(); c++) for (int r = 0; r < m.rows(); r++)
59 ret(r, c) += 10*r + 100*c;
60 return ret;
61}
62
63struct CustomOperatorNew {
64 CustomOperatorNew() = default;
65
66 Eigen::Matrix4d a = Eigen::Matrix4d::Zero();
67 Eigen::Matrix4d b = Eigen::Matrix4d::Identity();
68
69 EIGEN_MAKE_ALIGNED_OPERATOR_NEW;
70};
71
35test_initializer eigen([](py::module &m) {
36 typedef Eigen::Matrix<float, 5, 6, Eigen::RowMajor> FixedMatrixR;
37 typedef Eigen::Matrix<float, 5, 6> FixedMatrixC;
38 typedef Eigen::Matrix<float, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor> DenseMatrixR;
39 typedef Eigen::Matrix<float, Eigen::Dynamic, Eigen::Dynamic> DenseMatrixC;
72test_initializer eigen([](py::module &m) {
73 typedef Eigen::Matrix<float, 5, 6, Eigen::RowMajor> FixedMatrixR;
74 typedef Eigen::Matrix<float, 5, 6> FixedMatrixC;
75 typedef Eigen::Matrix<float, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor> DenseMatrixR;
76 typedef Eigen::Matrix<float, Eigen::Dynamic, Eigen::Dynamic> DenseMatrixC;
77 typedef Eigen::Matrix<float, 4, Eigen::Dynamic> FourRowMatrixC;
78 typedef Eigen::Matrix<float, Eigen::Dynamic, 4> FourColMatrixC;
79 typedef Eigen::Matrix<float, 4, Eigen::Dynamic> FourRowMatrixR;
80 typedef Eigen::Matrix<float, Eigen::Dynamic, 4> FourColMatrixR;
40 typedef Eigen::SparseMatrix<float, Eigen::RowMajor> SparseMatrixR;
41 typedef Eigen::SparseMatrix<float> SparseMatrixC;
42
43 m.attr("have_eigen") = true;
44
81 typedef Eigen::SparseMatrix<float, Eigen::RowMajor> SparseMatrixR;
82 typedef Eigen::SparseMatrix<float> SparseMatrixC;
83
84 m.attr("have_eigen") = true;
85
45 // Non-symmetric matrix with zero elements
46 Eigen::MatrixXf mat(5, 6);
47 mat << 0, 3, 0, 0, 0, 11, 22, 0, 0, 0, 17, 11, 7, 5, 0, 1, 0, 11, 0,
48 0, 0, 0, 0, 11, 0, 0, 14, 0, 8, 11;
86 m.def("double_col", [](const Eigen::VectorXf &x) -> Eigen::VectorXf { return 2.0f * x; });
87 m.def("double_row", [](const Eigen::RowVectorXf &x) -> Eigen::RowVectorXf { return 2.0f * x; });
88 m.def("double_complex", [](const Eigen::VectorXcf &x) -> Eigen::VectorXcf { return 2.0f * x; });
89 m.def("double_threec", [](py::EigenDRef<Eigen::Vector3f> x) { x *= 2; });
90 m.def("double_threer", [](py::EigenDRef<Eigen::RowVector3f> x) { x *= 2; });
91 m.def("double_mat_cm", [](Eigen::MatrixXf x) -> Eigen::MatrixXf { return 2.0f * x; });
92 m.def("double_mat_rm", [](DenseMatrixR x) -> DenseMatrixR { return 2.0f * x; });
49
93
50 m.def("double_col", &double_col);
51 m.def("double_row", &double_row);
52 m.def("double_mat_cm", &double_mat_cm);
53 m.def("double_mat_rm", &double_mat_rm);
54 m.def("cholesky1", &cholesky1);
55 m.def("cholesky2", &cholesky2);
56 m.def("cholesky3", &cholesky3);
57 m.def("cholesky4", &cholesky4);
58 m.def("cholesky5", &cholesky5);
59 m.def("cholesky6", &cholesky6);
94 // Different ways of passing via Eigen::Ref; the first and second are the Eigen-recommended
95 m.def("cholesky1", [](Eigen::Ref<MatrixXdR> x) -> Eigen::MatrixXd { return x.llt().matrixL(); });
96 m.def("cholesky2", [](const Eigen::Ref<const MatrixXdR> &x) -> Eigen::MatrixXd { return x.llt().matrixL(); });
97 m.def("cholesky3", [](const Eigen::Ref<MatrixXdR> &x) -> Eigen::MatrixXd { return x.llt().matrixL(); });
98 m.def("cholesky4", [](Eigen::Ref<const MatrixXdR> x) -> Eigen::MatrixXd { return x.llt().matrixL(); });
60
99
100 // Mutators: these add some value to the given element using Eigen, but Eigen should be mapping into
101 // the numpy array data and so the result should show up there. There are three versions: one that
102 // works on a contiguous-row matrix (numpy's default), one for a contiguous-column matrix, and one
103 // for any matrix.
104 auto add_rm = [](Eigen::Ref<MatrixXdR> x, int r, int c, double v) { x(r,c) += v; };
105 auto add_cm = [](Eigen::Ref<Eigen::MatrixXd> x, int r, int c, double v) { x(r,c) += v; };
106
107 // Mutators (Eigen maps into numpy variables):
108 m.def("add_rm", add_rm); // Only takes row-contiguous
109 m.def("add_cm", add_cm); // Only takes column-contiguous
110 // Overloaded versions that will accept either row or column contiguous:
111 m.def("add1", add_rm);
112 m.def("add1", add_cm);
113 m.def("add2", add_cm);
114 m.def("add2", add_rm);
115 // This one accepts a matrix of any stride:
116 m.def("add_any", [](py::EigenDRef<Eigen::MatrixXd> x, int r, int c, double v) { x(r,c) += v; });
117
118 // Return mutable references (numpy maps into eigen varibles)
119 m.def("get_cm_ref", []() { return Eigen::Ref<Eigen::MatrixXd>(get_cm()); });
120 m.def("get_rm_ref", []() { return Eigen::Ref<MatrixXdR>(get_rm()); });
121 // The same references, but non-mutable (numpy maps into eigen variables, but is !writeable)
122 m.def("get_cm_const_ref", []() { return Eigen::Ref<const Eigen::MatrixXd>(get_cm()); });
123 m.def("get_rm_const_ref", []() { return Eigen::Ref<const MatrixXdR>(get_rm()); });
124 // Just the corners (via a Map instead of a Ref):
125 m.def("get_cm_corners", []() {
126 auto &x = get_cm();
127 return py::EigenDMap<Eigen::Matrix2d>(
128 x.data(),
129 py::EigenDStride(x.outerStride() * (x.rows() - 1), x.innerStride() * (x.cols() - 1)));
130 });
131 m.def("get_cm_corners_const", []() {
132 const auto &x = get_cm();
133 return py::EigenDMap<const Eigen::Matrix2d>(
134 x.data(),
135 py::EigenDStride(x.outerStride() * (x.rows() - 1), x.innerStride() * (x.cols() - 1)));
136 });
137
138 m.def("reset_refs", reset_refs); // Restores get_{cm,rm}_ref to original values
139
140 // Increments and returns ref to (same) matrix
141 m.def("incr_matrix", [](Eigen::Ref<Eigen::MatrixXd> m, double v) {
142 m += Eigen::MatrixXd::Constant(m.rows(), m.cols(), v);
143 return m;
144 }, py::return_value_policy::reference);
145
146 // Same, but accepts a matrix of any strides
147 m.def("incr_matrix_any", [](py::EigenDRef<Eigen::MatrixXd> m, double v) {
148 m += Eigen::MatrixXd::Constant(m.rows(), m.cols(), v);
149 return m;
150 }, py::return_value_policy::reference);
151
152 // Returns an eigen slice of even rows
153 m.def("even_rows", [](py::EigenDRef<Eigen::MatrixXd> m) {
154 return py::EigenDMap<Eigen::MatrixXd>(
155 m.data(), (m.rows() + 1) / 2, m.cols(),
156 py::EigenDStride(m.outerStride(), 2 * m.innerStride()));
157 }, py::return_value_policy::reference);
158
159 // Returns an eigen slice of even columns
160 m.def("even_cols", [](py::EigenDRef<Eigen::MatrixXd> m) {
161 return py::EigenDMap<Eigen::MatrixXd>(
162 m.data(), m.rows(), (m.cols() + 1) / 2,
163 py::EigenDStride(2 * m.outerStride(), m.innerStride()));
164 }, py::return_value_policy::reference);
165
61 // Returns diagonals: a vector-like object with an inner stride != 1
62 m.def("diagonal", [](const Eigen::Ref<const Eigen::MatrixXd> &x) { return x.diagonal(); });
63 m.def("diagonal_1", [](const Eigen::Ref<const Eigen::MatrixXd> &x) { return x.diagonal<1>(); });
64 m.def("diagonal_n", [](const Eigen::Ref<const Eigen::MatrixXd> &x, int index) { return x.diagonal(index); });
65
66 // Return a block of a matrix (gives non-standard strides)
67 m.def("block", [](const Eigen::Ref<const Eigen::MatrixXd> &x, int start_row, int start_col, int block_rows, int block_cols) {
68 return x.block(start_row, start_col, block_rows, block_cols);
69 });
70
166 // Returns diagonals: a vector-like object with an inner stride != 1
167 m.def("diagonal", [](const Eigen::Ref<const Eigen::MatrixXd> &x) { return x.diagonal(); });
168 m.def("diagonal_1", [](const Eigen::Ref<const Eigen::MatrixXd> &x) { return x.diagonal<1>(); });
169 m.def("diagonal_n", [](const Eigen::Ref<const Eigen::MatrixXd> &x, int index) { return x.diagonal(index); });
170
171 // Return a block of a matrix (gives non-standard strides)
172 m.def("block", [](const Eigen::Ref<const Eigen::MatrixXd> &x, int start_row, int start_col, int block_rows, int block_cols) {
173 return x.block(start_row, start_col, block_rows, block_cols);
174 });
175
176 // return value referencing/copying tests:
177 class ReturnTester {
178 Eigen::MatrixXd mat = create();
179 public:
180 ReturnTester() { print_created(this); }
181 ~ReturnTester() { print_destroyed(this); }
182 static Eigen::MatrixXd create() { return Eigen::MatrixXd::Ones(10, 10); }
183 static const Eigen::MatrixXd createConst() { return Eigen::MatrixXd::Ones(10, 10); }
184 Eigen::MatrixXd &get() { return mat; }
185 Eigen::MatrixXd *getPtr() { return &mat; }
186 const Eigen::MatrixXd &view() { return mat; }
187 const Eigen::MatrixXd *viewPtr() { return &mat; }
188 Eigen::Ref<Eigen::MatrixXd> ref() { return mat; }
189 Eigen::Ref<const Eigen::MatrixXd> refConst() { return mat; }
190 Eigen::Block<Eigen::MatrixXd> block(int r, int c, int nrow, int ncol) { return mat.block(r, c, nrow, ncol); }
191 Eigen::Block<const Eigen::MatrixXd> blockConst(int r, int c, int nrow, int ncol) const { return mat.block(r, c, nrow, ncol); }
192 py::EigenDMap<Eigen::Matrix2d> corners() { return py::EigenDMap<Eigen::Matrix2d>(mat.data(),
193 py::EigenDStride(mat.outerStride() * (mat.outerSize()-1), mat.innerStride() * (mat.innerSize()-1))); }
194 py::EigenDMap<const Eigen::Matrix2d> cornersConst() const { return py::EigenDMap<const Eigen::Matrix2d>(mat.data(),
195 py::EigenDStride(mat.outerStride() * (mat.outerSize()-1), mat.innerStride() * (mat.innerSize()-1))); }
196 };
197 using rvp = py::return_value_policy;
198 py::class_<ReturnTester>(m, "ReturnTester")
199 .def(py::init<>())
200 .def_static("create", &ReturnTester::create)
201 .def_static("create_const", &ReturnTester::createConst)
202 .def("get", &ReturnTester::get, rvp::reference_internal)
203 .def("get_ptr", &ReturnTester::getPtr, rvp::reference_internal)
204 .def("view", &ReturnTester::view, rvp::reference_internal)
205 .def("view_ptr", &ReturnTester::view, rvp::reference_internal)
206 .def("copy_get", &ReturnTester::get) // Default rvp: copy
207 .def("copy_view", &ReturnTester::view) // "
208 .def("ref", &ReturnTester::ref) // Default for Ref is to reference
209 .def("ref_const", &ReturnTester::refConst) // Likewise, but const
210 .def("ref_safe", &ReturnTester::ref, rvp::reference_internal)
211 .def("ref_const_safe", &ReturnTester::refConst, rvp::reference_internal)
212 .def("copy_ref", &ReturnTester::ref, rvp::copy)
213 .def("copy_ref_const", &ReturnTester::refConst, rvp::copy)
214 .def("block", &ReturnTester::block)
215 .def("block_safe", &ReturnTester::block, rvp::reference_internal)
216 .def("block_const", &ReturnTester::blockConst, rvp::reference_internal)
217 .def("copy_block", &ReturnTester::block, rvp::copy)
218 .def("corners", &ReturnTester::corners, rvp::reference_internal)
219 .def("corners_const", &ReturnTester::cornersConst, rvp::reference_internal)
220 ;
221
71 // Returns a DiagonalMatrix with diagonal (1,2,3,...)
72 m.def("incr_diag", [](int k) {
73 Eigen::DiagonalMatrix<int, Eigen::Dynamic> m(k);
74 for (int i = 0; i < k; i++) m.diagonal()[i] = i+1;
75 return m;
76 });
77
78 // Returns a SelfAdjointView referencing the lower triangle of m
79 m.def("symmetric_lower", [](const Eigen::MatrixXi &m) {
80 return m.selfadjointView<Eigen::Lower>();
81 });
82 // Returns a SelfAdjointView referencing the lower triangle of m
83 m.def("symmetric_upper", [](const Eigen::MatrixXi &m) {
84 return m.selfadjointView<Eigen::Upper>();
85 });
86
222 // Returns a DiagonalMatrix with diagonal (1,2,3,...)
223 m.def("incr_diag", [](int k) {
224 Eigen::DiagonalMatrix<int, Eigen::Dynamic> m(k);
225 for (int i = 0; i < k; i++) m.diagonal()[i] = i+1;
226 return m;
227 });
228
229 // Returns a SelfAdjointView referencing the lower triangle of m
230 m.def("symmetric_lower", [](const Eigen::MatrixXi &m) {
231 return m.selfadjointView<Eigen::Lower>();
232 });
233 // Returns a SelfAdjointView referencing the lower triangle of m
234 m.def("symmetric_upper", [](const Eigen::MatrixXi &m) {
235 return m.selfadjointView<Eigen::Upper>();
236 });
237
87 m.def("fixed_r", [mat]() -> FixedMatrixR {
88 return FixedMatrixR(mat);
89 });
238 // Test matrix for various functions below.
239 Eigen::MatrixXf mat(5, 6);
240 mat << 0, 3, 0, 0, 0, 11,
241 22, 0, 0, 0, 17, 11,
242 7, 5, 0, 1, 0, 11,
243 0, 0, 0, 0, 0, 11,
244 0, 0, 14, 0, 8, 11;
90
245
91 m.def("fixed_c", [mat]() -> FixedMatrixC {
92 return FixedMatrixC(mat);
93 });
246 m.def("fixed_r", [mat]() -> FixedMatrixR { return FixedMatrixR(mat); });
247 m.def("fixed_r_const", [mat]() -> const FixedMatrixR { return FixedMatrixR(mat); });
248 m.def("fixed_c", [mat]() -> FixedMatrixC { return FixedMatrixC(mat); });
249 m.def("fixed_copy_r", [](const FixedMatrixR &m) -> FixedMatrixR { return m; });
250 m.def("fixed_copy_c", [](const FixedMatrixC &m) -> FixedMatrixC { return m; });
251 m.def("fixed_mutator_r", [](Eigen::Ref<FixedMatrixR>) {});
252 m.def("fixed_mutator_c", [](Eigen::Ref<FixedMatrixC>) {});
253 m.def("fixed_mutator_a", [](py::EigenDRef<FixedMatrixC>) {});
254 m.def("dense_r", [mat]() -> DenseMatrixR { return DenseMatrixR(mat); });
255 m.def("dense_c", [mat]() -> DenseMatrixC { return DenseMatrixC(mat); });
256 m.def("dense_copy_r", [](const DenseMatrixR &m) -> DenseMatrixR { return m; });
257 m.def("dense_copy_c", [](const DenseMatrixC &m) -> DenseMatrixC { return m; });
258 m.def("sparse_r", [mat]() -> SparseMatrixR { return Eigen::SparseView<Eigen::MatrixXf>(mat); });
259 m.def("sparse_c", [mat]() -> SparseMatrixC { return Eigen::SparseView<Eigen::MatrixXf>(mat); });
260 m.def("sparse_copy_r", [](const SparseMatrixR &m) -> SparseMatrixR { return m; });
261 m.def("sparse_copy_c", [](const SparseMatrixC &m) -> SparseMatrixC { return m; });
262 m.def("partial_copy_four_rm_r", [](const FourRowMatrixR &m) -> FourRowMatrixR { return m; });
263 m.def("partial_copy_four_rm_c", [](const FourColMatrixR &m) -> FourColMatrixR { return m; });
264 m.def("partial_copy_four_cm_r", [](const FourRowMatrixC &m) -> FourRowMatrixC { return m; });
265 m.def("partial_copy_four_cm_c", [](const FourColMatrixC &m) -> FourColMatrixC { return m; });
94
266
95 m.def("fixed_passthrough_r", [](const FixedMatrixR &m) -> FixedMatrixR {
96 return m;
97 });
267 // Test that we can cast a numpy object to a Eigen::MatrixXd explicitly
268 m.def("cpp_copy", [](py::handle m) { return m.cast<Eigen::MatrixXd>()(1, 0); });
269 m.def("cpp_ref_c", [](py::handle m) { return m.cast<Eigen::Ref<Eigen::MatrixXd>>()(1, 0); });
270 m.def("cpp_ref_r", [](py::handle m) { return m.cast<Eigen::Ref<MatrixXdR>>()(1, 0); });
271 m.def("cpp_ref_any", [](py::handle m) { return m.cast<py::EigenDRef<Eigen::MatrixXd>>()(1, 0); });
98
272
99 m.def("fixed_passthrough_c", [](const FixedMatrixC &m) -> FixedMatrixC {
100 return m;
101 });
102
273
103 m.def("dense_r", [mat]() -> DenseMatrixR {
104 return DenseMatrixR(mat);
105 });
274 // Test that we can prevent copying into an argument that would normally copy: First a version
275 // that would allow copying (if types or strides don't match) for comparison:
276 m.def("get_elem", &get_elem);
277 // Now this alternative that calls the tells pybind to fail rather than copy:
278 m.def("get_elem_nocopy", [](Eigen::Ref<const Eigen::MatrixXd> m) -> double { return get_elem(m); },
279 py::arg().noconvert());
280 // Also test a row-major-only no-copy const ref:
281 m.def("get_elem_rm_nocopy", [](Eigen::Ref<const Eigen::Matrix<long, -1, -1, Eigen::RowMajor>> &m) -> long { return m(2, 1); },
282 py::arg().noconvert());
106
283
107 m.def("dense_c", [mat]() -> DenseMatrixC {
108 return DenseMatrixC(mat);
109 });
284 // Issue #738: 1xN or Nx1 2D matrices were neither accepted nor properly copied with an
285 // incompatible stride value on the length-1 dimension--but that should be allowed (without
286 // requiring a copy!) because the stride value can be safely ignored on a size-1 dimension.
287 m.def("iss738_f1", &adjust_matrix<const Eigen::Ref<const Eigen::MatrixXd> &>, py::arg().noconvert());
288 m.def("iss738_f2", &adjust_matrix<const Eigen::Ref<const Eigen::Matrix<double, -1, -1, Eigen::RowMajor>> &>, py::arg().noconvert());
110
289
111 m.def("dense_passthrough_r", [](const DenseMatrixR &m) -> DenseMatrixR {
112 return m;
113 });
114
115 m.def("dense_passthrough_c", [](const DenseMatrixC &m) -> DenseMatrixC {
116 return m;
117 });
118
119 m.def("sparse_r", [mat]() -> SparseMatrixR {
120 return Eigen::SparseView<Eigen::MatrixXf>(mat);
121 });
122
123 m.def("sparse_c", [mat]() -> SparseMatrixC {
124 return Eigen::SparseView<Eigen::MatrixXf>(mat);
125 });
126
127 m.def("sparse_passthrough_r", [](const SparseMatrixR &m) -> SparseMatrixR {
128 return m;
129 });
130
131 m.def("sparse_passthrough_c", [](const SparseMatrixC &m) -> SparseMatrixC {
132 return m;
133 });
290 py::class_<CustomOperatorNew>(m, "CustomOperatorNew")
291 .def(py::init<>())
292 .def_readonly("a", &CustomOperatorNew::a)
293 .def_readonly("b", &CustomOperatorNew::b);
134});
294});