Re: [eigen] How to resize a partially fixed matrix |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/eigen Archives
]
- To: eigen@xxxxxxxxxxxxxxxxxxx
- Subject: Re: [eigen] How to resize a partially fixed matrix
- From: Tim Hutt <tdhutt@xxxxxxxxx>
- Date: Wed, 24 Jun 2009 17:21:25 +0100
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :from:date:message-id:subject:to:content-type :content-transfer-encoding; bh=Fd80HxZ5QkeAcNQIm+Ms074ey29q7n4bKP8MlWeGk8k=; b=X39aG5GCbvU+YTdUwG/x/m1alsZZFo3DDVJiXti0N6u/0+Nx3RFp61iUksAPftZvlx R8menMNH5ezToAANFNJ5Br7accf4/HexTRptVSkpSOFZ8QQCibYrzOmGUxZ0jrf3QL4B pLT7K8FWSi+pvVncaB6T1ZjyZAz0ApuH8E9GA=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type:content-transfer-encoding; b=lp65apHXcdD0KmsNsv4++rxiDq6dab0lKPHT+Sx0Ozj8HUmjXtHZ2nMaVP0bqgWzjP C6vf9ROFjfC4UgnVf/EdOE8/4blcGwwCNRdLFhwYEnb32M7Wb+0vAxSnd837yWnqXNfx EoYhwyOJicJ6Qc2RXjr89kicEm1B3eEZgoPFU=
> 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:
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