Skip to content

Commit 222ceef

Browse files
committed
Improve memory usage when computing SVD in SOT entity
1 parent 4a24591 commit 222ceef

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

src/sot/sot.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,7 @@ computeControlLaw( dynamicgraph::Vector& control,const int& iterTime )
514514
dynamicgraph::Matrix &V = mem->V;
515515
dynamicgraph::Matrix &JK = mem->JK;
516516
dynamicgraph::Matrix &Jt = mem->Jt;
517+
MemoryTaskSOT::SVD_t& svd = mem->svd;
517518

518519
Jp.resize( mJ,nJ );
519520
V.resize( mJ,mJ );
@@ -564,14 +565,20 @@ computeControlLaw( dynamicgraph::Vector& control,const int& iterTime )
564565
/***/sotCOUNTER(4,5); // Jt*S
565566

566567
/* --- PINV --- */
567-
Eigen::MatrixXd EMPTY(0,0);
568-
Eigen::dampedInverse(Jt,Jp,EMPTY,S,V,th);
568+
svd.compute (Jt);
569+
Eigen::dampedInverse (svd, Jp, th);
570+
V.noalias() = svd.matrixV();
571+
// TODO I think variable S could be removed as it is not used when
572+
// not recomputing the pseudo inverse.
573+
S.noalias() = svd.singularValues();
569574
/***/sotCOUNTER(5,6); // PINV
570575
sotDEBUG(2) << "V after dampedInverse." << V <<endl;
571576
/* --- RANK --- */
572577
{
573-
const unsigned int Jmax = S.size(); rankJ=0;
574-
for( unsigned i=0;i<Jmax;++i ) { if( S(i)>th ) rankJ++; }
578+
rankJ = 0;
579+
while ( rankJ < svd.singularValues().size()
580+
&& th < svd.singularValues()[rankJ])
581+
{ ++rankJ; }
575582
}
576583

577584
sotDEBUG(45) << "control"<<iterTask<<" = "<<control<<endl;
@@ -584,7 +591,7 @@ computeControlLaw( dynamicgraph::Vector& control,const int& iterTime )
584591
//sotDEBUG(45) << "U"<<iterTask<<" = "<< U<<endl;
585592
sotDEBUG(45) << "S"<<iterTask<<" = "<< S<<endl;
586593
sotDEBUG(45) << "V"<<iterTask<<" = "<< V<<endl;
587-
sotDEBUG(45) << "U"<<iterTask<<" = "<< EMPTY<<endl;
594+
sotDEBUG(45) << "U"<<iterTask<<" = "<< svd.matrixU()<<endl;
588595

589596
mem->jacobianInvSINOUT = Jp;
590597
mem->jacobianInvSINOUT.setTime( iterTime );

0 commit comments

Comments
 (0)