@@ -105,7 +105,24 @@ computeJacobian( dynamicgraph::Matrix& J,int time )
105
105
try {
106
106
int dimJ = J .rows ();
107
107
int nbc = J.cols ();
108
- if ( 0 ==dimJ ){ dimJ = 1 ; J.resize (dimJ,nbc); }
108
+ if ( 0 ==dimJ ) {
109
+ // Compute the correct size
110
+ for ( JacobianList::iterator iter = jacobianList.begin ();
111
+ iter!=jacobianList.end (); ++iter )
112
+ {
113
+ Signal< dynamicgraph::Matrix,int >& jacobian = ** iter;
114
+ const dynamicgraph::Matrix& partialJacobian = jacobian (time );
115
+ dimJ += partialJacobian.rows ();
116
+ if (nbc == 0 )
117
+ nbc = partialJacobian.cols ();
118
+ else if (nbc != partialJacobian.cols ()) {
119
+ SOT_THROW ExceptionTask (ExceptionTask::NON_ADEQUATE_FEATURES,
120
+ " Features from the list don't "
121
+ " have compatible-size jacobians." );
122
+ }
123
+ }
124
+ J.resize (dimJ, nbc);
125
+ }
109
126
110
127
int cursorJ = 0 ;
111
128
@@ -119,23 +136,12 @@ computeJacobian( dynamicgraph::Matrix& J,int time )
119
136
const dynamicgraph::Matrix& partialJacobian = jacobian (time );
120
137
const int nbr = partialJacobian.rows ();
121
138
122
- if ( 0 ==nbc ) { nbc = partialJacobian.cols (); J.conservativeResize (nbc,dimJ); }
123
- else if ( partialJacobian.cols () != nbc )
124
- {SOT_THROW ExceptionTask (ExceptionTask::NON_ADEQUATE_FEATURES,
125
- " Features from the list don't "
126
- " have compatible-size jacobians." );}
127
139
sotDEBUG (25 ) << " Jp =" <<endl<< partialJacobian<<endl;
128
140
129
- while ( cursorJ+nbr>=dimJ )
130
- { dimJ *= 2 ; J.resize (dimJ,nbc); }
131
- for ( int kc=0 ;kc<nbc;++kc )
132
- for ( int k=0 ;k<nbr;++k )
133
- { J (cursorJ+k,kc) = partialJacobian (k,kc); }
141
+ J.middleRows (cursorJ, nbr) = partialJacobian;
134
142
cursorJ += nbr;
135
143
}
136
144
137
- /* If too much memory has been allocated, resize. */
138
- J.conservativeResize (cursorJ,nbc);
139
145
} catch SOT_RETHROW;
140
146
141
147
sotDEBUG (15 ) << " # Out }" << endl;
0 commit comments