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

[ Thread Index | Date Index | More lists.tuxfamily.org/eigen Archives ]


sorry, I were not very clear. Actually, handling std::min(lhs,rhs)
where typeof(lhs) != typeof(rhs) and both lhs and rhs are Eigen's type
is not a problem:

template<typename Left,typename Right>
inline const blabla
min(const Eigen::ArrayBase<Left>& x, const Eigen::ArrayBase<Right>& y);

does the job.

The problem is support the case where typeof(lhs)==typeof(rhs) because
the STL already define a generic version for that case, and my
previous overload is not considered. Likewise, the enable_if trick
cannot help here (unless I'm overseeing something). I think that the
only solution would be to have overloads for every Eigen expression
types, but that's not something we wanna do.


gael

On Mon, Apr 4, 2011 at 4:39 PM, Karl Rupp <rupp@xxxxxxxxxxxxxxxx> wrote:
> 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,
>                   ReturnTypeHere>::type
> 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:
> http://www.boost.org/doc/libs/1_46_1/libs/utility/enable_if.html
> The implementation of enable_if is trivial, so no need to worry about boost
> dependencies.
>
> Maybe that helps...
>
> Best regards,
> Karli
>
>
> 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.
>>
>> gael
>>
>>
>> On Fri, Apr 1, 2011 at 9:23 AM, Helmut Jarausch
>> <jarausch@xxxxxxxxxxxxxxxxxxx>  wrote:
>>>
>>> Hi,
>>>
>>> is the following assumed to work (I saw it in the Quick Reference
>>> Guide)
>>>
>>> #include<Eigen/Core>
>>> #include<cmath>
>>> given
>>> 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
>>> /usr/lib/gcc/x86_64-pc-linux-gnu/4.5.2/include/g++-v4/bits/
>>> 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,
>>> Helmut.
>>>
>>>
>>>
>>
>>
>>
>
>
>
>



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/