29 #ifndef _TOMOGRAPHER_MATHTOOLS_POS_SEMIDEF_UTIL 30 #define _TOMOGRAPHER_MATHTOOLS_POS_SEMIDEF_UTIL 39 #include <Eigen/Eigenvalues> 56 template<
typename VectorType>
61 typedef typename VectorType::Index Index;
64 RealScalar new_excess_trace = 0;
67 for (k = 0; k < vec.size(); ++k) {
69 if (vec(k) < tolerance) {
70 new_excess_trace += tolerance - vec(k);
78 RealScalar remove_from_each = new_excess_trace / num_pos;
79 for (k = 0; k < vec.size(); ++k) {
80 if (vec(k) < tolerance) {
83 vec(k) -= remove_from_each;
95 template<
typename MatrixType,
typename Der>
102 rho.template cast<typename MatrixType::Scalar>()
107 forcePosVecKeepSum<RealVectorType>(d, tolerance);
109 return U * d.asDiagonal() * U.adjoint();
120 template<
typename MatrixType>
131 forcePosVecKeepSum<RealVectorType>(d, tolerance);
133 return U * d.cwiseSqrt().asDiagonal() * U.adjoint();
144 template<
typename MatrixType>
155 forcePosVecKeepSum<RealVectorType>(d, tolerance);
157 for (
typename MatrixType::Index k = 0; k < d.size(); ++k) {
158 if (d(k) > tolerance) {
163 return U * d.asDiagonal() * U.adjoint();
Base namespace for the Tomographer project.
const RealVectorType & eigenvalues() const
Some C++ utilities, with a tad of C++11 tricks.
internal::plain_col_type< MatrixType, RealScalar >::type RealVectorType
const MatrixType & eigenvectors() const
#define tomographer_assert(...)
Assertion test macro.