59 setDense(0, 0, value);
70 vector< DMatrix > foo(nCols,
DMatrix());
71 for (
unsigned row = 0;
row < nRows; ++
row)
72 elements.push_back( foo );
74 vector< SubBlockMatrixType > bar(nCols,
SBMT_ZERO);
75 for (
unsigned row = 0;
row < nRows; ++
row)
76 types.push_back( bar );
90 for( i=0; i < getNumRows(); i++ ){
91 for( j=0; j < getNumCols(); j++ ){
95 tmp.
types [i][j] = types [i][j];
96 tmp.
elements [i][j] = elements [i][j];
102 tmp.
elements [i][j] += elements [i][j];
118 for( i = 0; i < getNumRows(); i++ ){
119 for( j = 0; j < getNumCols(); j++ ){
123 types [i][j] = arg.
types [i][j];
124 elements [i][j] = arg.
elements [i][j];
130 elements [i][j] += arg.
elements [i][j];
147 for( i=0; i < getNumRows(); i++ ){
148 for( j=0; j < getNumCols(); j++ ){
152 tmp.
types [i][j] = types [i][j];
153 tmp.
elements [i][j] = elements [i][j];
180 for( i=0; i < getNumRows(); i++ ){
181 for( j=0; j < getNumCols(); j++ ){
184 elements[i][j] *= scalar ;
198 uint newNumRows = getNumRows( );
202 for( i=0; i<newNumRows; ++i ){
203 for( k=0; k<getNumCols( ); ++k ){
205 switch( types[i][k] ){
209 for( j=0; j<newNumCols; ++j ){
221 result.
elements[i][j] += elements[i][k];
222 else result.
elements[i][j] = elements[i][k];
233 for( j=0; j<newNumCols; ++j ){
247 result.
elements[i][j] = elements[i][k];
251 result.
elements[i][j] += elements[i][k];
278 uint newNumRows = getNumCols( );
282 for( i=0; i<newNumRows; ++i ){
283 for( k=0; k<getNumRows( ); ++k ){
285 switch( types[k][i] ){
289 for( j=0; j<newNumCols; ++j ){
294 else result.
elements[i][j] = elements[k][i].transpose() * arg.
elements[k][j];
299 result.
elements[i][j] += elements[k][i].transpose();
300 else result.
elements[i][j] = elements[k][i].transpose();
311 for( j=0; j<newNumCols; ++j ){
323 result.
elements[i][j] = elements[k][i];
327 result.
elements[i][j] += elements[k][i];
352 for( i = 0; i < getNumRows(); i++ ){
353 for( j = 0; j < getNumCols(); j++ ){
354 result.
elements[j][i] = elements[i][j].transpose();
355 result.
types [j][i] = types [i][j] ;
368 for( run1 = 0; run1 < nRows; run1++ ){
369 for( run2 = 0; run2 < nCols; run2++ ){
372 result.
setIdentity( run1, run2, elements[run1][run2].getNumRows() );
375 result.
setDense( run1, run2, elements[run1][run2].absolute() );
388 for( run1 = 0; run1 < nRows; run1++ ){
389 for( run2 = 0; run2 < nCols; run2++ ){
392 result.
setIdentity( run1, run2, elements[run1][run2].getNumRows() );
395 result.
setDense( run1, run2, elements[run1][run2].positive() );
408 for( run1 = 0; run1 < nRows; run1++ ){
409 for( run2 = 0; run2 < nCols; run2++ ){
412 result.
setDense( run1, run2, elements[run1][run2].negative() );
422 stream <<
"Printing Block DMatrix:" << endl << endl;
424 for (
unsigned i = 0; i < getNumRows(); ++i)
426 stream <<
"Row " << i << endl;
427 for (
unsigned j = 0; j < getNumCols(); ++j)
431 if( types[i][j] ==
SBMT_DENSE ) stream << elements[i][j] << endl;
432 if( types[i][j] ==
SBMT_ONE ) stream <<
"ONE " << endl;
433 if( types[i][j] ==
SBMT_ZERO ) stream <<
"ZERO " << endl;
436 stream <<
"ZERO " << endl;
439 stream << endl << endl;
448 ASSERT( rowIdx < getNumRows( ) );
449 ASSERT( colIdx < getNumCols( ) );
451 elements[rowIdx][colIdx] = value ;
460 ASSERT( rowIdx < getNumRows( ) );
461 ASSERT( colIdx < getNumCols( ) );
465 elements[rowIdx][colIdx] += value;
469 return setDense( rowIdx, colIdx, value );
477 ASSERT( rowIdx < getNumRows( ) );
478 ASSERT( colIdx < getNumCols( ) );
481 if( types[rowIdx][colIdx] !=
SBMT_ZERO ){
483 ASSERT( nR == elements[rowIdx][colIdx].getNumRows( ) );
484 ASSERT( nC == elements[rowIdx][colIdx].getNumCols( ) );
486 value = elements[rowIdx][colIdx];
Implements a very rudimentary block sparse matrix class.
returnValue print(std::ostream &stream=std::cout) const
BlockMatrix transpose() const
returnValue setDense(uint rowIdx, uint colIdx, const DMatrix &value)
Allows to pass back messages to the calling function.
BlockMatrix operator^(const BlockMatrix &arg) const
BlockMatrix getAbsolute() const
BEGIN_NAMESPACE_ACADO typedef unsigned int uint
BlockMatrix operator+(const BlockMatrix &arg) const
#define CLOSE_NAMESPACE_ACADO
BlockMatrix getNegative() const
GenericMatrix< double > DMatrix
BlockMatrix operator-(const BlockMatrix &arg) const
returnValue getSubBlock(uint rowIdx, uint colIdx, DMatrix &value) const
std::vector< std::vector< SubBlockMatrixType > > types
EIGEN_STRONG_INLINE void resize(Index nbRows, Index nbCols)
returnValue init(uint _nRows, uint _nCols)
BlockMatrix & operator+=(const BlockMatrix &arg)
Derived & setZero(Index size)
BlockMatrix getPositive() const
BlockMatrix operator*(const BlockMatrix &arg) const
BlockMatrix operator*=(double scalar)
#define BEGIN_NAMESPACE_ACADO
returnValue setIdentity(uint rowIdx, uint colIdx, uint dim)
void init(int nV, int nC, SymmetricMatrix *H, real_t *g, Matrix *A, const real_t *const lb, const real_t *const ub, const real_t *const lbA, const real_t *const ubA, int nWSR, const real_t *const x0, Options *options, int nOutputs, mxArray *plhs[])
returnValue addDense(uint rowIdx, uint colIdx, const DMatrix &value)
std::vector< std::vector< DMatrix > > elements