Question

I want to apply the threshold function to a bunch of fuzzy values (floats):

template <typename Derived>
void Threshold(Eigen::ArrayBase<Derived>& params)
{
  params = (params >= 0.0f).cast<float>();
}

The idea is that I end up with a bunch of 1s and 0s (float) where there used to be fuzzy values. But when I do this I get the following error:

src/core/Neuron.h: In static member function ‘static void Neuron::Threshold(Eigen::ArrayBase&)’: src/core/Neuron.h:119:43: error: expected primary-expression before ‘float’ params = (params >= 0.0f).cast(); ^ src/core/Neuron.h:119:43: error: expected ‘;’ before ‘float’ make: * [src/core/Cell.o] Error 1

Clearly I'm not using the cast method properly. I've looked at the Documentation and it gives the following prototype for the cast method:

internal::cast_return_type< Derived,const CwiseUnaryOp<internal::scalar_cast_op<typename internal::traits<Derived>::Scalar, NewType>, const Derived> >::type cast () const inline

I don't really understand what all that means, but I'm guessing I might be missing a template parameter?

Was it helpful?

Solution

Try:

params = (params >= 0.0f).template cast<float>();

This usage basically is just an overloading of the template keyword. Here, it's a hint to the compiler that you are trying to call a member template. See this for full details.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top