Re: [eigen] Re: XLC Port: Part II - External definition of a template member function of a template class causing the problems?

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


I didn't know that template partial specialization allowed you to
change the number of template parameters.  That doesn't seem right to
me.

A

On Sat, Jan 30, 2010 at 5:14 PM, Benoit Jacob <jacob.benoit.1@xxxxxxxxx> wrote:
> 2010/1/30 Benoit Jacob <jacob.benoit.1@xxxxxxxxx>:
>> 2010/1/30 Aron Ahmadia <aja2111@xxxxxxxxxxxx>
>>>
>>> Dear All,
>>> Thanks Thomas for your input.  I went back and double-checked the class/typename declarations/definitions and nothing obvious appeared.
>>> This does not appear to be a typename/class bug.  In the classes that I have looked at so far, the Eigen developers have been fairly careful to use the 'typename' keyword almost exclusively.  Is it possible that the XLC Compiler does not know how to deduce the template arguments for ei_traits when it is used like so?
>>> template<typename MatrixType, int BlockRows=Dynamic, int BlockCols=Dynamic,
>>>   int _DirectAccessStatus = (ei_traits<MatrixType>::Flags&DirectAccessBit) ? HasDirectAccess : NoDirectAccess> class Block;
>>> In Eigen ei_traits is not defined as a single template parameter template.
>>
>> It is !!
>>
>>>It is forward declared:
>>> template<typename C> struct ei_traits;
>>
>> So this by itself means that it's a single template parameter template,
>>
>>> It is defined in Matrix.h like this:
>>> template<typename _Scalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
>>> struct ei_traits<Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols> >
>>
>> Yes, so here ei_traits is still specialized with a single template
>> parameter, which is here Matrix<_Scalar, _Rows, _Cols, _Options,
>> _MaxRows, _MaxCols>. Again, this is a full specialization of Matrix,
>> so this is just a plain class type that doesn't remember that it comes
>> from the template Matrix. The parameters Scalar, _Rows, etc.... are
>> not to be considered template parameters of ei_traits.
>
> Just to clarify this, this is what one calls a partial specialization
> of ei_traits, and it is valid to have the partial specialization
> depend on more template parameters than ei_traits itself does.
>
> Try this:
>
> #include<iostream>
>
> template<typename T> struct ei_traits
> {
>  ei_traits() { std::cout<< "generic" <<std::endl; }
> };
>
> template<typename T, typename U> struct Foo
> {};
>
> template<typename T, typename U>
> struct ei_traits<Foo<T,U> >
> {
>  ei_traits() { std::cout<< "Foo" <<std::endl; }
> };
>
> int main()
> {
>  ei_traits<int> a;
>  ei_traits<Foo<int,float> > b;
> }
>
> Benoit
>
>>
>>> { ... }
>>> It is defined later in ArrayWrapper.h like this:
>>> template<typename ExpressionType>
>>> struct ei_traits<MatrixWrapper<ExpressionType> >
>>>  : public ei_traits<ExpressionType>
>>> But I suspect the intended usage is in Matrix.h, not in ArrayWrapper.h
>>
>> In Eigen, each class Foo uses ei_traits<Foo>. More specifically, we
>> use a lot the curiously recurring template pattern,
>> http://en.wikipedia.org/wiki/Curiously_recurring_template_pattern
>>
>> So we have classes Foo that inherit MatrixBase<Foo>, so we are
>> simultaneously defining Foo and MatrixBase<Foo> which poses
>> complicated forward-declaration problems which we solve by defining
>> some stuff (typedefs and enums) in an auxiliary class ei_traits<Foo>
>> and letting both Foo and MatrixBase<Foo> read that stuff from
>> ei_traits<Foo>.
>>
>>  (I don't think XLC is attempting to use either definition, but I'm
>> puzzled as to why it doesn't like even the ArrayWrapper template).
>>
>> ei_traits<Foo> is used for example in MatrixBase<Foo>. Search for
>> ei_traits in MatrixBase.h.
>>
>>> I understand that there's a concept of adding 'traits' by using templates, but I don't know much beyond that
>>
>> I don't really see what we're doing here as implementing a general
>> 'traits' concept. It's just a little device that we use to resolve
>> issues when Foo and MatrixBase<Foo> are being defined simultaneously.
>>
>>>or how to understand whether or not Eigen is doing something valid here.
>>
>> With 99% certainty, it's valid!
>>
>>>  By using the inlining described before, I can successfully at least include all of Core without getting any compiler errors, it is now in the instantiation phase that XLC is whining.  More thoughts and advice are always appreciated.
>>
>> What frightens me now is the idea that perhaps XLC doesn't like the
>> CRTP (see above link).
>>
>> Benoit
>>
>>
>>> Aron
>>>
>>>
>>> On Wed, Jan 27, 2010 at 5:54 PM, Alexandre Eichenberger <alexe@xxxxxxxxxx> wrote:
>>>>
>>>> Aron,
>>>>
>>>> I have contacted someone at Toronto (product division) but have not heard back from them. Please keep me updated on whether the fix proposed by Thomas worked for you with xlc.
>>>>
>>>>
>>>> Alexandre
>>>>
>>>> ------------------------------------------------------------------------------------------
>>>> Alexandre Eichenberger, Advanced Compiler Technologies
>>>> - research: compiler optimization & SIMD code generation
>>>> - mail/info: http://www.research.ibm.com/people/a/alexe
>>>> - phone: 862-1812 (t/l), 914-945-1812 (external)
>>>>
>>>>
>>>> Thomas Capricelli ---01/27/2010 09:18:27 AM---Ah, wait, i've had this kind of problem when trying icc (i think) : there are templates declared (in
>>>>
>>>>
>>>> From:
>>>> Thomas Capricelli <orzel@xxxxxxxxxxxxxxx>
>>>> To:
>>>> eigen@xxxxxxxxxxxxxxxxxxx
>>>> Cc:
>>>> Aron Ahmadia <aja2111@xxxxxxxxxxxx>, Alexandre Eichenberger/Watson/IBM@IBMUS, John A Gunnels/Watson/IBM@IBMUS, aron.ahmadia@xxxxxxxxxxxx
>>>> Date:
>>>> 01/27/10 09:18 AM
>>>> Subject:
>>>> Re: [eigen] Re: XLC Port: Part II - External definition of a template member function of a template class causing the problems?
>>>> ________________________________
>>>>
>>>>
>>>>
>>>>
>>>> Ah, wait, i've had this kind of problem when trying icc (i think) : there are templates declared (in forward as
>>>> template<typename T>
>>>>
>>>> but later on defined with
>>>> template<class T>
>>>>
>>>> It seems that most compilers do not care. I think icc issued warnings... maybe yours is just not happy with this. This can easily be fixed without disturbing other compilers i think.
>>>>
>>>> Thomas
>>>> --
>>>> Thomas Capricelli <orzel@xxxxxxxxxxxxxxx>
>>>> http://www.freehackers.org/thomas
>>>>
>>>> In data mercoledì 27 gennaio 2010 14:50:38, Thomas Capricelli ha scritto:
>>>> > > template<typename T> struct ei_traits;
>>>>
>>>>
>>>
>>
>
>
>



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