Skip to content

Commit bcc721b

Browse files
committed
Avoid some dynamic allocation.
1 parent eaf7c67 commit bcc721b

File tree

5 files changed

+20
-13
lines changed

5 files changed

+20
-13
lines changed

include/sot/core/memory-task-sot.hh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ namespace dynamicgraph {
3838
{
3939
public:// protected:
4040
/* Internal memory to reduce the dynamic allocation at task resolution. */
41+
dg::Vector err;
4142
dg::Matrix Jt; //( nJ,mJ );
4243
dg::Matrix Jp;
4344
dg::Matrix PJp;

include/sot/core/sot.hh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,8 @@ namespace dynamicgraph {
136136
dg::Matrix& Jact );
137137
static dg::Matrix & computeJacobianConstrained( const TaskAbstract& task,
138138
const dg::Matrix& K );
139-
static dg::Vector
140-
taskVectorToMlVector(const VectorMultiBound& taskVector);
139+
static void
140+
taskVectorToMlVector(const VectorMultiBound& taskVector, Vector& err);
141141

142142
public:
143143

src/sot/sot-qr.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,8 @@ computeControlLaw( dynamicgraph::Vector& control,const int& iterTime )
674674
{
675675
TaskAbstract & task = **(stack.begin());
676676
const dynamicgraph::Matrix &Jac = task.jacobianSOUT(iterTime);
677-
const dynamicgraph::Vector err = Sot::taskVectorToMlVector(task.taskSOUT(iterTime));
677+
const dynamicgraph::Vector err;
678+
Sot::taskVectorToMlVector(task.taskSOUT(iterTime), err);
678679
const unsigned int mJ = Jac.rows();
679680
/***/sotCOUNTER(0,1); // Direct Dynamic
680681

@@ -765,7 +766,8 @@ computeControlLaw( dynamicgraph::Vector& control,const int& iterTime )
765766

766767
TaskAbstract & task = **iter;
767768
const dynamicgraph::Matrix &Jac = task.jacobianSOUT(iterTime);
768-
const dynamicgraph::Vector err = Sot::taskVectorToMlVector(task.taskSOUT(iterTime));
769+
const dynamicgraph::Vector err;
770+
Sot::taskVectorToMlVector(task.taskSOUT(iterTime), err);
769771
const unsigned int mJ = Jac.rows();
770772
/***/sotCOUNTER(0,1); // Direct Dynamic
771773

@@ -875,7 +877,8 @@ computeControlLaw( dynamicgraph::Vector& control,const int& iterTime )
875877
TaskAbstract & task = **iter;
876878
MemoryTaskSOT * mem = dynamic_cast<MemoryTaskSOT *>( task.memoryInternal );
877879
const dynamicgraph::Matrix &Jac = mem->JK;
878-
const dynamicgraph::Vector &err = Sot::taskVectorToMlVector(task.taskSOUT.accessCopy());
880+
const dynamicgraph::Vector err;
881+
Sot::taskVectorToMlVector(task.taskSOUT.accessCopy(), err);
879882

880883
dynamicgraph::Vector diffErr(err.size());
881884
diffErr = Jac*control;

src/sot/sot.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -446,17 +446,16 @@ static void computeJacobianActivated( Task* taskSpec,
446446
# define sotPRINTCOUNTER(nbc1)
447447
#endif // #ifdef WITH_CHRONO
448448

449-
dynamicgraph::Vector Sot::
450-
taskVectorToMlVector( const VectorMultiBound& taskVector )
449+
void Sot::
450+
taskVectorToMlVector( const VectorMultiBound& taskVector, Vector& res )
451451
{
452-
dynamicgraph::Vector res(taskVector.size()); res.setZero();
452+
res.resize(taskVector.size());
453453
unsigned int i=0;
454454

455455
for( VectorMultiBound::const_iterator iter=taskVector.begin();
456456
iter!=taskVector.end();++iter,++i ) {
457457
res(i)=iter->getSingleBound();
458458
}
459-
return res;
460459
}
461460

462461
dynamicgraph::Vector& Sot::
@@ -495,7 +494,6 @@ computeControlLaw( dynamicgraph::Vector& control,const int& iterTime )
495494
TaskAbstract & task = **iter;
496495
sotDEBUG(15) << "Task: e_" << task.getName() << std::endl;
497496
const dynamicgraph::Matrix &Jac = task.jacobianSOUT(iterTime);
498-
const dynamicgraph::Vector err = taskVectorToMlVector(task.taskSOUT(iterTime));
499497
sotCOUNTER(0,1); // Direct Dynamic
500498

501499
unsigned int rankJ;
@@ -516,6 +514,9 @@ computeControlLaw( dynamicgraph::Vector& control,const int& iterTime )
516514
dynamicgraph::Matrix &Jt = mem->Jt;
517515
MemoryTaskSOT::SVD_t& svd = mem->svd;
518516

517+
taskVectorToMlVector(task.taskSOUT(iterTime), mem->err);
518+
const dynamicgraph::Vector &err = mem->err;
519+
519520
Jp.resize( mJ,nJ );
520521
V.resize( mJ,mJ );
521522
Jt.resize( nJ,mJ );
@@ -650,8 +651,6 @@ computeControlLaw( dynamicgraph::Vector& control,const int& iterTime )
650651

651652
if( 0!=taskGradient )
652653
{
653-
const dynamicgraph::Vector err
654-
= taskVectorToMlVector(taskGradient->taskSOUT.access(iterTime));
655654
const dynamicgraph::Matrix & Jac = taskGradient->jacobianSOUT.access(iterTime);
656655

657656
const unsigned int nJ = Jac.rows();
@@ -666,6 +665,9 @@ computeControlLaw( dynamicgraph::Vector& control,const int& iterTime )
666665
taskGradient->memoryInternal = mem;
667666
}
668667

668+
taskVectorToMlVector(taskGradient->taskSOUT.access(iterTime), mem->err);
669+
const dynamicgraph::Vector& err = mem->err;
670+
669671
sotDEBUG(45) << "K = " << K <<endl;
670672
sotDEBUG(45) << "Jff = " << Jac <<endl;
671673

src/sot/weighted-sot.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,8 @@ computeWeightedControlLaw( dynamicgraph::Vector& control,const int& iterTime )
285285
sotDEBUGF(5,"Rank %d.",iterTask);
286286
TaskAbstract & task = **iter;
287287
const dynamicgraph::Matrix &JacRO = task.jacobianSOUT(iterTime);
288-
const dynamicgraph::Vector err = Sot::taskVectorToMlVector(task.taskSOUT(iterTime));
288+
const dynamicgraph::Vector err;
289+
Sot::taskVectorToMlVector(task.taskSOUT(iterTime), err);
289290
const unsigned int nJ = JacRO.rows();
290291
sotCOUNTER(0b,1); // Direct Dynamic
291292

0 commit comments

Comments
 (0)