25#define RES(v) ((std::vector<T> *)v)
49 size_t nrows = in.
rows();
50 size_t ncols = in.
cols();
52 for (
size_t r = 0; r < nrows; r++) {
70 size_t nrows = in.
rows();
71 size_t ncols = in.
cols();
73 for (
size_t c = 0;
c < ncols;
c++) {
93 const int offset=in.
cols()-(
c2-
c1+1);
95 if (
i ==
nullptr ||
t ==
nullptr) {
99 for(
size_t r=0;r<=(
r2-
r1);r++)
116 bool ok =
connection.expectBlock((
char*)&header,
sizeof(header));
124 if ( r != (
size_t)(header.
rows) ||
c!=(
size_t)(header.
cols))
155 connection.appendBlock((
char*)&header,
sizeof(header));
174 std::string
spacer((width<0) ?
"\t" :
" ");
177 std::string
ret =
"";
179 const double* src = (*this).data();
184 for (r = 0; r < nrows; r++) {
186 for (
c = 0;
c < ncols;
c++) {
197void Matrix::updatePointers()
199 if (matrix !=
nullptr) {
204 matrix=
new double* [nrows];
208 for(r=1;r<nrows; r++)
210 matrix[r]=matrix[r-1]+ncols;
220 if(nrows!=r.nrows || ncols!=r.ncols)
229 storage=
new double[ncols*nrows];
230 memcpy(storage, r.storage, ncols*nrows*
sizeof(
double));
236 storage =
new double[ncols * nrows];
238 memcpy(storage, r.storage, ncols*nrows*
sizeof(
double));
246 size_t nelem = nrows*ncols;
247 for (
size_t k = 0;
k <
nelem;
k++) {
256 if (matrix !=
nullptr) {
260 if (storage !=
nullptr) {
277 if (storage!=
nullptr)
288 for(
int r=0; r<
copy_r;r++)
298 for(
size_t r=0; r<
copy_r;r++)
325 memset(storage, 0,
sizeof(
double)*ncols*nrows);
333 for (
size_t r = 0; r < nrows; r++) {
352 storage=
new double[ncols*nrows];
353 memcpy(storage,
ret.storage, ncols*nrows*
sizeof(
double));
363 for (
size_t c = 0;
c < ncols;
c++) {
382 storage=
new double[ncols*nrows];
383 memcpy(storage,
ret.storage, ncols*nrows*
sizeof(
double));
391 ret.resize(ncols, nrows);
393 for (
size_t r = 0; r < nrows; r++) {
394 for (
size_t c = 0;
c < ncols;
c++) {
395 ret[
c][r] = (*this)[r][
c];
407 for (
size_t c = 0;
c < ncols;
c++) {
408 ret[
c] = (*this)[r][
c];
419 for (
size_t r = 0; r < nrows; r++) {
420 ret[r] = (*this)[r][
c];
428 if (r >=
rows() ||
c + size - 1 >=
cols()) {
434 for (
size_t i = 0;
i < size;
i++) {
435 ret[
i] = (*this)[r][
c +
i];
443 if (r + size - 1 >=
rows() ||
c >=
cols()) {
449 for (
size_t i = 0;
i < size;
i++) {
450 ret[
i] = (*this)[r +
i][
c];
465 for (
size_t r = 0; r <
tmpR; r++,
c++) {
481 for (
size_t r = 0; r <
tmpR; r++,
c++) {
482 (*this)[r][
c] =
d[r];
498 if (
tmp1 ==
nullptr ||
tmp2 ==
nullptr) {
515 if ((
row >= nrows) || (r.
length() != ncols)) {
519 for (
size_t c = 0;
c < ncols;
c++) {
520 (*this)[
row][
c] = r[
c];
528 if ((
col >= ncols) || (
c.length() != nrows)) {
532 for (
size_t r = 0; r < nrows; r++) {
533 (*this)[r][
col] =
c[r];
541 if ((
c +
m.cols() > ncols) || (r +
m.rows() > nrows)) {
545 for (
size_t i = 0;
i <
m.rows();
i++) {
546 for (
size_t j = 0;
j <
m.cols();
j++) {
547 (*this)[r +
i][
c +
j] =
m(
i,
j);
556 if (r >= nrows ||
c + s - 1 >= (
size_t)ncols) {
560 for (
size_t i = 0;
i < s;
i++) {
561 (*this)[r][
i +
c] = v[
i];
569 if (r + s - 1 >= (
size_t)nrows ||
c >= ncols) {
573 for (
size_t i = 0;
i < s;
i++) {
574 (*this)[r +
i][
c] = v[
i];
585 storage=
new double [r*
c];
586 memset(storage, 0, r*
c*
sizeof(
double));
597 if (
m.storage!=
nullptr)
599 storage=
new double [nrows*ncols];
600 memcpy(storage,
m.storage, nrows*ncols*
sizeof(
double));
#define BOTTLE_TAG_FLOAT64
contains the definition of a Matrix type
contains the definition of a Vector type
A mini-server for performing network communication in the background.
An interface for reading from a network connection.
An interface for writing to a network connection.
This is a base class for objects that can be both read from and be written to the YARP network.
Matrix removeRows(size_t first_row, size_t how_many)
Modifies the matrix, removing one or more rows from it.
void zero()
Zero the matrix.
Vector getRow(size_t r) const
Get a row of the matrix as a vector.
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
Vector subcol(size_t r, size_t c, size_t size) const
Get a subcolumn of the matrix as a vector.
void resize(size_t r, size_t c)
Resize the matrix, if matrix is not empty preserve old content.
bool operator==(const yarp::sig::Matrix &r) const
True iff all elements of a match all element of b.
Matrix transposed() const
Return the transposed 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 n...
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.
const Matrix & diagonal(const Vector &d)
Build a diagonal matrix, don't resize.
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 numb...
size_t cols() const
Return number of columns.
Vector getCol(size_t c) const
Get a columns of the matrix as a vector.
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.
double * data()
Return a pointer to the first element.
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.
bool write(yarp::os::ConnectionWriter &connection) const override
Write vector to a connection.
const Matrix & operator=(const Matrix &r)
Copy operator.
size_t rows() const
Return number of rows.
Vector subrow(size_t r, size_t c, size_t size) const
Get a subrow 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.
std::string toString(int precision=-1, int width=-1, const char *endRowStr="\n") const
Print matrix to a string.
const Matrix & eye()
Build an identity matrix, don't resize.
size_t length() const
Get the length of the vector.
An interface to the operating system, including Port based communication.
std::int32_t NetInt32
Definition of the NetInt32 type.
VectorOf< double > Vector
bool removeRows(const Matrix &in, Matrix &out, size_t first_row, size_t how_many)
bool submatrix(const Matrix &in, Matrix &out, size_t r1, size_t r2, size_t c1, size_t c2)
bool removeCols(const Matrix &in, Matrix &out, size_t first_col, size_t how_many)
The main, catch-all namespace for YARP.
#define YARP_END_PACK
Ends 1 byte packing for structs/classes.
#define YARP_BEGIN_PACK
Starts 1 byte packing for structs/classes.