#include <yarp/sig/Matrix.h>
Public Member Functions | |
Matrix () | |
Matrix (size_t r, size_t c) | |
Matrix (const Matrix &m) | |
Copy constructor. More... | |
~Matrix () | |
Destructor. More... | |
const Matrix & | operator= (const Matrix &r) |
Copy operator. More... | |
const Matrix & | operator= (double v) |
Set all elements of the matrix to a given value. More... | |
size_t | rows () const |
Return number of rows. More... | |
size_t | cols () const |
Return number of columns. More... | |
void | resize (size_t r, size_t c) |
Resize the matrix, if matrix is not empty preserve old content. More... | |
double * | operator[] (size_t r) |
Single element access, no range check. More... | |
const double * | operator[] (size_t r) const |
Single element access, no range check (const version). More... | |
const double & | operator() (size_t r, size_t c) const |
Single element access, no range check. More... | |
double & | operator() (size_t r, size_t c) |
Single element access, no range check. More... | |
void | zero () |
Zero the matrix. More... | |
bool | setRow (size_t row, const Vector &r) |
Set a row of the matrix copying the values from a vector: the vector length must be equal to the number of columns of the matrix. More... | |
bool | setCol (size_t col, const Vector &c) |
Set a column of the matrix copying the values from a vector: the vector length must be equal to the number of rows of the matrix. More... | |
Matrix | transposed () const |
Return the transposed of the matrix. More... | |
const Matrix & | eye () |
Build an identity matrix, don't resize. More... | |
const Matrix & | diagonal (const Vector &d) |
Build a diagonal matrix, don't resize. More... | |
Matrix | submatrix (size_t r1, size_t r2, size_t c1, size_t c2) const |
Extract a submatrix from (r1,c1) to (r2,c2) (extremes included), as in Matlab B=A(r1:r2, c1:c2). More... | |
bool | setSubmatrix (const Matrix &m, size_t r, size_t c) |
Set a portion of this matrix with the values of the specified matrix m. More... | |
bool | setSubrow (const Vector &v, size_t r, size_t c) |
Set a portion of a row of this matrix with the values of the specified vector v. More... | |
bool | setSubcol (const Vector &v, size_t r, size_t c) |
Set a portion of a column of this matrix with the values of the specified vector v. More... | |
Vector | getRow (size_t r) const |
Get a row of the matrix as a vector. More... | |
Vector | getCol (size_t c) const |
Get a columns of the matrix as a vector. More... | |
Matrix | removeCols (size_t first_col, size_t how_many) |
Modifies the matrix, removing one or more columns from it. More... | |
Matrix | removeRows (size_t first_row, size_t how_many) |
Modifies the matrix, removing one or more rows from it. More... | |
Vector | subrow (size_t r, size_t c, size_t size) const |
Get a subrow of the matrix as a vector. More... | |
Vector | subcol (size_t r, size_t c, size_t size) const |
Get a subcolumn of the matrix as a vector. More... | |
std::string | toString (int precision=-1, int width=-1, const char *endRowStr="\n") const |
Print matrix to a string. More... | |
double * | data () |
Return a pointer to the first element. More... | |
const double * | data () const |
Return a pointer to the first element (const version). More... | |
bool | operator== (const yarp::sig::Matrix &r) const |
True iff all elements of a match all element of b. More... | |
bool | read (yarp::os::ConnectionReader &connection) override |
Read this object from a network connection. More... | |
bool | write (yarp::os::ConnectionWriter &connection) const override |
Write vector to a connection. More... | |
Public Member Functions inherited from yarp::os::Portable | |
virtual Type | getType () const |
Public Member Functions inherited from yarp::os::PortReader | |
virtual | ~PortReader () |
Destructor. More... | |
virtual Type | getReadType () const |
Public Member Functions inherited from yarp::os::PortWriter | |
virtual | ~PortWriter () |
Destructor. More... | |
virtual void | onCompletion () const |
This is called when the port has finished all writing operations. More... | |
virtual void | onCommencement () const |
This is called when the port is about to begin writing operations. More... | |
virtual yarp::os::Type | getWriteType () const |
Additional Inherited Members | |
Static Public Member Functions inherited from yarp::os::Portable | |
static bool | copyPortable (const PortWriter &writer, PortReader &reader) |
Copy one portable to another, via writing and reading. More... | |
A class for a Matrix.
A Matrix can be sent/read to/from a port. Use the [] operator to access the r row of the matrix. The function returns a pointer so [][] access the r,c element in the matrix.
Matrix::Matrix | ( | size_t | r, |
size_t | c | ||
) |
Definition at line 534 of file Matrix.cpp.
Matrix::Matrix | ( | const Matrix & | m | ) |
Copy constructor.
Definition at line 545 of file Matrix.cpp.
Matrix::~Matrix | ( | ) |
Destructor.
Definition at line 242 of file Matrix.cpp.
|
inline |
|
inline |
|
inline |
Build a diagonal matrix, don't resize.
Definition at line 443 of file Matrix.cpp.
const Matrix & Matrix::eye | ( | ) |
Build an identity matrix, don't resize.
Definition at line 429 of file Matrix.cpp.
Vector Matrix::getCol | ( | size_t | c | ) | const |
Get a columns of the matrix as a vector.
c | the column number |
Definition at line 392 of file Matrix.cpp.
Vector Matrix::getRow | ( | size_t | r | ) | const |
Get a row of the matrix as a vector.
r | the row number |
Definition at line 381 of file Matrix.cpp.
|
inline |
|
inline |
Copy operator.
Definition at line 207 of file Matrix.cpp.
const Matrix & Matrix::operator= | ( | double | v | ) |
Set all elements of the matrix to a given value.
v | a scalar |
Definition at line 233 of file Matrix.cpp.
bool Matrix::operator== | ( | const yarp::sig::Matrix & | r | ) | const |
True iff all elements of a match all element of b.
Definition at line 457 of file Matrix.cpp.
|
inline |
|
inline |
|
overridevirtual |
Read this object from a network connection.
Override this for your particular class.
reader | an interface to the network connection for reading |
Implements yarp::os::Portable.
Definition at line 112 of file Matrix.cpp.
Matrix Matrix::removeCols | ( | size_t | first_col, |
size_t | how_many | ||
) |
Modifies the matrix, removing one or more columns from it.
first_col | the number of the first column to remove |
how_many | the number of columns to remove |
Definition at line 313 of file Matrix.cpp.
Matrix Matrix::removeRows | ( | size_t | first_row, |
size_t | how_many | ||
) |
Modifies the matrix, removing one or more rows from it.
first_row | the number of the first row to remove |
how_many | the number of rows to remove |
Definition at line 341 of file Matrix.cpp.
void Matrix::resize | ( | size_t | r, |
size_t | c | ||
) |
Resize the matrix, if matrix is not empty preserve old content.
r | number of rows |
c | number of columns |
Definition at line 251 of file Matrix.cpp.
|
inline |
bool Matrix::setCol | ( | size_t | col, |
const Vector & | c | ||
) |
Set a column of the matrix copying the values from a vector: the vector length must be equal to the number of rows of the matrix.
col | the column number |
c | a vector which contains the desired values for the column |
Definition at line 490 of file Matrix.cpp.
bool Matrix::setRow | ( | size_t | row, |
const Vector & | r | ||
) |
Set a row of the matrix copying the values from a vector: the vector length must be equal to the number of columns of the matrix.
row | the row number |
r | vector which contains the desired values for the row |
Definition at line 479 of file Matrix.cpp.
bool Matrix::setSubcol | ( | const Vector & | v, |
size_t | r, | ||
size_t | c | ||
) |
Set a portion of a column of this matrix with the values of the specified vector v.
The portion to be set is from row r to row r+v.size()-1.
v | vector containing the values to set |
r | start row index |
c | index of the column to set |
Definition at line 523 of file Matrix.cpp.
bool Matrix::setSubmatrix | ( | const Matrix & | m, |
size_t | r, | ||
size_t | c | ||
) |
Set a portion of this matrix with the values of the specified matrix m.
The portion to be set is from row r to row r+m.rows()-1 and from column c to column c+m.cols()-1.
m | matrix containing the values to set |
r | start row |
c | start column |
Definition at line 501 of file Matrix.cpp.
bool Matrix::setSubrow | ( | const Vector & | v, |
size_t | r, | ||
size_t | c | ||
) |
Set a portion of a row of this matrix with the values of the specified vector v.
The portion to be set is from column c to column c+v.size()-1.
v | vector containing the values to set |
r | index of the row to set |
c | start column |
Definition at line 512 of file Matrix.cpp.
Vector Matrix::subcol | ( | size_t | r, |
size_t | c, | ||
size_t | size | ||
) | const |
Get a subcolumn of the matrix as a vector.
r | the first row number |
c | the column number |
size | the size of the subcolumn |
Definition at line 416 of file Matrix.cpp.
|
inline |
Vector Matrix::subrow | ( | size_t | r, |
size_t | c, | ||
size_t | size | ||
) | const |
Get a subrow of the matrix as a vector.
r | the row number |
c | the first column number |
size | the size of the subrow |
Definition at line 403 of file Matrix.cpp.
std::string Matrix::toString | ( | int | precision = -1 , |
int | width = -1 , |
||
const char * | endRowStr = "\n" |
||
) | const |
Print matrix to a string.
Useful for display, writing to text. To get a nice format the optional parameters precision and width may be used (same meaning as in printf and cout).
precision | the number of digits to be printed after the decimal point. |
width | minimum number of characters to be printed. If the value to be printed is shorter than this number, the result is padded with blank spaces. The value is never truncated. |
endRowStr | string appended at the end of every row, except for the last one. If width is specified the inter-value separator is a blank space, otherwise it is a tab. Warning: the string format might change in the future. This method is here to ease debugging. |
Definition at line 167 of file Matrix.cpp.
Matrix Matrix::transposed | ( | ) | const |
Return the transposed of the matrix.
Definition at line 369 of file Matrix.cpp.
|
overridevirtual |
Write vector to a connection.
return true iff a vector was written correctly
Implements yarp::os::Portable.
Definition at line 139 of file Matrix.cpp.
void Matrix::zero | ( | ) |