17 # pragma warning(disable : 4996) // C4996: std::unary_negation is deprecated 20 #include <Eigen/Cholesky> 28 for (
int i = 0;
i < x.rows();
i++) {
29 for (
int j = 0;
j < x.cols();
j++) {
30 x(
i,
j) = 11 + 10 *
i +
j;
37 static Eigen::MatrixXd *
x;
39 x =
new Eigen::MatrixXd(3, 3);
64 template <
typename MatrixArgType>
66 Eigen::MatrixXd
ret(m);
67 for (
int c = 0;
c < m.cols();
c++) {
68 for (
int r = 0; r < m.rows(); r++) {
69 ret(r,
c) += 10 * r + 100 *
c;
78 Eigen::Matrix4d
a = Eigen::Matrix4d::Zero();
79 Eigen::Matrix4d
b = Eigen::Matrix4d::Identity();
97 m.def(
"double_col", [](
const Eigen::VectorXf &
x) -> Eigen::VectorXf {
return 2.0f *
x; });
99 [](
const Eigen::RowVectorXf &x) -> Eigen::RowVectorXf {
return 2.0f *
x; });
100 m.def(
"double_complex",
101 [](
const Eigen::VectorXcf &x) -> Eigen::VectorXcf {
return 2.0f *
x; });
102 m.def(
"double_threec", [](py::EigenDRef<Eigen::Vector3f> x) { x *= 2; });
103 m.def(
"double_threer", [](py::EigenDRef<Eigen::RowVector3f> x) { x *= 2; });
104 m.def(
"double_mat_cm", [](
const Eigen::MatrixXf &x) -> Eigen::MatrixXf {
return 2.0f *
x; });
105 m.def(
"double_mat_rm", [](
const DenseMatrixR &x) -> DenseMatrixR {
return 2.0f *
x; });
112 return x.llt().matrixL();
117 return x.llt().matrixL();
129 m.def(
"add_rm", add_rm);
130 m.def(
"add_cm", add_cm);
132 m.def(
"add1", add_rm);
133 m.def(
"add1", add_cm);
134 m.def(
"add2", add_cm);
135 m.def(
"add2", add_rm);
138 [](py::EigenDRef<Eigen::MatrixXd> x,
int r,
int c,
double v) {
x(r, c) +=
v; });
153 m += Eigen::MatrixXd::Constant(m.rows(), m.cols(),
v);
156 py::return_value_policy::reference);
161 [](py::EigenDRef<Eigen::MatrixXd> m,
double v) {
162 m += Eigen::MatrixXd::Constant(m.rows(), m.cols(),
v);
165 py::return_value_policy::reference);
170 [](py::EigenDRef<Eigen::MatrixXd> m) {
171 return py::EigenDMap<Eigen::MatrixXd>(
177 py::return_value_policy::reference);
182 [](py::EigenDRef<Eigen::MatrixXd> m) {
183 return py::EigenDMap<Eigen::MatrixXd>(
189 py::return_value_policy::reference);
204 int block_cols) {
return x.block(start_row, start_col, block_rows, block_cols); });
214 static Eigen::MatrixXd
create() {
return Eigen::MatrixXd::Ones(10, 10); }
216 static const Eigen::MatrixXd createConst() {
return Eigen::MatrixXd::Ones(10, 10); }
217 Eigen::MatrixXd &
get() {
return mat; }
218 Eigen::MatrixXd *getPtr() {
return &
mat; }
219 const Eigen::MatrixXd &
view() {
return mat; }
220 const Eigen::MatrixXd *viewPtr() {
return &
mat; }
224 return mat.block(r, c, nrow, ncol);
227 return mat.block(r, c, nrow, ncol);
229 py::EigenDMap<Eigen::Matrix2d>
corners() {
230 return py::EigenDMap<Eigen::Matrix2d>(
233 mat.innerStride() * (mat.innerSize() - 1)));
235 py::EigenDMap<const Eigen::Matrix2d> cornersConst()
const {
236 return py::EigenDMap<const Eigen::Matrix2d>(
239 mat.innerStride() * (mat.innerSize() - 1)));
243 py::class_<ReturnTester>(
m,
"ReturnTester")
246 .def_static(
"create_const", &ReturnTester::createConst)
248 .def(
"get_ptr", &ReturnTester::getPtr, rvp::reference_internal)
254 .def(
"ref_const", &ReturnTester::refConst)
256 .def(
"ref_const_safe", &ReturnTester::refConst, rvp::reference_internal)
258 .def(
"copy_ref_const", &ReturnTester::refConst,
rvp::copy)
261 .def(
"block_const", &ReturnTester::blockConst, rvp::reference_internal)
264 .def(
"corners_const", &ReturnTester::cornersConst, rvp::reference_internal);
268 m.def(
"incr_diag", [](
int k) {
270 for (
int i = 0;
i < k;
i++) {
277 m.def(
"symmetric_lower",
278 [](
const Eigen::MatrixXi &m) {
return m.selfadjointView<
Eigen::Lower>(); });
280 m.def(
"symmetric_upper",
281 [](
const Eigen::MatrixXi &m) {
return m.selfadjointView<
Eigen::Upper>(); });
284 Eigen::MatrixXf
mat(5, 6);
285 mat << 0, 3, 0, 0, 0, 11, 22, 0, 0, 0, 17, 11, 7, 5, 0, 1, 0, 11, 0, 0, 0, 0, 0, 11, 0, 0, 14,
289 m.def(
"fixed_r", [mat]() -> FixedMatrixR {
return FixedMatrixR(mat); });
293 m.def(
"fixed_r_const", [mat]() ->
const FixedMatrixR {
return FixedMatrixR(mat); });
294 m.def(
"fixed_c", [mat]() -> FixedMatrixC {
return FixedMatrixC(mat); });
295 m.def(
"fixed_copy_r", [](
const FixedMatrixR &m) -> FixedMatrixR {
return m; });
296 m.def(
"fixed_copy_c", [](
const FixedMatrixC &m) -> FixedMatrixC {
return m; });
300 m.def(
"fixed_mutator_a", [](
const py::EigenDRef<FixedMatrixC> &) {});
302 m.def(
"dense_r", [mat]() -> DenseMatrixR {
return DenseMatrixR(mat); });
303 m.def(
"dense_c", [mat]() -> DenseMatrixC {
return DenseMatrixC(mat); });
304 m.def(
"dense_copy_r", [](
const DenseMatrixR &m) -> DenseMatrixR {
return m; });
305 m.def(
"dense_copy_c", [](
const DenseMatrixC &m) -> DenseMatrixC {
return m; });
307 m.def(
"sparse_r", [mat]() -> SparseMatrixR {
313 m.def(
"sparse_copy_r", [](
const SparseMatrixR &m) -> SparseMatrixR {
return m; });
314 m.def(
"sparse_copy_c", [](
const SparseMatrixC &m) -> SparseMatrixC {
return m; });
316 m.def(
"partial_copy_four_rm_r", [](
const FourRowMatrixR &m) -> FourRowMatrixR {
return m; });
317 m.def(
"partial_copy_four_rm_c", [](
const FourColMatrixR &m) -> FourColMatrixR {
return m; });
318 m.def(
"partial_copy_four_cm_r", [](
const FourRowMatrixC &m) -> FourRowMatrixC {
return m; });
319 m.def(
"partial_copy_four_cm_c", [](
const FourColMatrixC &m) -> FourColMatrixC {
return m; });
323 m.def(
"cpp_copy", [](py::handle m) {
return m.cast<Eigen::MatrixXd>()(1, 0); });
327 [](py::handle m) {
return m.cast<py::EigenDRef<Eigen::MatrixXd>>()(1, 0); });
342 "get_elem_rm_nocopy",
366 m.def(
"iss1105_col", [](
const Eigen::VectorXd &) {
return true; });
367 m.def(
"iss1105_row", [](
const Eigen::RowVectorXd &) {
return true; });
373 [](
const py::EigenDRef<const Eigen::MatrixXd> &
A,
374 const py::EigenDRef<const Eigen::MatrixXd> &
B) -> Eigen::MatrixXd {
375 if (A.cols() != B.rows()) {
376 throw std::domain_error(
"Nonconformable matrices!");
384 py::class_<CustomOperatorNew>(
m,
"CustomOperatorNew")
394 py::module_::import(
"numpy").attr(
"ones")(10);
398 py::module_::import(
"numpy").attr(
"ones")(10);
Matrix< RealScalar, Dynamic, Dynamic > M
m m block(1, 0, 2, 2)<< 4
Eigen::Stride< Eigen::Dynamic, Eigen::Dynamic > EigenDStride
A versatible sparse matrix representation.
EIGEN_DEVICE_FUNC const DiagonalVectorType & diagonal() const
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor > MatrixXdR
void print_destroyed(T *inst, Values &&...values)
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy y set format x g set format y g set format x2 g set format y2 g set format z g set angles radians set nogrid set key title set key left top Right noreverse box linetype linewidth samplen spacing width set nolabel set noarrow set nologscale set logscale x set set pointsize set encoding default set nopolar set noparametric set view
Represents a diagonal matrix with its storage.
double get_elem(const Eigen::Ref< const Eigen::MatrixXd > &m)
Eigen::MatrixXd & get_cm()
CustomOperatorNew()=default
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const ArgReturnType arg() const
Array< int, Dynamic, 1 > v
Expression of a dense or sparse matrix with zero or too small values removed.
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
A matrix or vector expression mapping an existing expression.
ADT create(const Signature &signature)
Expression of a fixed-size or dynamic-size block.
void print_created(T *inst, Values &&...values)
void corners(const MatrixType &m)
Eigen::MatrixXd adjust_matrix(MatrixArgType m)
int EIGEN_BLAS_FUNC() copy(int *n, RealScalar *px, int *incx, RealScalar *py, int *incy)
Container::iterator get(Container &c, Position position)
The matrix class, also used for vectors and row-vectors.
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy x
return_value_policy
Approach used to cast a previously unknown C++ instance into a Python object.