qpOASES 3.2.1
An Implementation of the Online Active Set Strategy
Public Member Functions | Protected Attributes | List of all members
DenseMatrix Class Reference

Interfaces matrix-vector operations tailored to general dense matrices. More...

#include <Matrices.hpp>

Inheritance diagram for DenseMatrix:
Matrix SymDenseMat

Public Member Functions

 DenseMatrix ()
 
 DenseMatrix (int_t m, int_t n, int_t lD, real_t *v)
 
virtual ~DenseMatrix ()
 
virtual void free ()
 
virtual Matrixduplicate () const
 
virtual real_t diag (int_t i) const
 
virtual BooleanType isDiag () const
 
virtual real_t getNorm (int_t type=2) const
 
virtual real_t getRowNorm (int_t rNum, int_t type=2) const
 
virtual returnValue getRowNorm (real_t *norm, int_t type=2) const
 
virtual returnValue getRow (int_t rNum, const Indexlist *const icols, real_t alpha, real_t *row) const
 
virtual returnValue getCol (int_t cNum, const Indexlist *const irows, real_t alpha, real_t *col) const
 
virtual returnValue getSparseSubmatrix (int_t irowsLength, const int_t *const irowsNumber, int_t icolsLength, const int_t *const icolsNumber, int_t rowoffset, int_t coloffset, int_t &numNonzeros, int_t *irn, int_t *jcn, real_t *avals, BooleanType only_lower_triangular=BT_FALSE) const
 
virtual returnValue times (int_t xN, real_t alpha, const real_t *x, int_t xLD, real_t beta, real_t *y, int_t yLD) const
 
virtual returnValue transTimes (int_t xN, real_t alpha, const real_t *x, int_t xLD, real_t beta, real_t *y, int_t yLD) const
 
virtual returnValue times (const Indexlist *const irows, const Indexlist *const icols, int_t xN, real_t alpha, const real_t *x, int_t xLD, real_t beta, real_t *y, int_t yLD, BooleanType yCompr=BT_TRUE) const
 
virtual returnValue transTimes (const Indexlist *const irows, const Indexlist *const icols, int_t xN, real_t alpha, const real_t *x, int_t xLD, real_t beta, real_t *y, int_t yLD) const
 
virtual returnValue addToDiag (real_t alpha)
 
virtual real_tfull () const
 
virtual returnValue print (const char *name=0) const
 
virtual returnValue writeToFile (FILE *output_file, const char *prefix) const
 
virtual returnValue getSparseSubmatrix (const Indexlist *const irows, const Indexlist *const icols, int_t rowoffset, int_t coloffset, int_t &numNonzeros, int_t *irn, int_t *jcn, real_t *avals, BooleanType only_lower_triangular=BT_FALSE) const
 
virtual returnValue getSparseSubmatrix (const Indexlist *const irows, int_t idx_icol, int_t rowoffset, int_t coloffset, int_t &numNonzeros, int_t *irn, int_t *jcn, real_t *avals, BooleanType only_lower_triangular=BT_FALSE) const
 
virtual returnValue getSparseSubmatrix (int_t idx_row, const Indexlist *const icols, int_t rowoffset, int_t coloffset, int_t &numNonzeros, int_t *irn, int_t *jcn, real_t *avals, BooleanType only_lower_triangular=BT_FALSE) const
 
BooleanType needToFreeMemory () const
 
void doFreeMemory ()
 
void doNotFreeMemory ()
 

Protected Attributes

int_t nRows
 
int_t nCols
 
int_t leaDim
 
real_tval
 
BooleanType freeMemory
 

Detailed Description

Dense matrix class (row major format).

Author
Andreas Potschka, Christian Kirches, Hans Joachim Ferreau
Version
3.2
Date
2011-2017

Constructor & Destructor Documentation

◆ DenseMatrix() [1/2]

DenseMatrix::DenseMatrix ( )
inline

Default constructor.

Referenced by duplicate().

