16 # pragma warning(disable: 4996) // C4996: std::unary_negation is deprecated 19 #include <Eigen/Cholesky> 28 for (
int i = 0;
i < x.rows();
i++)
for (
int j = 0;
j < x.cols();
j++)
29 x(
i,
j) = 11 + 10*
i +
j;
34 static Eigen::MatrixXd *
x;
36 x =
new Eigen::MatrixXd(3, 3);
62 template <
typename MatrixArgType> Eigen::MatrixXd
adjust_matrix(MatrixArgType
m) {
63 Eigen::MatrixXd
ret(m);
64 for (
int c = 0;
c < m.cols();
c++)
for (
int r = 0; r < m.rows(); r++)
65 ret(r,
c) += 10*r + 100*
c;
72 Eigen::Matrix4d
a = Eigen::Matrix4d::Zero();
73 Eigen::Matrix4d
b = Eigen::Matrix4d::Identity();
91 m.def(
"double_col", [](
const Eigen::VectorXf &
x) -> Eigen::VectorXf {
return 2.0f *
x; });
92 m.def(
"double_row", [](
const Eigen::RowVectorXf &x) -> Eigen::RowVectorXf {
return 2.0f *
x; });
93 m.def(
"double_complex", [](
const Eigen::VectorXcf &x) -> Eigen::VectorXcf {
return 2.0f *
x; });
94 m.def(
"double_threec", [](py::EigenDRef<Eigen::Vector3f> x) { x *= 2; });
95 m.def(
"double_threer", [](py::EigenDRef<Eigen::RowVector3f> x) { x *= 2; });
96 m.def(
"double_mat_cm", [](Eigen::MatrixXf x) -> Eigen::MatrixXf {
return 2.0f *
x; });
97 m.def(
"double_mat_rm", [](DenseMatrixR x) -> DenseMatrixR {
return 2.0f *
x; });
115 m.def(
"add_rm", add_rm);
116 m.def(
"add_cm", add_cm);
118 m.def(
"add1", add_rm);
119 m.def(
"add1", add_cm);
120 m.def(
"add2", add_cm);
121 m.def(
"add2", add_rm);
123 m.def(
"add_any", [](py::EigenDRef<Eigen::MatrixXd> x,
int r,
int c,
double v) {
x(r,c) +=
v; });
136 m += Eigen::MatrixXd::Constant(m.rows(), m.cols(),
v);
138 }, py::return_value_policy::reference);
141 m.def(
"incr_matrix_any", [](py::EigenDRef<Eigen::MatrixXd> m,
double v) {
142 m += Eigen::MatrixXd::Constant(m.rows(), m.cols(),
v);
144 }, py::return_value_policy::reference);
147 m.def(
"even_rows", [](py::EigenDRef<Eigen::MatrixXd> m) {
148 return py::EigenDMap<Eigen::MatrixXd>(
149 m.data(), (m.rows() + 1) / 2, m.cols(),
151 }, py::return_value_policy::reference);
154 m.def(
"even_cols", [](py::EigenDRef<Eigen::MatrixXd> m) {
155 return py::EigenDMap<Eigen::MatrixXd>(
156 m.data(), m.rows(), (m.cols() + 1) / 2,
158 }, py::return_value_policy::reference);
167 return x.block(start_row, start_col, block_rows, block_cols);
177 static Eigen::MatrixXd
create() {
return Eigen::MatrixXd::Ones(10, 10); }
178 static const Eigen::MatrixXd createConst() {
return Eigen::MatrixXd::Ones(10, 10); }
179 Eigen::MatrixXd &
get() {
return mat; }
180 Eigen::MatrixXd *getPtr() {
return &
mat; }
181 const Eigen::MatrixXd &
view() {
return mat; }
182 const Eigen::MatrixXd *viewPtr() {
return &
mat; }
187 py::EigenDMap<Eigen::Matrix2d>
corners() {
return py::EigenDMap<Eigen::Matrix2d>(mat.data(),
188 py::EigenDStride(mat.outerStride() * (mat.outerSize()-1), mat.innerStride() * (mat.innerSize()-1))); }
189 py::EigenDMap<const Eigen::Matrix2d> cornersConst()
const {
return py::EigenDMap<const Eigen::Matrix2d>(mat.data(),
190 py::EigenDStride(mat.outerStride() * (mat.outerSize()-1), mat.innerStride() * (mat.innerSize()-1))); }
193 py::class_<ReturnTester>(
m,
"ReturnTester")
196 .def_static(
"create_const", &ReturnTester::createConst)
198 .def(
"get_ptr", &ReturnTester::getPtr, rvp::reference_internal)
204 .def(
"ref_const", &ReturnTester::refConst)
206 .def(
"ref_const_safe", &ReturnTester::refConst, rvp::reference_internal)
208 .def(
"copy_ref_const", &ReturnTester::refConst,
rvp::copy)
211 .def(
"block_const", &ReturnTester::blockConst, rvp::reference_internal)
214 .def(
"corners_const", &ReturnTester::cornersConst, rvp::reference_internal)
219 m.def(
"incr_diag", [](
int k) {
226 m.def(
"symmetric_lower", [](
const Eigen::MatrixXi &m) {
230 m.def(
"symmetric_upper", [](
const Eigen::MatrixXi &m) {
235 Eigen::MatrixXf
mat(5, 6);
236 mat << 0, 3, 0, 0, 0, 11,
243 m.def(
"fixed_r", [mat]() -> FixedMatrixR {
return FixedMatrixR(mat); });
244 m.def(
"fixed_r_const", [mat]() ->
const FixedMatrixR {
return FixedMatrixR(mat); });
245 m.def(
"fixed_c", [mat]() -> FixedMatrixC {
return FixedMatrixC(mat); });
246 m.def(
"fixed_copy_r", [](
const FixedMatrixR &m) -> FixedMatrixR {
return m; });
247 m.def(
"fixed_copy_c", [](
const FixedMatrixC &m) -> FixedMatrixC {
return m; });
251 m.def(
"fixed_mutator_a", [](py::EigenDRef<FixedMatrixC>) {});
253 m.def(
"dense_r", [mat]() -> DenseMatrixR {
return DenseMatrixR(mat); });
254 m.def(
"dense_c", [mat]() -> DenseMatrixC {
return DenseMatrixC(mat); });
255 m.def(
"dense_copy_r", [](
const DenseMatrixR &m) -> DenseMatrixR {
return m; });
256 m.def(
"dense_copy_c", [](
const DenseMatrixC &m) -> DenseMatrixC {
return m; });
260 m.def(
"sparse_copy_r", [](
const SparseMatrixR &m) -> SparseMatrixR {
return m; });
261 m.def(
"sparse_copy_c", [](
const SparseMatrixC &m) -> SparseMatrixC {
return m; });
263 m.def(
"partial_copy_four_rm_r", [](
const FourRowMatrixR &m) -> FourRowMatrixR {
return m; });
264 m.def(
"partial_copy_four_rm_c", [](
const FourColMatrixR &m) -> FourColMatrixR {
return m; });
265 m.def(
"partial_copy_four_cm_r", [](
const FourRowMatrixC &m) -> FourRowMatrixC {
return m; });
266 m.def(
"partial_copy_four_cm_c", [](
const FourColMatrixC &m) -> FourColMatrixC {
return m; });
270 m.def(
"cpp_copy", [](py::handle m) {
return m.cast<Eigen::MatrixXd>()(1, 0); });
273 m.def(
"cpp_ref_any", [](py::handle m) {
return m.cast<py::EigenDRef<Eigen::MatrixXd>>()(1, 0); });
298 m.def(
"iss1105_col", [](Eigen::VectorXd) {
return true; });
299 m.def(
"iss1105_row", [](Eigen::RowVectorXd) {
return true; });
303 m.def(
"matrix_multiply", [](
const py::EigenDRef<const Eigen::MatrixXd>
A,
const py::EigenDRef<const Eigen::MatrixXd>
B)
305 if (A.cols() != B.rows())
throw std::domain_error(
"Nonconformable matrices!");
310 py::class_<CustomOperatorNew>(
m,
"CustomOperatorNew")
320 py::module::import(
"numpy").attr(
"ones")(10);
324 py::module::import(
"numpy").attr(
"ones")(10);
double get_elem(Eigen::Ref< const Eigen::MatrixXd > m)
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::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.
Eigen::MatrixXd & get_cm()
CustomOperatorNew()=default
EIGEN_DEVICE_FUNC const DiagonalVectorType & diagonal() const
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.
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const ArgReturnType arg() const
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.