#include <yarp/sig/Matrix.h>
Public Member Functions | |
Matrix () | |
Matrix (size_t r, size_t c) | |
Matrix (const Matrix &m) | |
Copy constructor. | |
~Matrix () | |
Destructor. | |
const Matrix & | operator= (const Matrix &r) |
Copy operator. | |
const Matrix & | operator= (double v) |
Set all elements of the matrix to a given value. | |
size_t | rows () const |
Return number of rows. | |
size_t | cols () const |
Return number of columns. | |
void | resize (size_t r, size_t c) |
Resize the matrix, if matrix is not empty preserve old content. | |
double * | operator[] (size_t r) |
Single element access, no range check. | |
const double * | operator[] (size_t r) const |
Single element access, no range check (const version). | |
const double & | operator() (size_t r, size_t c) const |
Single element access, no range check. | |
double & | operator() (size_t r, size_t c) |
Single element access, no range check. | |
void | zero () |
Zero the matrix. | |
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. | |
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. | |
Matrix | transposed () const |
Return the transposed of the matrix. | |
const Matrix & | eye () |
Build an identity matrix, don't resize. | |
const Matrix & | diagonal (const Vector &d) |
Build a diagonal matrix, don't resize. | |
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). | |
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. | |
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. | |
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. | |
Vector | getRow (size_t r) const |
Get a row of the matrix as a vector. | |
Vector | getCol (size_t c) const |
Get a columns of the matrix as a vector. | |
Matrix | removeCols (size_t first_col, size_t how_many) |
Modifies the matrix, removing one or more columns from it. | |
Matrix | removeRows (size_t first_row, size_t how_many) |
Modifies the matrix, removing one or more rows from it. | |
Vector | subrow (size_t r, size_t c, size_t size) const |
Get a subrow of the matrix as a vector. | |
Vector | subcol (size_t r, size_t c, size_t size) const |
Get a subcolumn of the matrix as a vector. | |
std::string | toString (int precision=-1, int width=-1, const char *endRowStr="\n") const |
Print matrix to a string. | |
double * | data () |
Return a pointer to the first element. | |
const double * | data () const |
Return a pointer to the first element (const version). | |
bool | operator== (const yarp::sig::Matrix &r) const |
True iff all elements of a match all element of b. | |
bool | read (yarp::os::ConnectionReader &connection) override |
Read this object from a network connection. | |
bool | write (yarp::os::ConnectionWriter &connection) const override |
Write vector to a connection. | |
Public Member Functions inherited from yarp::os::Portable | |
virtual Type | getType () const |
Public Member Functions inherited from yarp::os::PortReader | |
virtual | ~PortReader () |
Destructor. | |
virtual Type | getReadType () const |
Public Member Functions inherited from yarp::os::PortWriter | |
virtual | ~PortWriter () |
Destructor. | |
virtual void | onCompletion () const |
This is called when the port has finished all writing operations. | |
virtual void | onCommencement () const |
This is called when the port is about to begin writing operations. | |
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. | |
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.
Definition at line 579 of file Matrix.cpp.
Copy constructor.
Definition at line 590 of file Matrix.cpp.
Matrix::~Matrix | ( | ) |
Destructor.
Definition at line 254 of file Matrix.cpp.
|
inline |
|
inline |
|
inline |
Build a diagonal matrix, don't resize.
Definition at line 472 of file Matrix.cpp.
Build an identity matrix, don't resize.
Definition at line 456 of file Matrix.cpp.
Get a columns of the matrix as a vector.
c | the column number |
Definition at line 414 of file Matrix.cpp.
Get a row of the matrix as a vector.
r | the row number |
Definition at line 402 of file Matrix.cpp.
Copy operator.
Definition at line 214 of file Matrix.cpp.
Set all elements of the matrix to a given value.
v | a scalar |
Definition at line 244 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 488 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.
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 328 of file Matrix.cpp.
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 358 of file Matrix.cpp.
Resize the matrix, if matrix is not empty preserve old content.
r | number of rows |
c | number of columns |
Definition at line 265 of file Matrix.cpp.
|
inline |
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 526 of file Matrix.cpp.
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 513 of file Matrix.cpp.
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 566 of file Matrix.cpp.
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 539 of file Matrix.cpp.
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 553 of file Matrix.cpp.
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 441 of file Matrix.cpp.
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 426 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 171 of file Matrix.cpp.
Matrix Matrix::transposed | ( | ) | const |
Return the transposed of the matrix.
Definition at line 388 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 142 of file Matrix.cpp.
void Matrix::zero | ( | ) |