◆ DenseMatrix() [2/2]

DenseMatrix::DenseMatrix ( int_t  m,
int_t  n,
int_t  lD,
real_t v 
)
inline

Constructor from vector of values. Caution: Data pointer must be valid throughout lifetime

Parameters
mNumber of rows.
nNumber of columns.
lDLeading dimension.
vValues.

◆ ~DenseMatrix()

DenseMatrix::~DenseMatrix ( )
virtual

Destructor.

References BT_TRUE, free(), and Matrix::needToFreeMemory().

Member Function Documentation

◆ addToDiag()

returnValue DenseMatrix::addToDiag ( real_t  alpha)
virtual

Adds given offset to diagonal of matrix.

Returns
SUCCESSFUL_RETURN
RET_NO_DIAGONAL_AVAILABLE
Parameters
alphaDiagonal offset.

Implements Matrix.

References leaDim, nCols, nRows, SUCCESSFUL_RETURN, and val.

◆ diag()

real_t DenseMatrix::diag ( int_t  i) const
virtual

Returns i-th diagonal entry.

Returns
i-th diagonal entry
Parameters
iIndex.

Implements Matrix.

References leaDim, and val.

◆ doFreeMemory()

void Matrix::doFreeMemory ( )
inlineinherited

◆ doNotFreeMemory()

void Matrix::doNotFreeMemory ( )
inlineinherited

◆ duplicate()

Matrix * DenseMatrix::duplicate ( ) const
virtual

Returns a deep-copy of the Matrix object.

Returns
Deep-copy of Matrix object

Implements Matrix.

Reimplemented in SymDenseMat.

References BT_TRUE, DenseMatrix(), Matrix::doFreeMemory(), nCols, Matrix::needToFreeMemory(), nRows, real_t, and val.

◆ free()

void DenseMatrix::free ( )
virtual

Frees all internal memory.

Implements Matrix.

References val.

Referenced by ~DenseMatrix().

◆ full()

real_t * DenseMatrix::full ( ) const
virtual

Allocates and creates dense matrix array in row major format.

Note: Calling function has to free allocated memory!

Returns
Pointer to matrix array.

Implements Matrix.

References nCols, nRows, real_t, and val.

◆ getCol()

returnValue DenseMatrix::getCol ( int_t  cNum,
const Indexlist *const  irows,
real_t  alpha,
real_t col 
) const
virtual

Retrieve indexed entries of matrix column multiplied by alpha.

Returns
SUCCESSFUL_RETURN
Parameters
cNumColumn number.
irowsIndex list specifying rows.
alphaScalar factor.
colOutput column vector.

Implements Matrix.

References BT_TRUE, isEqual(), leaDim, Indexlist::length, Indexlist::number, SUCCESSFUL_RETURN, and val.

◆ getNorm()

real_t DenseMatrix::getNorm ( int_t  type = 2) const
virtual

Get the N-norm of the matrix

Returns
N-norm of the matrix
Parameters
typeNorm type, 1: one-norm, 2: Euclidean norm.

Implements Matrix.

References getNorm(), nCols, nRows, REFER_NAMESPACE_QPOASES, and val.

Referenced by getNorm(), and getRowNorm().

◆ getRow()

returnValue DenseMatrix::getRow ( int_t  rNum,
const Indexlist *const  icols,
real_t  alpha,
real_t row 
) const
virtual

Retrieve indexed entries of matrix row multiplied by alpha.

Returns
SUCCESSFUL_RETURN
Parameters
rNumRow number.
icolsIndex list specifying columns.
alphaScalar factor.
rowOutput row vector.

Implements Matrix.

References BT_TRUE, isEqual(), leaDim, Indexlist::length, nCols, Indexlist::number, SUCCESSFUL_RETURN, and val.

◆ getRowNorm() [1/2]

real_t DenseMatrix::getRowNorm ( int_t  rNum,
int_t  type = 2 
) const
virtual

Get the N-norm of a row

