Re: [eigen] min(Arr1,Arr2) is it supposed to work?

[ Thread Index | Date Index | More Archives ]

Hi guys,

I just stumbled over a similar issue in a totally different context yesterday - still, it might be just what is needed: What about using an enable_if variant for the overloads? Something like

template <typename LHS, typename RHS>
typename enable_if<is_eigen<LHS>::val || is_eigen<RHS>::val,
min(LHS const & lhs, RHS const & rhs) { ... }

The metafunction is_eigen<> should be such that it returns true if the argument is an Eigen type, otherwise false. In the body of min, you can then call e.g. Eigen::min(const ArrayBase<T>&, const ArrayBase<T>&)

Details on enable_if can be found e.g. here:
The implementation of enable_if is trivial, so no need to worry about boost dependencies.

Maybe that helps...

Best regards,

On 04/04/2011 04:23 PM, Gael Guennebaud wrote:
oops, indeed the quick ref guide is again in advance with Eigen
development. Actually, it seems to be impossible for us to support
std::min(array1,array2) because std::min is implemented in a generic
way as:

     template<typename _Tp>   inline const _Tp&   min(const _Tp&  __a,
const _Tp&  __b)
       if (__b<  __a)
	return __b;
       return __a;

therefore we cannot overload std::min for min(const
ArrayBase<T>&,const ArrayBase<T>&). To do so we would need overloads
for every expressions (Array<>, CwiseUnaryOp, CwiseBinaryOp, etc.).

I'm fixing the doc.


On Fri, Apr 1, 2011 at 9:23 AM, Helmut Jarausch
<jarausch@xxxxxxxxxxxxxxxxxxx>  wrote:

is the following assumed to work (I saw it in the Quick Reference

Eigen::Array3f V1, V2, V3;
  V1<<  1,2,3;
  V2<<  2,1,5;
  V3= V1.min(V2);       // this works
  V3= std::pow(V1,2);   // this works, as well

  V3= std::min(V1,V2);  // but this fails, see below
  cout<<  V3<<  endl;

Tmin.C:14:21:   instantiated from here
stl_algobase.h:191:7: error: could not convert '((const
Eigen::ArrayBase<Eigen::Array<float, 3, 1>  >*)((const
Eigen::Array<float, 3, 1>*)__b))->Eigen::ArrayBase<Derived>::operator<
[with OtherDerived = Eigen::Array<float, 3, 1>, Derived =
Eigen::Array<float, 3, 1>, typename Eigen::internal::traits<T>::Scalar
= float](((const Eigen::ArrayBase<Eigen::Array<float, 3, 1>  >&)((const
Eigen::ArrayBase<Eigen::Array<float, 3, 1>  >*)((const
Eigen::Array<float, 3, 1>*)__a))))' to 'bool'

Thanks for some info,

Mail converted by MHonArc 2.6.19+