template <typename Derived>
void Threshold(Eigen::DenseBase<Derived>& params)
// I tried void Threshold(Eigen::ArrayBase<Derived>& params) as well, same outcome
{
params = (params >= 0.0f).template cast<float>();
}
The problem is, when I call this function like this:
Eigen::Array<float, Eigen::Dynamic, Eigen::Dynamic> arr;
// fill it with stuff
Threshold(arr.col(0)); // error!
I get the following error:
no known conversion for argument 1 from ‘Eigen::DenseBase<Eigen::Array<float, -1, -1>
>::ColXpr {aka Eigen::Block<Eigen::Array<float, -1, -1>, -1, 1, true>}’ to
‘Eigen::DenseBase<Eigen::Block<Eigen::Array<float, -1, -1>, -1, 1, true> >&’
Is my function template wrong? How do I pass the output of the .col() method of an Eigen::Array object to a function?
Solution
You are probably looking for the Ref<> class which will allow you to write a function that accepts both columns of a matrix and vectors without templates nor copies: