2

I am making a function that can extend the given Matrix which is MatrixXd type. I was trying to use conservativeResize to achieve that, but when i use Ref in the function statement, conservativeResize doesn't work with with the Ref object, but resize do. I am wondering why this problem happens. Thanks in advance.

I tried to use MatrixXd &var directly in function statement, and it does work, but I don't know why Ref doesn't.

void mat_extend(Ref<MatrixXd> mat)
{
    int len = mat.rows();
    mat.conservativeResize(len+2,NoChange);
}
```
Oliver Yu
  • 99
  • 5

1 Answers1

0

In your case mat.resize(len+2,NoChange), won't work either. This should assert, unless you disabled assertions, in which case it will do nothing.

Ref does not allow resizing, since it does not "own" the memory it points to -- e.g., it could point to a block of another matrix, or to a Map of some externally allocated memory.

The reason that calling resize is allowed, is that in some generic code (including inside Eigen itself), matrices are first resized and then values are assigned. Guarding that by some isResizeable logic everywhere would be a mess.

chtz
  • 17,329
  • 4
  • 26
  • 56