Boost logo

Glas :

Re: [glas] Concept C++ [was Re: back to business}

From: Peter Gottschling (pgottsch_at_[hidden])
Date: 2006-11-27 12:34:43


Hi Karl,

On Nov 23, 2006, at 2:39 AM, Karl Meerbergen wrote:

> Peter,
>
> One question that is on my mind for a while now is the following one:
> the mathematical definition of e.g. magma is clear. When do two types
> belong to the same magma? E.g. int + double is an operation between
> different types but they belong to double. Is there a mechanism in
> your
> concepts that takes care of this?
>
Good question. That is an issue that needs careful consideration.
At the moment I only considered operations between arguments of the
same type. There are some ideas but they are not worked out in
detail. I see 2 approaches:

1. We can compute op(x, y) if T1 is convertible into T2 and T2 is a
magma, or vice versa. This approach is probably more flexible but
the risk is that the mixed operations on T1 and T2 must be
semantically equivalent to operations on T2. Unfortunately, with
automatic conversion, the programmer has no control whether the
semantics of the mixed operations are held.

2. We introduce a concept like MixedArithmetic<Op, T1, T2, TA> that
specifies that an operation of type Op on two arguments of types T1
and T2 are computed on type TA. Meaning: the arguments are converted
from T1 and T2 into TA and the concept check is performed w.r.t. TA,
e.g. AdditiveMagma<TA>. Most likely TA would be T1 or T2.

The second method seems to be semantically more controllable but is
also kind of cumbersome. The best would be search together for a
solution. I have no satisfying solution yet, only a very vague idea.

> Another examples is vector<double> v, w ;
> The expression v+w returns e.g.
> add_vector< vector<double>, vector<double> >,
> which is only evaluated at assignment, e.g. x=v+w.
> Do you deal with this returntype in your concepts? I think this
> would be
> very helpful.
>
That works. As long the return type is assignable to the vector
type. You can write x=v+w. Rolf Bonderer and I did this for
instance uBlas vector addition. He also defined some more
concept_maps so that one could use more complex expressions, like x+=
alpha * y;

If you add three vectors in one expression, e.g. x=v+w+z you run into
the first problem (unless you write an explicit concept_map for this
expression). I believe for expression templates exist also another
general solutions to enable interoperability between the original
type and intermediate results. However, if we find a good solution
for the first problem it might work for ET, too.

Best,

Peter
> Thanks,
>
> Karl
>
> On Wed, 2006-11-22 at 10:38 -0500, Peter Gottschling wrote:
>> Well, I used ConceptGCC many times and it works quite well now. The
>> fundamental concepts on the GLAS list, like ring and group, are
>> implemented with concepts now and compiled with ConceptGCC. I
>> published
>> the results as technical report:
>>
>> http://www.cs.indiana.edu/cgi-bin/techreports/TRNNN.cgi?trnum=TR638
>>
>> There is amongst others an example to compute the power function with
>> regard to an arbitrary binary function. There are different
>> algorithms
>> for magma, semi-group, monoid and groups. The concept compiler
>> dispatches to the most appropriate.
>>
>> In another paper still pending I did performance experiments and it
>> showed that the performance is the same as with gcc without concepts.
>>
>> There were occasionally some minor problems with ConceptGCC but Doug
>> fixed most of them in the meantime. That said, the compiler is
>> not in
>> perfect production mode yet but it is already extremely useful for
>> working with concepts.
>>
>> Cheers,
>> Peter
>>
>> On 22.11.2006, at 08:52, Ian McCulloch wrote:
>>
>>>
>>> On Wed, 22 Nov 2006, Karl Meerbergen wrote:
>>>
>>>> I think we should consider this. Is concept-gcc stable now?
>>>
>>> I think it is, although last time I checked there were some
>>> issues with
>>> compile times that ought to go away in the final version. Aside
>>> from
>>> spending a few hours reading the proposal, I have never used concept
>>> gcc.
>>> Maybe someone else on this list has? My impression was though, it
>>> would
>>> be the killer feature for linear algebra libs.
>>>
>>> Cheers,
>>> Ian
>>>
>>>
>>>>
>>>>
>>>> On Wed, 2006-11-22 at 14:36 +0100, Ian McCulloch wrote:
>>>>> Hi Karl, Toon,
>>>>>
>>>>> Have you considered using Concept-GCC ?
>>>>> http://www.generic-programming.org/languages/conceptcpp/
>>>>>
>>>>> Ian
>>>>>
>>>>> _______________________________________________
>>>>> glas mailing list
>>>>> glas_at_[hidden]
>>>>> http://lists.boost.org/mailman/listinfo.cgi/glas
>>>> --
>>>> Karl Meerbergen
>>>> Katholieke Universiteit Leuven
>>>> Department of Computer Science
>>>>
>>>> E-mail: karl.meerbergen_at_[hidden]
>>>> URL : http://www.cs.kuleuven.be/cwis/research/nalag/
>>>> Phone : +32 16 327700 (secretary)
>>>> Fax : +32 16 327996
>>>>
>>>> _______________________________________________
>>>> glas mailing list
>>>> glas_at_[hidden]
>>>> http://lists.boost.org/mailman/listinfo.cgi/glas
>>>>
>>>>
>>> _______________________________________________
>>> glas mailing list
>>> glas_at_[hidden]
>>> http://lists.boost.org/mailman/listinfo.cgi/glas
>>>
>> ------------
>> Peter Gottschling, Ph.D.
>> Research Associate
>> Open Systems Laboratory
>> Indiana University
>> 135 Lindley Hall
>> Bloomington, IN 47405
>> Tel.: +1-812-855-3608 Fax: +1-812-856-0853
>> http://www.osl.iu.edu/~pgottsch
>>
>> _______________________________________________
>> glas mailing list
>> glas_at_[hidden]
>> http://lists.boost.org/mailman/listinfo.cgi/glas
> --
> Karl Meerbergen
> Katholieke Universiteit Leuven
> Department of Computer Science
>
> E-mail: karl.meerbergen_at_[hidden]
> URL : http://www.cs.kuleuven.be/cwis/research/nalag/
> Phone : +32 16 327700 (secretary)
> Fax : +32 16 327996
>
> _______________________________________________
> glas mailing list
> glas_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/glas

------------
Peter Gottschling
Research Associate
Open Systems Laboratory
Indiana University
135 Lindley Hall
Bloomington, IN 47405
Tel.: +1 812 855-3608 Fax: +1 812 856 0853
http://www.osl.iu.edu/~pgottsch