Returns
N-norm of row rNum
Parameters
rNumRow number.
typeNorm type, 1: one-norm, 2: Euclidean norm.

Implements Matrix.

References getNorm(), leaDim, nCols, REFER_NAMESPACE_QPOASES, and val.

◆ getRowNorm() [2/2]

returnValue DenseMatrix::getRowNorm ( real_t norm,
int_t  type = 2 
) const
virtual

Get the N-norm of all rows

Returns
SUCCESSFUL_RETURN
Parameters
normNorm of each row.
typeNorm type, 1: one-norm, 2: Euclidean norm.

Implements Matrix.

References getNorm(), leaDim, nCols, nRows, REFER_NAMESPACE_QPOASES, SUCCESSFUL_RETURN, and val.

◆ getSparseSubmatrix() [1/4]

BEGIN_NAMESPACE_QPOASES returnValue Matrix::getSparseSubmatrix ( const Indexlist *const  irows,
const Indexlist *const  icols,
int_t  rowoffset,
int_t  coloffset,
int_t numNonzeros,
int_t irn,
int_t jcn,
real_t avals,
BooleanType  only_lower_triangular = BT_FALSE 
) const
virtualinherited

Retrieve entries of submatrix in Harwell-Boeing sparse format. If irn, jcn, and avals are null, this only counts the number of nonzeros. Otherwise, numNonzeros containts the size of irn, jcn, and avals on entry, and the written number of entries on return.

Returns
SUCCESSFUL_RETURN
Parameters
irowsIndex list specifying rows.
icolsIndex list specifying columns.
rowoffsetOffset for row entries.
coloffsetOffset for row entries.
numNonzerosNumber of nonzeros in submatrix.
irnRow position of entries (as position in irows) plus rowoffset.
jcnColumn position of entries (as position in irows) plus coloffset.
avalsNumerical values of the entries.
only_lower_triangularif true, only the lower triangular portion is returned. This can only be true for symmetric matrices and if irows==jcols.

References Indexlist::getLength(), Indexlist::getNumberArray(), and Matrix::getSparseSubmatrix().

Referenced by SQProblemSchur::addConstraint(), Matrix::getSparseSubmatrix(), SQProblemSchur::removeBound(), and SQProblemSchur::resetSchurComplement().

◆ getSparseSubmatrix() [2/4]

returnValue Matrix::getSparseSubmatrix ( const Indexlist *const  irows,
int_t  idx_icol,
int_t  rowoffset,
int_t  coloffset,
int_t numNonzeros,
int_t irn,
int_t jcn,
real_t avals,
BooleanType  only_lower_triangular = BT_FALSE 
) const
virtualinherited

Retrieve entries of submatrix in Harwell-Boeing sparse format. If irn, jcn, and avals are null, this only counts the number of nonzeros. Otherwise, numNonzeros containts the size of irn, jcn, and avals on entry, and the written number of entries on return. This version retrieves one column.

Returns
SUCCESSFUL_RETURN
Parameters
irowsIndex list specifying rows.
idx_icolIndex list specifying columns.
rowoffsetOffset for row entries.
coloffsetOffset for row entries.
numNonzerosNumber of nonzeros in submatrix.
irnRow position of entries (as position in irows) plus rowoffset.
jcnColumn position of entries (as position in irows) plus coloffset.
avalsNumerical values of the entries.
only_lower_triangularif true, only the lower triangular portion is returned. This can only be true for symmetric matrices and if irows==jcols.

References Indexlist::getLength(), Indexlist::getNumberArray(), and Matrix::getSparseSubmatrix().

◆ getSparseSubmatrix() [3/4]

returnValue Matrix::getSparseSubmatrix ( int_t  idx_row,
const Indexlist *const  icols,
int_t  rowoffset,
int_t  coloffset,
int_t numNonzeros,
int_t irn,
int_t jcn,
real_t avals,
BooleanType  only_lower_triangular = BT_FALSE 
) const
virtualinherited

