Re: [eigen] How to resize a partially fixed matrix

[ Thread Index | Date Index | More lists.tuxfamily.org/eigen Archives ]


Tim Hutt a écrit :
I tried to do that change and now I think that it's very nontrivial:
not sure anymore that it's a good move!
Here's what makes me change my mind. Look at what happens when you do:

Matrix<float,3,4> m;
m.resize(4);

How to interprete this? Should this be a NOP or a failed assertion?
There are many such issues in Matrix.h alone and I am afraid that any
way to allow that will result in a much more complex Matrix.h and less
consistent API....

Benoit
    
Hmm fair enough. If it really is too hard to change tho API then maybe
good documentation is the best approach. I've made some for you to
copy/paste:
  
How about a new escape constant "NoChange" (or whatever name fits), use that way :
A.resize(NoChange, 7);
Robert
At the end of 'Matrix and vector types' in the tutorial:

-------------
For dynamically sized matrices, where the size of one or both
dimensions is unspecified at compile time use the special value
Eigen::Dynamic. For example, VectorXd is a typedef for

 Matrix<double, Dynamic, 1>

As with statically sized matrices the static dimensions can be any
size. The following are all valid:

Matrix<double, 6, Dynamic> // Dynamic number of columns
Matrix<double, Dynamic, 2> // Dynamic number of rows
Matrix<double, Dynamic, Dynamic> // Fully dynamic
Matrix<double, 13, 3> // Fully static

Partially dynamic matrices use all the same API calls as fully dynamic
matrices, but the fixed dimension must remain constant or an assertion
will fail.

Matrix<double, 2, Dynamic> A; // OK, 2x0 matrix.
Matrix<double, 2, Dynamic> B(3); // Error, wrong constructor.
Matrix<double, 2, Dynamic> C(5, 7); // Error, number of rows is inconsistent.
Matrix<double, 2, Dynamic> D(2, 7); // OK.

The same is true of the resize() function.

A.resize(3); // Error, wrong function.
A.resize(5, 7); // Error, number of rows is inconsistent.
A.resize(2, 7); // OK.
------------

For Matrix::resize(int):
------------
Resizes *this to a vector of length size. This only works for vectors
(Matrix<?, Dynamic, 1> or Matrix<?, 1, Dynamic>). It does not work for
partially dynamic matrices when the static dimension is anything other
than 1. For example it will not work with Matrix<double, 2, Dynamic>.
To resize matrices of this type use resize(int, int).
------------

For Matrix::resize(int, int):
-----------
Makes sense for dynamic- or partially dynamic-size matrices only.

For partially dynamic sized matrices the static dimension must be
(redundantly unfortunately) given. For example:

Matrix<double, Dynamic, 2> A(10, 2); // Create a 10x2 matrix.
A.resize(20, 2); // Expand it to 20x2.
A.resize(10, 3); // This is an error.
----------

For Matrix(int, int):
---------
....default constructor Matrix() instead. For partially dynamic sized
matrices you must pass both the static and dynamic sizes, for example

Matrix<double, Dynamic, 2> A(10, 3); // Error.
Matrix<double, Dynamic, 2> A(10, 2); // OK, Creates a 10x2 matrix.
----------

Even if you change it in future it would be good to add this
documentation. And I've written it all for you so no excuses! :-)

Tim



  


--
Robert Bocquier


ARTURIA
4 chemin de Malacher
38240 Meylan - France
Tel: +33 438 020 555
Fax: +33 438 020 525

http://www.arturia.com



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/