Registered Member
|
I know the subject sounds confusing and wired. The problem is that, I have a matrix whose size are only known at run-time. Therefore, I can only use MatrixXd, etc. However, it is known that, once it is created, its size will not change until it is destroyed. That is the matrix shall be allocated dynamically, but its size is fixed during its lifetime.
Is there a way to construct such a matrix? That is, I would like to have a sort of lock mechanism. After the creation of the matrix, I lock its size. And subsequent calls to resize() or assignment that may change the size of matrix shall raise an exception condition or fail an assertion in debug mode, unless it is unlock explicitly. |
Moderator
|
I guess this is for debugging purpose. Then you may try to compile with -DEIGEN_NO_AUTOMATIC_RESIZING, see this page:
http://eigen.tuxfamily.org/dox-devel/To ... tives.html |
Registered Member
|
Thanks for the hint. I actually would like the explicit resize method be disabled. Like a true fixed size matrix that the interface is there but has no effect
|
Moderator
|
Resizing a fixed size object with wrong trigger and assertion, just like this macro does for dynamic objects.
|
Registered Member
|
I think I have not express things, clear. Here is an example
Compile it with EIGEN_NO_AUTOMATIC_RESIZING does not make it an error or failed assertion. I think it must sounds odd why I want to disable this explicit resize(Integer). So here is a little more context. I am writing a library, which has a class that abstract a certain mathematical object. I use an Eigen::Matrix to store some elements. Let's say
I would like the user only be able to resize the matrix through MY resize() method. It will have some other side effects, so merely resize the states_ matrix will not do. One solution is clearly I don't provide user the write access to the whole MatrixXd object at all. Only allows them to manipulate it through wrapper elements accessors. But there is no restriction on what user can do with the values of states_ at all. So for example if the user want to assign to the a column of the matrix with another Eigen::VectorXd, it has either loop through my element accessors, or I provide some wrapper to make the things similar to the following happen
with The only thing that I don't want them to do is resize it, because there are other things in the class must change when the states are resized. |
Moderator
|
OK, at least EIGEN_NO_AUTOMATIC_RESIZING prevents from implicit resizing like:
particle.states_mat() = MatrixXf::Zero(1000,200); Now want you need is to disable resize() for users, but you still need to be able to call it from ParticleCollection. The only way to do it is to add a new class, let's call it StaticMatrix, inheriting Eigen::Matrix<>. In this class you only have to declare and implement the constructors you need for you, import the assignment operators, and declare a private resize function. Then in ParticleCollection, you will still be able to resize it by first casting it into a MatrixXf: static_cast<MatrixXf&>(state_).resize(....); Of course the users will still be able to do it, but that cannot be done by accident. |
Registered users: Baidu [Spider], Bing [Bot], Google [Bot]