@@ -383,7 +383,7 @@ static void computeJacobianActivated( Task* taskSpec,
383
383
for ( int i=0 ;i<Jt.cols ();++i )
384
384
{
385
385
if (! controlSelec (i) )
386
- {for ( int j= 0 ;j< Jt.rows ();++j ) { Jt (j,i)= 0 .; } }
386
+ { Jt.col (i). setZero (); }
387
387
}
388
388
}
389
389
else
@@ -514,6 +514,7 @@ computeControlLaw( dynamicgraph::Vector& control,const int& iterTime )
514
514
dynamicgraph::Matrix &V = mem->V ;
515
515
dynamicgraph::Matrix &JK = mem->JK ;
516
516
dynamicgraph::Matrix &Jt = mem->Jt ;
517
+ MemoryTaskSOT::SVD_t& svd = mem->svd ;
517
518
518
519
Jp.resize ( mJ ,nJ );
519
520
V.resize ( mJ ,mJ );
@@ -531,22 +532,19 @@ computeControlLaw( dynamicgraph::Vector& control,const int& iterTime )
531
532
sotDEBUG (2 ) <<" Recompute inverse." <<endl;
532
533
533
534
/* --- FIRST ALLOCS --- */
534
- dynamicgraph::Vector &S = mem->S ;
535
-
536
535
sotDEBUG (1 ) << " Size = "
537
- << S. size ( ) + mem->Jff .cols ()*mem->Jff .rows ()
536
+ << std::min (nJ, mJ ) + mem->Jff .cols ()*mem->Jff .rows ()
538
537
+ mem->Jact .cols ()*mem->Jact .rows () << std::endl;
539
538
540
539
sotDEBUG (1 ) << std::endl;
541
- S.resize ( std::min (nJ,mJ ) );
542
540
sotDEBUG (1 ) << " nJ=" << nJ << " " << " Jac.cols()=" << Jac.cols ()
543
541
<<" " << " mJ=" << mJ <<std::endl;
544
542
mem->Jff .resize ( nJ,Jac.cols ()-mJ ); // number dofs, number constraints
545
543
sotDEBUG (1 ) << std::endl;
546
544
mem->Jact .resize ( nJ,mJ );
547
545
sotDEBUG (1 ) << std::endl;
548
546
sotDEBUG (1 ) << " Size = "
549
- << S. size ( ) + mem->Jff .cols ()*mem->Jff .rows ()
547
+ << std::min (nJ, mJ ) + mem->Jff .cols ()*mem->Jff .rows ()
550
548
+ mem->Jact .cols ()*mem->Jact .rows () << std::endl;
551
549
552
550
/* **/ sotCOUNTER (1 ,2 ); // first allocs
@@ -556,22 +554,25 @@ computeControlLaw( dynamicgraph::Vector& control,const int& iterTime )
556
554
/* **/ sotCOUNTER (2 ,3 ); // compute JK
557
555
558
556
/* --- COMPUTE Jt --- */
559
- if ( 0 <iterTask ) Jt = JK*Proj; else { Jt = JK; }
557
+ if ( 0 <iterTask ) Jt. noalias () = JK*Proj; else { Jt = JK; }
560
558
/* **/ sotCOUNTER (3 ,4 ); // compute Jt
561
559
562
560
/* --- COMPUTE S --- */
563
561
computeJacobianActivated ( dynamic_cast <Task*>( &task ),Jt,iterTime );
564
562
/* **/ sotCOUNTER (4 ,5 ); // Jt*S
565
563
566
564
/* --- PINV --- */
567
- Eigen::MatrixXd EMPTY (0 ,0 );
568
- Eigen::dampedInverse (Jt,Jp,EMPTY,S,V,th);
565
+ svd.compute (Jt);
566
+ Eigen::dampedInverse (svd, Jp, th);
567
+ V.noalias () = svd.matrixV ();
569
568
/* **/ sotCOUNTER (5 ,6 ); // PINV
570
569
sotDEBUG (2 ) << " V after dampedInverse." << V <<endl;
571
570
/* --- RANK --- */
572
571
{
573
- const unsigned int Jmax = S.size (); rankJ=0 ;
574
- for ( unsigned i=0 ;i<Jmax;++i ) { if ( S (i)>th ) rankJ++; }
572
+ rankJ = 0 ;
573
+ while ( rankJ < svd.singularValues ().size ()
574
+ && th < svd.singularValues ()[rankJ])
575
+ { ++rankJ; }
575
576
}
576
577
577
578
sotDEBUG (45 ) << " control" <<iterTask<<" = " <<control<<endl;
@@ -582,9 +583,9 @@ computeControlLaw( dynamicgraph::Vector& control,const int& iterTime )
582
583
sotDEBUG (15 ) << " e" <<iterTask<<" = " <<err<<endl;
583
584
sotDEBUG (45 ) << " JJp" <<iterTask<<" = " << JK*Jp <<endl;
584
585
// sotDEBUG(45) << "U"<<iterTask<<" = "<< U<<endl;
585
- sotDEBUG (45 ) << " S" <<iterTask<<" = " << S <<endl;
586
+ sotDEBUG (45 ) << " S" <<iterTask<<" = " << svd. singularValues () <<endl;
586
587
sotDEBUG (45 ) << " V" <<iterTask<<" = " << V<<endl;
587
- sotDEBUG (45 ) << " U" <<iterTask<<" = " << EMPTY <<endl;
588
+ sotDEBUG (45 ) << " U" <<iterTask<<" = " << svd. matrixU () <<endl;
588
589
589
590
mem->jacobianInvSINOUT = Jp;
590
591
mem->jacobianInvSINOUT .setTime ( iterTime );
@@ -612,43 +613,17 @@ computeControlLaw( dynamicgraph::Vector& control,const int& iterTime )
612
613
/* --- COMPUTE QDOT AND P --- */
613
614
/* DEBUG: normally, the first iter (ie the test below)
614
615
* is the same than the other, starting with control_0 = q0SIN. */
615
- if ( iterTask==0 ) control += Jp*err; else
616
- control += Jp*(err - JK*control);
616
+ if ( iterTask==0 ) control. noalias () += Jp*err;
617
+ else control += Jp*(err - JK*control);
617
618
/* **/ sotCOUNTER (7 ,8 ); // QDOT
618
619
619
620
/* --- OPTIMAL FORM: To debug. --- */
620
621
if ( 0 ==iterTask )
621
622
{ Proj.resize ( mJ ,mJ ); Proj.setIdentity (); }
622
623
623
- // {
624
- // double *p,*v1,*v2,*vtmp1,*vtmp2;
625
- // p = traits::matrix_storage(Proj.matrix);
626
- // v1 = traits::matrix_storage(V.matrix);
627
- // v2 = traits::matrix_storage(V.matrix);
628
- // vtmp1 = traits::matrix_storage(V.matrix);
629
- // /***/sotCOUNTER(6,7); // Ppre
630
-
631
- // for( unsigned int i=0;i<mJ;++i )
632
- // {
633
- // vtmp2 = traits::matrix_storage(V.matrix);
634
- // for( unsigned int j=0;j<mJ;++j )
635
- // {
636
- // v1 = vtmp1; v2 = vtmp2;
637
- // for( unsigned int k=0;k<rankJ;++k )
638
- // {
639
- // (*p) -=( *v1) * (*v2);
640
- // v2++;v1++;
641
- // }
642
- // p++; vtmp2 += mJ;
643
- // }
644
- // vtmp1 += mJ;
645
- // /***/sotCOUNTER(7,8); // P
646
- // }
647
- // }
648
- /* NON OPTIMAL FORM: to be replaced after debug. */
649
- // Proj-=Jp*Jt;
650
-
651
624
/* --- OLIVIER START --- */
625
+ // Update by Joseph Mirabel to match Eigen API
626
+
652
627
sotDEBUG (2 ) << " Proj non optimal (rankJ= " <<rankJ
653
628
<< " , iterTask =" << iterTask
654
629
<< " )" ;
@@ -657,36 +632,7 @@ computeControlLaw( dynamicgraph::Vector& control,const int& iterTime )
657
632
sotDEBUG (2 ) << " JpxJt = " << Jp*Jt;
658
633
sotDEBUG (25 ) << " Proj-Jp*Jt" <<iterTask<<" = " << (Proj-Jp*Jt) <<endl;
659
634
660
- /* NON OPTIMAL FORM: to be replaced after debug. */
661
- if (1 )
662
- {
663
- double *p,*v1,*v2,*vtmp1,*vtmp2;
664
- p = MRAWDATA (Proj);
665
- v1 = MRAWDATA (V);
666
- v2 = MRAWDATA (V);
667
- vtmp1 = MRAWDATA (V);
668
- /* **/ sotCOUNTER (6 ,7 ); // Ppre
669
-
670
- for ( int i=0 ;i<mJ ;++i )
671
- {
672
- vtmp2 = MRAWDATA (V);
673
- for ( int j=0 ;j<mJ ;++j )
674
- {
675
- v1 = vtmp1; v2 =vtmp2;
676
- for (unsigned int k=0 ;k<rankJ;++k )
677
- // for( unsigned int k=0;k<mJ;++k )
678
- {
679
- (*p) -=( *v1) * (*v2);
680
- v2+=mJ ;v1+=mJ ;
681
- }
682
- p++; vtmp2 ++;
683
- }
684
- vtmp1++;
685
- }
686
- /* **/ sotCOUNTER (7 ,8 ); // P
687
- }
688
- else
689
- { Proj-=Jp*Jt;}
635
+ Proj.noalias () -= svd.matrixV ().leftCols (rankJ) * svd.matrixV ().leftCols (rankJ).adjoint ();
690
636
691
637
/* --- OLIVIER END --- */
692
638
@@ -727,6 +673,7 @@ computeControlLaw( dynamicgraph::Vector& control,const int& iterTime )
727
673
dynamicgraph::Matrix &Jp = mem->Jp ;
728
674
dynamicgraph::Matrix &PJp = mem->PJp ;
729
675
dynamicgraph::Matrix &Jt = mem->Jt ;
676
+ MemoryTaskSOT::SVD_t& svd = mem->svd ;
730
677
731
678
mem->JK .resize ( nJ,mJ );
732
679
mem->Jt .resize ( nJ,mJ );
@@ -743,18 +690,17 @@ computeControlLaw( dynamicgraph::Vector& control,const int& iterTime )
743
690
sotDEBUG (35 ) << " Jgrad = " << JK <<endl;
744
691
745
692
// Use optimized-memory Jt to do the p-inverse.
746
- Jt=JK; Eigen::dampedInverse ( Jt, Jp,th );
747
- PJp = Proj*Jp;
693
+ Jt=JK;
694
+ svd.compute (Jt);
695
+ // TODO the two next lines could be replaced by
696
+ Eigen::dampedInverse ( svd, Jp,th );
697
+ PJp.noalias () = Proj*Jp;
748
698
749
699
/* --- COMPUTE ERR --- */
750
- dynamicgraph::Vector Herr ( err.size () );
751
- for ( int i=0 ;i<err.size (); ++i )
752
- {
753
- Herr (i) = err (i);
754
- }
700
+ const dynamicgraph::Vector& Herr ( err );
755
701
756
702
/* --- COMPUTE CONTROL --- */
757
- control += PJp*Herr;
703
+ control. noalias () += PJp*Herr;
758
704
759
705
/* --- TRACE --- */
760
706
sotDEBUG (45 ) << " Pgrad = " << (PJp*Herr) <<endl;
0 commit comments