Re: [eigen] Maximum size at compile time

[ Thread Index | Date Index | More Archives ]

Hi Joseph,

we have the same issue in our lab, and each time I start a new project I kick myself for not pushing this feature during the Eigen3 beta.
The use of Map is not really satisfactory and error prone. Most critically, there is no workaround for matrix decompositions, for which there will be reallocation whenever the size of the matrix changes.
Basically, there would be a need of a memory management mode in which a reallocation occurs only if the new buffer needs to be bigger than the current one. For now, the size of the buffer is supposed to be row()*cols(), so we would need an additional integer to keep track of the buffer size separately from the matrix size, which would break the ABI.

Joris Vaillant began to tackle the problem a few years ago, but the PR has never been completely finished:
Maybe we could try to put it back on rail.


On Thu, May 17, 2018 at 6:57 PM, Joseph Mirabel <joseph.mirabel@xxxxxxx> wrote:
Hi Eigen developers,

I have used Eigen for a few years now and I am still amazed by this
library. Thanks a lot for it !

In parts of the code where time is critical, I would like to avoid
dynamic allocation. The matrix size is not know at compile time (and
unbounded). However, at run-time, and outside of these critical regions,
it is possible to know the maximum size of most matrices. Thus, it is
possible to dynamically allocate enough memory in non-critical regions
and use only the necessary part of this allocated memory in critical
regions (thus with no reallocation). I know this can be done with class
Map at the cost of a less readable code. I believe this can also be done
with class Matrix itself, without too much effort. I could not find any
record on the topic. I thus have two questions:

- Is my belief (it would not be too hard to add a run-time maximum size
in class Matrix) correct ?
A (naive ?) approach is to add an option like EnableMaxSizeAtRunTime.
When enabled, a member `max_size` would be added to class `Matrix`.
max_size would always be the allocated size. Then reallocation would be
  * when `Matrix::resize` is called and the requested size is larger
than `max_size`
  * when `Matrix::reserve` (a new method) is called.

- Is this of interest for Eigen ?


Mail converted by MHonArc 2.6.19+