Merge lp:~honzik/minieigen/minieigen into lp:~eudoxos/minieigen/trunk

Proposed by Václav Šmilauer
Status: Merged
Merge reported by: Václav Šmilauer
Merged at revision: not available
Proposed branch: lp:~honzik/minieigen/minieigen
Merge into: lp:~eudoxos/minieigen/trunk
Diff against target: 110 lines (+72/-0)
1 file modified
minieigen/minieigen.cpp (+72/-0)
To merge this branch: bzr merge lp:~honzik/minieigen/minieigen
Reviewer Review Type Date Requested Status
Václav Šmilauer Approve
Review via email: mp+175521@code.launchpad.net

Description of the change

Add various decompositions

To post a comment you must log in.
Revision history for this message
Václav Šmilauer (eudoxos) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'minieigen/minieigen.cpp'
--- minieigen/minieigen.cpp 2013-04-18 21:04:34 +0000
+++ minieigen/minieigen.cpp 2013-07-18 10:20:35 +0000
@@ -426,6 +426,7 @@
426 static Vector3r Matrix3r_leviCivita(const Matrix3r& self){ return leviCivita(self); }426 static Vector3r Matrix3r_leviCivita(const Matrix3r& self){ return leviCivita(self); }
427#endif427#endif
428428
429
429/*** wrapping methods which are defined by eigen, but return expression template, which does not work with python ***/430/*** wrapping methods which are defined by eigen, but return expression template, which does not work with python ***/
430static Vector3r Quaternionr_Rotate(Quaternionr& q, const Vector3r& u){ return q*u; }431static Vector3r Quaternionr_Rotate(Quaternionr& q, const Vector3r& u){ return q*u; }
431// supposed to return raw pointer (or auto_ptr), boost::python takes care of the lifetime management432// supposed to return raw pointer (or auto_ptr), boost::python takes care of the lifetime management
@@ -466,6 +467,57 @@
466template<typename VT> Eigen::Matrix<typename VT::Scalar,VT::RowsAtCompileTime,VT::RowsAtCompileTime>467template<typename VT> Eigen::Matrix<typename VT::Scalar,VT::RowsAtCompileTime,VT::RowsAtCompileTime>
467Vector_asDiagonal(const VT& self){ return self.asDiagonal(); }468Vector_asDiagonal(const VT& self){ return self.asDiagonal(); }
468469
470
471/****** matrix decompositions ******/
472// svd decomposition
473template<typename MatrixInType, typename MatrixUType, typename MatrixSType, typename MatrixVType>
474py::tuple Matrix_jacobiSVD(const MatrixInType& in) {
475 MatrixUType u;
476 MatrixVType v;
477 MatrixSType s;
478 Eigen::JacobiSVD<MatrixInType> svd(in, Eigen::ComputeThinU | Eigen::ComputeThinV);
479 u = svd.matrixU();
480 v = svd.matrixV();
481 s = svd.singularValues().asDiagonal();
482 return py::make_tuple(u,s,v);
483}
484static py::tuple Matrix3r_jacobiSVD(const Matrix3r& in) { return Matrix_jacobiSVD<Matrix3r,Matrix3r,Matrix3r,Matrix3r>(in); }
485static py::tuple Matrix6r_jacobiSVD(const Matrix6r& in) { return Matrix_jacobiSVD<Matrix6r,Matrix6r,Matrix6r,Matrix6r>(in); }
486static py::tuple MatrixXr_jacobiSVD(const MatrixXr& in) { return Matrix_jacobiSVD<MatrixXr,MatrixXr,MatrixXr,MatrixXr>(in); }
487
488// polar decomposition
489template<typename MatrixType>
490py::tuple Matrix_computeUnitaryPositive(const MatrixType& in) {
491 assert(in.rows()==in.cols());
492 MatrixType u, s, v, retU, retP;
493 Eigen::JacobiSVD<MatrixType> svd(in, Eigen::ComputeThinU | Eigen::ComputeThinV);
494 u = svd.matrixU();
495 v = svd.matrixV();
496 s = svd.singularValues().asDiagonal();
497 retU = u*v.transpose();
498 retP = v*s*v.transpose();
499 return py::make_tuple(retU,retP);
500}
501static py::tuple Matrix3r_computeUnitaryPositive(const Matrix3r& in) { return Matrix_computeUnitaryPositive<Matrix3r>(in); }
502static py::tuple Matrix6r_computeUnitaryPositive(const Matrix6r& in) { return Matrix_computeUnitaryPositive<Matrix6r>(in); }
503static py::tuple MatrixXr_computeUnitaryPositive(const MatrixXr& in) { return Matrix_computeUnitaryPositive<MatrixXr>(in); }
504
505// eigen decomposition
506template<typename MatrixType, typename VectorType>
507py::tuple Matrix_selfAdjointEigenDecomposition(const MatrixType& in) {
508 MatrixType eigVecs;
509 VectorType eigVals;
510 Eigen::SelfAdjointEigenSolver<MatrixType> a(in); eigVecs=a.eigenvectors(); eigVals=a.eigenvalues();
511 return py::make_tuple(eigVecs,eigVals);
512}
513static py::tuple Matrix3r_selfAdjointEigenDecomposition(const Matrix3r& in) { return Matrix_selfAdjointEigenDecomposition<Matrix3r,Vector3r>(in); }
514static py::tuple Matrix6r_selfAdjointEigenDecomposition(const Matrix6r& in) { return Matrix_selfAdjointEigenDecomposition<Matrix6r,Vector6r>(in); }
515static py::tuple MatrixXr_selfAdjointEigenDecomposition(const MatrixXr& in) { return Matrix_selfAdjointEigenDecomposition<MatrixXr,VectorXr>(in); }
516
517
518
519
520
469#undef IDX_CHECK521#undef IDX_CHECK
470522
471// those are again needed to wrap the result (TODO: use some templates here)523// those are again needed to wrap the result (TODO: use some templates here)
@@ -647,6 +699,12 @@
647 .add_static_property("Zero",&Matrix3r_Zero)699 .add_static_property("Zero",&Matrix3r_Zero)
648 .add_static_property("Ones",&Matrix3r_Ones)700 .add_static_property("Ones",&Matrix3r_Ones)
649 .def("Random",&Matrix3r_Random).staticmethod("Random")701 .def("Random",&Matrix3r_Random).staticmethod("Random")
702 .def("jacobiSVD",&Matrix3r_jacobiSVD,"Compute SVD decomposition of matrix, retuns (U,S,V) such that self=U*S*V.transpose()")
703 .def("svd",&Matrix3r_jacobiSVD,"Shortcut for jacobiSVD")
704 .def("computeUnitaryPositive",&Matrix3r_computeUnitaryPositive,"Compute polar decomposition (unitary matrix U and positive semi-definite symmetric matrix P such that self=U*P")
705 .def("polarDecomposition",&Matrix3r_computeUnitaryPositive,"Shortcut for computeUnitaryPositive")
706 .def("selfAdjointEigenDecomposition",&Matrix3r_selfAdjointEigenDecomposition,"Compute eigen (spectral) decomposition of symmetric matrix, returns (eigVecs,eigVals). eigVecs is orthogonal Matrix3 with columns ar normalized eigenvectors, eigVals is Vector3 with corresponding eigenvalues. self=eigVecs*diag(eigVals)*eigVecs.transpose()")
707 .def("spectralDecomposition",&Matrix3r_selfAdjointEigenDecomposition,"Shortcut for selfAdjointEigenDecomposition")
650 #if 0708 #if 0
651 .def("polarDecomposition",&Matrix3r_polarDecomposition)709 .def("polarDecomposition",&Matrix3r_polarDecomposition)
652 .def("symmEigen",&Matrix3r_symmEigen)710 .def("symmEigen",&Matrix3r_symmEigen)
@@ -675,6 +733,13 @@
675 .def("ur",&Matrix6r_ur)733 .def("ur",&Matrix6r_ur)
676 .def("ll",&Matrix6r_ll)734 .def("ll",&Matrix6r_ll)
677 .def("lr",&Matrix6r_lr)735 .def("lr",&Matrix6r_lr)
736 //
737 .def("jacobiSVD",&Matrix6r_jacobiSVD,"Compute SVD decomposition of matrix, retuns (U,S,V) such that self=U*S*V.transpose()")
738 .def("svd",&Matrix6r_jacobiSVD,"Shortcut for jacobiSVD")
739 .def("computeUnitaryPositive",&Matrix6r_computeUnitaryPositive,"Compute polar decomposition (unitary matrix U and positive semi-definite symmetric matrix P such that self=U*P")
740 .def("polarDecomposition",&Matrix6r_computeUnitaryPositive,"Shortcut for computeUnitaryPositive")
741 .def("selfAdjointEigenDecomposition",&Matrix6r_selfAdjointEigenDecomposition,"Compute eigen (spectral) decomposition of symmetric matrix, returns (eigVecs,eigVals). eigVecs is orthogonal Matrix6 with columns ar normalized eigenvectors, eigVals is Vector6 with corresponding eigenvalues. self=eigVecs*diag(eigVals)*eigVecs.transpose()")
742 .def("spectralDecomposition",&Matrix6r_selfAdjointEigenDecomposition,"Shortcut for selfAdjointEigenDecomposition")
678743
679 //744 //
680 .def("__neg__",&Matrix6r__neg__)745 .def("__neg__",&Matrix6r__neg__)
@@ -763,6 +828,13 @@
763 .def("pruned",&Matrix_pruned<MatrixXr>,py::arg("absTol")=1e-6)828 .def("pruned",&Matrix_pruned<MatrixXr>,py::arg("absTol")=1e-6)
764 .def("maxAbsCoeff",&Matrix_maxAbsCoeff<MatrixXr>)829 .def("maxAbsCoeff",&Matrix_maxAbsCoeff<MatrixXr>)
765 .def("sum",&Matrix_sum<MatrixXr>)830 .def("sum",&Matrix_sum<MatrixXr>)
831 //
832 .def("jacobiSVD",&MatrixXr_jacobiSVD,"Compute SVD decomposition of matrix, retuns (U,S,V) such that self=U*S*V.transpose()")
833 .def("svd",&MatrixXr_jacobiSVD,"Shortcut for jacobiSVD")
834 .def("computeUnitaryPositive",&MatrixXr_computeUnitaryPositive,"Compute polar decomposition (unitary matrix U and positive semi-definite symmetric matrix P such that self=U*P")
835 .def("polarDecomposition",&MatrixXr_computeUnitaryPositive,"Shortcut for computeUnitaryPositive")
836 .def("selfAdjointEigenDecomposition",&MatrixXr_selfAdjointEigenDecomposition,"Compute eigen (spectral) decomposition of symmetric matrix, returns (eigVecs,eigVals). eigVecs is orthogonal MatrixX with columns ar normalized eigenvectors, eigVals is VectorX with corresponding eigenvalues. self=eigVecs*diag(eigVals)*eigVecs.transpose()")
837 .def("spectralDecomposition",&MatrixXr_selfAdjointEigenDecomposition,"Shortcut for selfAdjointEigenDecomposition")
766838
767 //839 //
768 .def("__neg__",&MatrixXr__neg__)840 .def("__neg__",&MatrixXr__neg__)

Subscribers

People subscribed via source and target branches