Retrieve entries of submatrix in Harwell-Boeing sparse format. If irn, jcn, and avals are null, this only counts the number of nonzeros. Otherwise, numNonzeros containts the size of irn, jcn, and avals on entry, and the written number of entries on return. This version retrieves one row.

Returns
SUCCESSFUL_RETURN
Parameters
idx_rowRow number.
icolsIndex list specifying columns.
rowoffsetOffset for row entries.
coloffsetOffset for row entries.
numNonzerosNumber of nonzeros in submatrix.
irnRow position of entries (as position in irows) plus rowoffset.
jcnColumn position of entries (as position in irows) plus coloffset.
avalsNumerical values of the entries.
only_lower_triangularif true, only the lower triangular portion is returned. This can only be true for symmetric matrices and if irows==jcols.

References Indexlist::getLength(), Indexlist::getNumberArray(), and Matrix::getSparseSubmatrix().

◆ getSparseSubmatrix() [4/4]

returnValue DenseMatrix::getSparseSubmatrix ( int_t  irowsLength,
const int_t *const  irowsNumber,
int_t  icolsLength,
const int_t *const  icolsNumber,
int_t  rowoffset,
int_t  coloffset,
int_t numNonzeros,
int_t irn,
int_t jcn,
real_t avals,
BooleanType  only_lower_triangular = BT_FALSE 
) const
virtual

Retrieve entries of submatrix in Harwell-Boeing sparse format. If irn, jcn, and avals are null, this only counts the number of nonzeros. Otherwise, numNonzeros containts the size of irn, jcn, and avals on entry, and the written number of entries on return.

Returns
SUCCESSFUL_RETURN
Parameters
irowsLengthNumber of rows.
irowsNumberArray with row numbers.
icolsLengthNumber of columns.
icolsNumberArray with column numbers.
rowoffsetOffset for row entries.
coloffsetOffset for row entries.
numNonzerosNumber of nonzeros in submatrix.
irnRow position of entries (as position in irows) plus rowoffset.
jcnColumn position of entries (as position in irows) plus coloffset.
avalsNumerical values of the entries.
only_lower_triangularif true, only the lower triangular portion is returned. This can only be true for symmetric matrices and if irows==jcols.

Implements Matrix.

References BT_FALSE, isZero(), leaDim, real_t, RET_INVALID_ARGUMENTS, SUCCESSFUL_RETURN, THROWERROR, and val.

◆ isDiag()

BooleanType DenseMatrix::isDiag ( ) const
virtual

Checks whether matrix is square and diagonal.

Returns
BT_TRUE iff matrix is square and diagonal;
BT_FALSE otherwise.

Implements Matrix.

References BT_FALSE, BT_TRUE, EPS, getAbs(), leaDim, nCols, nRows, and val.

◆ needToFreeMemory()

BooleanType Matrix::needToFreeMemory ( ) const
inlineinherited

Returns whether internal memory needs to be de-allocated.

Returns
BT_TRUE iff internal memory needs to be de-allocated,
BT_FALSE otherwise

References Matrix::freeMemory.

Referenced by duplicate(), SymDenseMat::duplicateSym(), ~DenseMatrix(), SparseMatrix::~SparseMatrix(), and SparseMatrixRow::~SparseMatrixRow().

◆ print()

returnValue DenseMatrix::print ( const char *  name = 0) const
virtual

Prints matrix to screen.

Returns
SUCCESSFUL_RETURN
Parameters
nameName of matrix.

Implements Matrix.

References nCols, nRows, print(), REFER_NAMESPACE_QPOASES, and val.

Referenced by print().

◆ times() [1/2]

returnValue DenseMatrix::times ( const Indexlist *const  irows,
const Indexlist *const  icols,
int_t  xN,
real_t  alpha,
const real_t x,
int_t  xLD,
real_t  beta,
real_t y,
int_t  yLD,
BooleanType  yCompr = BT_TRUE 
) const
virtual

