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

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


2009/6/24 Tim Hutt <tdhutt@xxxxxxxxx>:
> 2009/6/24 Benoit Jacob <jacob.benoit.1@xxxxxxxxx>:
>> 2009/6/24 Markus Benjamin Fröb <grey_earl@xxxxxx>:
>>>>     Matrix<float,Dynamic,2> m;
>>>>     m.resize(3);
>>>>
>>>> but then we also want this to work:
>>>>
>>>>     Matrix<float,3,2> m;
>>>>     m.resize(3);
>>>
>>> I don't see why the second case should work, since a) it's ambigous what the
>>> user wanted and b) in the documentation it says explicitly "Of course, fixed-
>>> size matrices can't be resized."
>>
>> Yes, that's what I meant, sorry if I was unclear, we were wondering if
>> A should be allowed and I said "if we want to allow A then we also
>> want to allow B", where B is impossible, conclusion: we can't allow A.
>
> I see what you mean. You're saying if you have code like this:
>
> Matrix<double, Dynamic, 3> m;
> // ... lots of code ...
> m.resize(10, 3);
>
> And then for some reason later you want to make m fully dynamic then
> you only have to change the declaration:
>
> Matrix<double, Dynamic, Dynamic> m;
> // ... lots of code ...
> m.resize(10, 3); // Still works.
>
> In which case the trade-off is:
>
> Pros: Constructor and resize are more logical, code is less redundant.
> The code shows that the matrix isn't fully dynamic (i.e. you might
> accidentally try m.resize(10, 4) in the code above.
> Cons: Have to change code if you change matrices from partially to
> fully dynamic.

What you say makes sense but what I really had in mind (if you want to
know) is the case where we have code written for partially-dynamic
matrices and some day we want to use it on fixed-size matrices. This
is where the distinction between AT_MOST_ONE_DYNAMIC_DIM and
EXACTLY_ONE_DYNAMIC_DIM matters, and this is the example that I had in
mind when I said that even EXACTLY_ONE_DYNAMIC_DIM didn't cut it.

So suppose that we had allowed resize(int) on partially dynamic matrices, like:

int x = 4;
Matrix<double, Dynamic, 3> m;
// ... lots of code ...
m.resize(x);

And then some day we want to apply this to a fixed-size matrix m
(because we happen to fully know its size at compile time, and we want
to take advantage of this for better speed) then we would like to only
have to change the declaration, as follows, but unfortunately there's
no sane way to allow resize(int) in that case:

int x = 4;
Matrix<double, 4, 3> m;
// ... lots of code ...
m.resize(4); // BOOM! doesn't work.

Thus, in order to get an API that seamlessly specializes in the
fixed-size case, we can't allow resize(int) for partially dynamic
matrices.

Benoit



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