Re: [eigen] compile-time sqrt |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/eigen Archives
]
- To: eigen@xxxxxxxxxxxxxxxxxxx
- Subject: Re: [eigen] compile-time sqrt
- From: Benoit Jacob <jacob.benoit.1@xxxxxxxxx>
- Date: Thu, 11 Feb 2010 09:34:54 -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; bh=txkM6aX44lPlCvauS+yWHfU2P88v9AgC2HdTlpfpg8A=; b=dhmYgtZ48MDvE0+PKfbj4GxPDqEBwIuttAfpLVk7fArDs00xo07Jcr75gHTpjwhmLj T2jFZbzwrSPEuB+F6Ex/cA6B9N+vywwx00NGSnvUiNR+Ke7ArBbGZ6+sYkJlQBUG/NJo 06kII23mo3fR1uPTAAK2VwkmYLY7zrpaQ3vEQ=
- 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; b=OgPsgeXWcbr96YfHq8AwXIGOInUrIT+tIgGL6K0wfsCLKtdw0jrSqMIzhskFENn91W +GdwpjR6bKfcZ5HhFOsPb3LhAmMdGQVwSd/Dslqn44fY9kZEhBXUuQPVLc45f2OEbybl n8cJWk2qdaPVtM7z2AZwBp3aZe5iejihkjAKI=
Or you could have a template struct with a static method, default to a
sqrt call, and have specializations for float and double where you
manually provide the precomputed sqrt value.
Benoit
2010/2/10 Benoit Jacob <jacob.benoit.1@xxxxxxxxx>:
> Hi,
>
> The problem lies even deeper than that: ei_meta_sqrt takes an integer,
> and actually floats can't be template parameters. So you can't use
> ei_meta_sqrt for that.
>
> In contexts where you're happy with just GCC, it's been able to
> evaluate sqrt at compile time for a while. Since GCC 4.3, a lot more
> functions are evaluated at compile time using MPFR. GCC 4.5 introduces
> the same thing for complex numbers.
>
> Thus, for lack of a better solution, you might just do a sqrt call and
> rely on the compiler to optimize it at compile time.
>
> An alternative is to compare x*x < eps instead of comparing x < sqrt(eps).
>
> Benoit
>
> 2010/2/10 Thomas Capricelli <orzel@xxxxxxxxxxxxxxx>:
>>
>> Hi.
>>
>> I sometimes need to use sqrt of epsilon (typically in unsupported/Eigen/src/NonLinearOptimization/chkder.h)
>> Currently i do
>> const Scalar eps = ei_sqrt(NumTraits<Scalar>::epsilon());
>>
>> but i'd like to have it computed at compile-time.. i'm not sure how to do this. I've tried :
>> const Scalar eps = ei_meta_sqrt<NumTraits<Scalar>::epsilon()>::ret;
>>
>> but the compiler complais that epsilon() is a function call hence the template can't be done.
>>
>> Thomas
>> --
>> Thomas Capricelli <orzel@xxxxxxxxxxxxxxx>
>> http://www.freehackers.org/thomas
>>
>>
>>
>