Registered Member
|
The documentation for Writing Functions Taking Eigen Types as Parameters (http://eigen.tuxfamily.org/dox/TopicFunctionTakingEigenTypes.html) nicely describes how to write functions that take generic Eigen types as input parameters and output parameters. For example `cov(x,y,C)` computes the covariance matrix of the inputs `x` and `y` into the output `C`.
I'd like to extend upon this example to consider generic Eigen types as return arguments. Then I'd like to be able to do things like `C = cov(x,y)` and `C.block(0,0,3,3) = cov(x,x+y);` etc. Here's a little example program that contains a fully templated input-output implementation of cov (e.g. `cov(x,y,C)`) and then a broken wrapper with `C` as a return argument. In the `main` function I included some example calls to check compilation. Obviously I'd like to implement `cov` only once, so hopefully the return-arg version is just a thin wrapper on top of the full output-arg version. Ideally, I'd like things like `C.block(0,0,3,3) = cov(x,y);` to work too.
|
Registered Member
|
The documentation for this is on dev version:
http://eigen.tuxfamily.org/dox-devel/To ... nType.html Even known it's in dev, I think that the latest release support this api already, so you are good to go. |
Moderator
|
Instead of writing a full expression, one can exploit Eigen::ReturnByValue to reduce a bit the amount of work. In both cases, the general idea is to let cov(x,y) returns a proxy object, let's call it CovProxy storing references to x and y, and from which Eigen will call CovProxy::evalTo(C) into which you call cov(this->x, this->y, C);
However, even using Eigen::ReturnByValue, this still require some amount of boiler-plate code. Perhaps, this could be wrapped into a more generic proxy simply storing a pointer to the arguments, and a function pointer. |
Moderator
|
For the fun, I've started a proof of concept in C++11:
File "rvo_plugin.h":
User code:
This example is still very limited, but it can surely be extended to be more generic on both the arguments and destination. |
Registered users: bartoloni, Bing [Bot], Evergrowing, Google [Bot], ourcraft