28 #ifndef POS_SEMIDEF_UTIL
29 #define POS_SEMIDEF_UTIL
38 #include <Eigen/Eigenvalues>
53 template<
typename VectorType>
58 typedef typename VectorType::Index Index;
61 RealScalar new_excess_trace = 0;
64 for (k = 0; k < vec.size(); ++k) {
66 if (vec(k) < tolerance) {
67 new_excess_trace += tolerance - vec(k);
73 eigen_assert(trace >= vec.size()*tolerance);
75 RealScalar remove_from_each = new_excess_trace / num_pos;
76 for (k = 0; k < vec.size(); ++k) {
77 if (vec(k) < tolerance) {
80 vec(k) -= remove_from_each;
92 template<
typename MatrixType,
typename Der>
99 rho.template cast<typename MatrixType::Scalar>()
104 force_pos_vec_keepsum<RealVectorType>(d, tolerance);
106 return U * d.asDiagonal() * U.adjoint();
117 template<
typename MatrixType>
128 force_pos_vec_keepsum<RealVectorType>(d, tolerance);
130 return U * d.cwiseSqrt().asDiagonal() * U.adjoint();
141 template<
typename MatrixType>
152 force_pos_vec_keepsum<RealVectorType>(d, tolerance);
154 for (
typename MatrixType::Index k = 0; k < d.size(); ++k) {
155 if (d(k) > tolerance) {
160 return U * d.asDiagonal() * U.adjoint();
Base namespace for the Tomographer project.
const RealVectorType & eigenvalues() const
internal::plain_col_type< MatrixType, RealScalar >::type RealVectorType
const MatrixType & eigenvectors() const