[ Thread Index |
Date Index
| More lists.tuxfamily.org/eigen Archives
]
- To: eigen@xxxxxxxxxxxxxxxxxxx
- Subject: Re: [eigen] FFT update
- From: Benoit Jacob <jacob.benoit.1@xxxxxxxxx>
- Date: Sun, 24 Jan 2010 11:52:37 -0500
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:content-type :content-transfer-encoding; bh=YzQs5l8XmFlOyhoiuMCp6h8ybL7RX3c+V/JhLIuuZhY=; b=CQr/z0AeImbLlIhWvxX1xTm4rbcWIzTnrBC3nX0E4GkGC4hcTdT5Wd1mbRZ1NUFPL4 W4tNjp3P4BB7XQNGO7jweB1az4G6X4nSkkESin1SUBVL3Hoil0FCizc907fVz0yYeslM 875aOfbndyLbixn/JNyxITVSRzk+GLHeq0TnU=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=uDIyYpZ8zk4zPzCR0PE4MGU29gkPr4s48J6ZpIzwOjfbim4gSBH8iatPuKe/TBpvMp j8HpzozUlU3O39LqbJLiQloK7wPsDapJWlGU6WkYSEJNdR6Jp0xzoEyxeZfbHNH6Tp6B L+I0OQan0BAIveXXqdjiGJWQ9uVrnSl//aG5k=
2010/1/24 Rohit Garg <rpg.314@xxxxxxxxx>:
> On Sun, Jan 24, 2010 at 12:33 PM, Benoit Jacob <jacob.benoit.1@xxxxxxxxx> wrote:
>> 2010/1/24 Benoit Jacob <jacob.benoit.1@xxxxxxxxx>:
>>> 2010/1/23 Benoit Jacob <jacob.benoit.1@xxxxxxxxx>:
>>>> By the way, this "ReturnByValue::coeff() crashes by infinite
>>>> recursion" thing is really ugly, I wonder how to fix it!!
>>>>
>>>> C++0x at last brings the ability to remove a base class function from
>>>> a derived class... I wonder how to implement that idea in C++98. Is
>>>> that enable_if?
>>>
>>> Forget enable_if, forget C++0x, forget boost, i'm your new idol.
>
> Alrighty, :)
>>>
>>> If we want to make sure that using ReturnByValue::coeff() generates an
>>> error at compile time without generating an error until it's actually
>>> used, we can define a class:
>>>
>>> class Unusable
>>> {
>>> // implement copy ctor/operator as private to disable them
>>> Unusable(const Unusable&) {}
>>> void operator=(const Unusable&) {}
>>> };
>>>
>>> We then let ReturnByValue::coeff() return that:
>>>
>>> class ReturnByValue
>>> {
>>> ...
>>> Unusable coeff(int, int) { return Unusable(); }
>>> ...
>>> };
>>>
>>> The result is that when the user does e.g.
>>> x = retval.coeff(i);
>>> or
>>> x = retval.coeff(i) + 123;
>>> he gets compilation errors.
>>>
>>> Just doing
>>> retval.coeff(i);
>>> doesn't give an error, but that should be optimizable as just a NOP anyway.
>>>
>>> With this, i go to bed full^Wproud of myself.
>>
>> Ah, this needed a little adjustment. Doing
>> Unusable coeff(int, int) { return Unusable(); }
>> was already copying a Unusable object, the return value of that
>> method. While the trick still worked with GCC, it was probably
>> fragile, and the error wasn't very explicit.
>>
>> Here is a much better variant:
>> const Unusable& coeff(int) const { return *reinterpret_cast<const
>> Unusable*>(this); }
>>
>> Now this method is really not using any Unusable constructor/operator.
>>
>> The error message when I do:
>> float x = rotate(v).coeff(0);
>> is now just:
>> returnbyvalue.cpp: In function ‘int main()’:
>> returnbyvalue.cpp:122: error: cannot convert ‘const
>> Eigen::Unusable’ to ‘float’ in initialization
>>
>> ok to commit?
>
> I'd suggest that since you are *forcing* a compiler error here, it
> would be better to add a long descriptive error to go with it. Some
> thing like this
>
> http://eigen.tuxfamily.org/index.php?title=FAQ#I_need_help_with_compiler_errors.21
Yes, good idea!
Benoit
>
>>
>> Benoit
>>
>>>
>>> Benoit
>>>
>>>>
>>>> Benoit
>>>>
>>>> 2010/1/23 Benoit Jacob <jacob.benoit.1@xxxxxxxxx>:
>>>>> Hi,
>>>>>
>>>>> Here's an example: see attached file.
>>>>> Enjoy!!
>>>>> Benoit
>>>>>
>>>>> 2010/1/22 Benoit Jacob <jacob.benoit.1@xxxxxxxxx>:
>>>>>> ok let me write an example...
>>>>>>
>>>>>> 2010/1/22 Jitse Niesen <jitse@xxxxxxxxxxxxxxxxx>:
>>>>>>> On Fri, 22 Jan 2010, Benoit Jacob wrote:
>>>>>>>
>>>>>>>> Our "policy" is now:
>>>>>>>> - try to return by value, optimizing with the ReturnByValue class,
>>>>>>>> wherever possible;
>>>>>>>> - otherwise you can just use references.
>>>>>>>
>>>>>>> Can somebody please explain how to use the ReturnByValue class?
>>>>>>> Or should I just extrapolate from the source code?
>>>>>>> I could not find any documentation.
>>>>>>>
>>>>>>> Jitse
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>
>>>>>
>>>>
>>>
>>
>>
>>
>
>
>
> --
> Rohit Garg
>
> http://rpg-314.blogspot.com/
>
> Senior Undergraduate
> Department of Physics
> Indian Institute of Technology
> Bombay
>
>
>