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++) {
53 for(
size_t c_in=0,c_out=0;c_in<ncols; c_in++)
57 c_in=c_in+(how_many-1);
60 ret[r][c_out]=(in)[r][c_in];
70 size_t nrows = in.
rows();
71 size_t ncols = in.
cols();
73 for (
size_t c = 0; c < ncols; c++) {
74 for(
size_t r_in=0, r_out=0; r_in<nrows; r_in++)
78 r_in=r_in+(how_many-1);
81 ret[r_out][c]=(in)[r_in][c];
92 const double *i=in.
data()+in.
cols()*r1+c1;
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++)
101 for(
size_t c=0;c<=(c2-c1);c++)
116 bool ok = connection.
expectBlock((
char*)&header,
sizeof(header));
124 if ( r != (
size_t)(header.
rows) || c!=(
size_t)(header.
cols))
131 for (l = 0; l < header.
listLen; l++) {
155 connection.
appendBlock((
char*)&header,
sizeof(header));
158 const double *tmp=
data();
159 for (l = 0; l < header.
listLen; l++) {
174 std::string spacer((width<0) ?
"\t" :
" ");
177 std::string
ret =
"";
179 const double* src = (*this).data();
184 for (r = 0; r < nrows; r++) {
185 if (r) {
ret += endRowStr; }
186 for (c = 0; c < ncols; c++) {
187 if (c) {
ret += spacer; }
188 sprintf(
buffer,
"% *.*lf", width, precision, *src); src++;
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) {
267 if (new_r == nrows && new_c == ncols) {
271 auto* new_storage=
new double[new_r*new_c];
273 const size_t copy_r=(new_r<nrows) ? new_r:nrows;
274 const size_t copy_c=(new_c<ncols) ? new_c:ncols;
277 if (storage!=
nullptr)
279 double *tmp_new=new_storage;
280 double *tmp_current=storage;
285 const int stepN=(new_c-copy_c);
286 const int stepC=(ncols-copy_c);
288 for(
int r=0; r<copy_r;r++)
290 for(
int c=0;c<copy_c;c++)
291 *tmp_new++=*tmp_current++;
293 tmp_current=matrix[r];
298 for(
size_t r=0; r<copy_r;r++)
300 tmp_current=matrix[r];
301 memcpy(tmp_new, tmp_current,
sizeof(
double)*copy_c);
311 memset(new_storage, 0,
sizeof(
double)*new_r*new_c);
325 memset(storage, 0,
sizeof(
double)*ncols*nrows);
331 ret.resize(nrows, ncols-how_many);
333 for (
size_t r = 0; r < nrows; r++) {
334 for(
size_t c_in=0,c_out=0;c_in<ncols; c_in++)
338 c_in=c_in+(how_many-1);
341 ret[r][c_out]=(*this)[r][c_in];
352 storage=
new double[ncols*nrows];
353 memcpy(storage,
ret.storage, ncols*nrows*
sizeof(
double));
361 ret.resize(nrows-how_many, ncols);
363 for (
size_t c = 0; c < ncols; c++) {
364 for(
size_t r_in=0, r_out=0; r_in<nrows; r_in++)
368 r_in=r_in+(how_many-1);
371 ret[r_out][c]=(*this)[r_in][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];
495 const double *tmp1=
data();
496 const double *tmp2=r.
data();
498 if (tmp1 ==
nullptr || tmp2 ==
nullptr) {
505 if (*tmp1++ != *tmp2++) {
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
An interface for reading from a network connection.
virtual bool expectBlock(char *data, size_t len)=0
Read a block of data from the network connection.
virtual bool convertTextMode()=0
Reads in a standard description in text mode, and converts it to a standard description in binary.
virtual yarp::conf::float64_t expectFloat64()=0
Read a 64-bit floating point number from the network connection.
An interface for writing to a network connection.
virtual bool convertTextMode()=0
Converts a standard description in binary into a textual description, if the connection is in text-mo...
virtual void appendFloat64(yarp::conf::float64_t data)=0
Send a representation of a 64-bit floating point number to the network connection.
virtual void appendBlock(const char *data, size_t len)=0
Send a block of data to the 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.
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.
bool read(ImageOf< PixelRgb > &dest, const std::string &src, image_fileformat format=FORMAT_ANY)
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.