| Re: [eigen] How to resize a partially fixed matrix | 
[ Thread Index | Date Index | More lists.tuxfamily.org/eigen Archives ]
Tim Hutt a écrit :
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/ |