Evaluate matrix vector product with submatrix given by Indexlist.

Returns
SUCCESSFUL_RETURN
Parameters
irowsIndex list specifying rows.
icolsIndex list specifying columns.
xNNumber of vectors to multiply.
alphaScalar factor for matrix vector product.
xInput vector to be multiplied.
xLDLeading dimension of input x.
betaScalar factor for y.
yOutput vector of results.
yLDLeading dimension of output y.
yComprCompressed storage for y.

Implements Matrix.

References BT_FALSE, BT_TRUE, isEqual(), Indexlist::iSort, isZero(), leaDim, Indexlist::length, nCols, Indexlist::number, SUCCESSFUL_RETURN, and val.

◆ times() [2/2]

returnValue DenseMatrix::times ( int_t  xN,
real_t  alpha,
const real_t x,
int_t  xLD,
real_t  beta,
real_t y,
int_t  yLD 
) const
virtual

Evaluate Y=alpha*A*X + beta*Y.

Returns
SUCCESSFUL_RETURN.
Parameters
xNNumber of vectors to multiply.
alphaScalar factor for matrix vector product.
xInput vector to be multiplied.
xLDLeading dimension of input x.
betaScalar factor for y.
yOutput vector of results.
yLDLeading dimension of output y.

Implements Matrix.

References GEMM, getMax(), nCols, nRows, SUCCESSFUL_RETURN, and val.

◆ transTimes() [1/2]

returnValue DenseMatrix::transTimes ( const Indexlist *const  irows,
const Indexlist *const  icols,
int_t  xN,
real_t  alpha,
const real_t x,
int_t  xLD,
real_t  beta,
real_t y,
int_t  yLD 
) const
virtual

Evaluate matrix transpose vector product.

Returns
SUCCESSFUL_RETURN
Parameters
irowsIndex list specifying rows.
icolsIndex list specifying columns.
xNNumber of vectors to multiply.
alphaScalar factor for matrix vector product.
xInput vector to be multiplied.
xLDLeading dimension of input x.
betaScalar factor for y.
yOutput vector of results.
yLDLeading dimension of output y.

Implements Matrix.

References BT_FALSE, BT_TRUE, isEqual(), Indexlist::iSort, isZero(), leaDim, Indexlist::length, Indexlist::number, SUCCESSFUL_RETURN, and val.

◆ transTimes() [2/2]

returnValue DenseMatrix::transTimes ( int_t  xN,
real_t  alpha,
const real_t x,
int_t  xLD,
real_t  beta,
real_t y,
int_t  yLD 
) const
virtual

Evaluate Y=alpha*A'*X + beta*Y.

Returns
SUCCESSFUL_RETURN.
Parameters
xNNumber of vectors to multiply.
alphaScalar factor for matrix vector product.
xInput vector to be multiplied.
xLDLeading dimension of input x.
betaScalar factor for y.
yOutput vector of results.
yLDLeading dimension of output y.

Implements Matrix.

References GEMM, getMax(), nCols, nRows, SUCCESSFUL_RETURN, and val.

◆ writeToFile()

returnValue DenseMatrix::writeToFile ( FILE *  output_file,
const char *  prefix 
) const
virtual

Write matrix to file.

Returns
SUCCESSFUL_RETURN

Implements Matrix.

References RET_NOT_YET_IMPLEMENTED, and THROWERROR.

Member Data Documentation

◆ freeMemory

BooleanType Matrix::freeMemory
protectedinherited

Indicating whether internal memory needs to be de-allocated.

Referenced by Matrix::doFreeMemory(), Matrix::doNotFreeMemory(), and Matrix::needToFreeMemory().

◆ leaDim

int_t DenseMatrix::leaDim
protected

◆ nCols

int_t DenseMatrix::nCols
protected

◆ nRows

int_t DenseMatrix::nRows
protected

◆ val

real_t* DenseMatrix::val
protected

The documentation for this class was generated from the following files: