Skip to content

Commit 2d50269

Browse files
committed
Clean and optimize Sot::computeControlLaw
1 parent ed450ba commit 2d50269

File tree

1 file changed

+9
-66
lines changed

1 file changed

+9
-66
lines changed

src/sot/sot.cpp

Lines changed: 9 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -627,34 +627,6 @@ computeControlLaw( dynamicgraph::Vector& control,const int& iterTime )
627627
if( 0==iterTask )
628628
{ Proj.resize( mJ,mJ ); Proj.setIdentity(); }
629629

630-
// {
631-
// double *p,*v1,*v2,*vtmp1,*vtmp2;
632-
// p = traits::matrix_storage(Proj.matrix);
633-
// v1 = traits::matrix_storage(V.matrix);
634-
// v2 = traits::matrix_storage(V.matrix);
635-
// vtmp1 = traits::matrix_storage(V.matrix);
636-
// /***/sotCOUNTER(6,7); // Ppre
637-
638-
// for( unsigned int i=0;i<mJ;++i )
639-
// {
640-
// vtmp2 = traits::matrix_storage(V.matrix);
641-
// for( unsigned int j=0;j<mJ;++j )
642-
// {
643-
// v1 = vtmp1; v2 = vtmp2;
644-
// for( unsigned int k=0;k<rankJ;++k )
645-
// {
646-
// (*p) -=( *v1) * (*v2);
647-
// v2++;v1++;
648-
// }
649-
// p++; vtmp2 += mJ;
650-
// }
651-
// vtmp1 += mJ;
652-
// /***/sotCOUNTER(7,8); // P
653-
// }
654-
// }
655-
/* NON OPTIMAL FORM: to be replaced after debug. */
656-
// Proj-=Jp*Jt;
657-
658630
/* --- OLIVIER START --- */
659631
sotDEBUG(2) << "Proj non optimal (rankJ= " <<rankJ
660632
<< ", iterTask =" << iterTask
@@ -664,36 +636,7 @@ computeControlLaw( dynamicgraph::Vector& control,const int& iterTime )
664636
sotDEBUG(2) << "JpxJt = " << Jp*Jt;
665637
sotDEBUG(25) << "Proj-Jp*Jt"<<iterTask<<" = "<< (Proj-Jp*Jt) <<endl;
666638

667-
/* NON OPTIMAL FORM: to be replaced after debug. */
668-
if (1)
669-
{
670-
double *p,*v1,*v2,*vtmp1,*vtmp2;
671-
p = MRAWDATA(Proj);
672-
v1 = MRAWDATA(V);
673-
v2 = MRAWDATA(V);
674-
vtmp1 = MRAWDATA(V);
675-
/***/sotCOUNTER(6,7); // Ppre
676-
677-
for( int i=0;i<mJ;++i )
678-
{
679-
vtmp2 = MRAWDATA(V);
680-
for( int j=0;j<mJ;++j )
681-
{
682-
v1 = vtmp1; v2 =vtmp2;
683-
for(unsigned int k=0;k<rankJ;++k )
684-
//for( unsigned int k=0;k<mJ;++k )
685-
{
686-
(*p) -=( *v1) * (*v2);
687-
v2+=mJ;v1+=mJ;
688-
}
689-
p++; vtmp2 ++;
690-
}
691-
vtmp1++;
692-
}
693-
/***/sotCOUNTER(7,8); // P
694-
}
695-
else
696-
{ Proj-=Jp*Jt;}
639+
Proj.noalias() -= Jp * Jt;
697640

698641
/* --- OLIVIER END --- */
699642

@@ -734,6 +677,7 @@ computeControlLaw( dynamicgraph::Vector& control,const int& iterTime )
734677
dynamicgraph::Matrix &Jp = mem->Jp;
735678
dynamicgraph::Matrix &PJp = mem->PJp;
736679
dynamicgraph::Matrix &Jt = mem->Jt;
680+
MemoryTaskSOT::SVD_t& svd = mem->svd;
737681

738682
mem->JK.resize( nJ,mJ );
739683
mem->Jt.resize( nJ,mJ );
@@ -750,18 +694,17 @@ computeControlLaw( dynamicgraph::Vector& control,const int& iterTime )
750694
sotDEBUG(35) << "Jgrad = " << JK <<endl;
751695

752696
// Use optimized-memory Jt to do the p-inverse.
753-
Jt=JK; Eigen::dampedInverse( Jt, Jp,th );
754-
PJp = Proj*Jp;
697+
Jt=JK;
698+
svd.compute (Jt);
699+
// TODO the two next lines could be replaced by
700+
Eigen::dampedInverse( svd, Jp,th );
701+
PJp.noalias() = Proj*Jp;
755702

756703
/* --- COMPUTE ERR --- */
757-
dynamicgraph::Vector Herr( err.size() );
758-
for( int i=0;i<err.size(); ++i )
759-
{
760-
Herr(i) = err(i);
761-
}
704+
const dynamicgraph::Vector& Herr( err );
762705

763706
/* --- COMPUTE CONTROL --- */
764-
control += PJp*Herr;
707+
control.noalias() += PJp*Herr;
765708

766709
/* --- TRACE --- */
767710
sotDEBUG(45) << "Pgrad = " << (PJp*Herr) <<endl;

0 commit comments

Comments
 (0)