31 #ifndef SVD_EIGEN_MACIE 32 #define SVD_EIGEN_MACIE 35 using namespace Eigen;
60 MatrixXd& B, VectorXd& tempi,
61 double threshold,
bool toggle)
64 unsigned int sweeps=0;
65 unsigned int rotations=0;
73 for(
unsigned int i=0;i<B.cols();i++){
74 for(
unsigned int j=i+1;j<B.cols();j++){
76 double p = B.col(i).dot(B.col(j));
77 double qi =B.col(i).dot(B.col(i));
78 double qj = B.col(j).dot(B.col(j));
80 double alpha =
pow(p,2.0)/(qi*qj);
89 cos=
sqrt((c+q)/(2*c));
93 sin=-
sqrt((c-q)/(2*c));
95 sin=
sqrt((c-q)/(2*c));
100 tempi = cos*B.col(i) + sin*B.col(j);
101 B.col(j) = - sin*B.col(i) + cos*B.col(j);
105 tempi.head(V.rows()) = cos*V.col(i) + sin*V.col(j);
106 V.col(j) = - sin*V.col(i) + cos*V.col(j);
107 V.col(i) = tempi.head(V.rows());
114 for(
unsigned int i=0;i<U.rows();i++) {
116 double si=
sqrt(B.col(i).dot(B.col(i)));
120 U.col(i) = B.col(i)/si;
132 B = U.transpose().lazyProduct(A);
137 for(
unsigned int i=0;i<B.cols();i++){
138 for(
unsigned int j=i+1;j<B.cols();j++){
140 double p = B.row(i).dot(B.row(j));
141 double qi = B.row(i).dot(B.row(i));
142 double qj = B.row(j).dot(B.row(j));
145 double alpha =
pow(p,2.0)/(qi*qj);
155 cos=
sqrt((c+q)/(2*c));
159 sin=-
sqrt((c-q)/(2*c));
161 sin=
sqrt((c-q)/(2*c));
166 tempi.head(B.cols()) = cos*B.row(i) + sin*B.row(j);
167 B.row(j) = - sin*B.row(i) + cos*B.row(j);
168 B.row(i) = tempi.head(B.cols());
172 tempi.head(U.rows()) = cos*U.col(i) + sin*U.col(j);
173 U.col(j) = - sin*U.col(i) + cos*U.col(j);
174 U.col(i) = tempi.head(U.rows());
182 for(
unsigned int i=0;i<V.rows();i++) {
183 double si=
sqrt(B.row(i).dot(B.row(i)));
187 V.col(i) = B.row(i)/si;
int svd_eigen_Macie(const MatrixXd &A, MatrixXd &U, VectorXd &S, MatrixXd &V, MatrixXd &B, VectorXd &tempi, double threshold, bool toggle)
INLINE Rall1d< T, V, S > sqrt(const Rall1d< T, V, S > &arg)
INLINE Rall1d< T, V, S > pow(const Rall1d< T, V, S > &arg, double m)
INLINE Rall1d< T, V, S > cos(const Rall1d< T, V, S > &arg)
INLINE Rall1d< T, V, S > sin(const Rall1d< T, V, S > &arg)