How do I apply the .cast() method to the output of a comparison operator?

Saturday, May 3, 2014

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?







http://ift.tt/1fGh2i2