Re: [eigen] Proposal: Include Constants to NumTraits |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/eigen Archives
]
- To: eigen@xxxxxxxxxxxxxxxxxxx
- Subject: Re: [eigen] Proposal: Include Constants to NumTraits
- From: Gael Guennebaud <gael.guennebaud@xxxxxxxxx>
- Date: Fri, 6 Apr 2012 21:57:22 +0200
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type:content-transfer-encoding; bh=myBdUbUHBe8RsUkOl5aK/0GPNtRg5zCjgtS1iCHRD2U=; b=lXilhoZCj4vdACm9Ja1AnW+JuAPTOWt7XSW9vuPucnLw2NW3p25z3kdjGMfxc1jpuu jfSZtVOvjUhYfGSDsX2Z/fRXdjxoU9iTyv74sIL1Ij55lJqRnHuXH/AIs9k/9HdMJZh7 dHWJEXefhYyQ4OUY3+eVrRIIjDg/56MwdQoVenxVCpuQpGqyUbCP/BcJbN/DbMx1DJ3v rAgBQaYZvOLzTEjhfJaOsMJO1U8JJAOZnPouegzFct8gZ3rBfwo8/x3aNEgrkBRFFSHq Kl/qh0u51uDQg3OjzWaR1cUR4pQBcNKqgHMx95kTp3O/5sapcGng00t5cnHvLP4sO+jz 5LnQ==
Hi,
I guess the list of such constants can be very large to cover all
application domains, so I'm not sure that's the scope of Eigen. The
idea is to have the constants that are needed for Eigen's algorithm
only, and if that feature is already well covered by boost then I
don't see a huge need for us to do a clone.
cheers,
gael
On Fri, Apr 6, 2012 at 6:24 AM, Pavel Holoborodko <pavel@xxxxxxxxxxxxxxx> wrote:
> Eigen is well designed to be invariant of scalar types.
>
> However I think there is one point for improvement - mathematical
> constants.
> They tied to scalar type (to its precision, e.g. double vs. multiple
> precision) and frequently needed in computations.
>
> Now, in true generic code in order to use matching-to-scalar constant we
> have to do something like: pi = acos(Scalar(-1)) (FFT module).
> Obviously this can (and should) be improved.
>
> We already handle machine epsilon by NumTraits. Why don't we include other
> constants to NumTraits?
> So that we can use them as follows
>
> typedef typename MatrixType::Scalar Scalar;
> typedef typename NumTraits<Scalar>::Real RealScalar;
>
> const RealScalar Pi = NumTraits<RealScalar>::Pi();
> const RealScalar Euler = NumTraits<RealScalar>::Euler();
> const RealScalar Log2 = NumTraits<RealScalar>::Log2();
> const RealScalar Catalan = NumTraits<RealScalar>::Catalan();
> ...
>
> // Use constants in the code below
> // ...
>
> This would make writing generic code much easier (and code will be cleaner).
>
> This is especially important for multiple precision types - where computing
> of const. takes a lot of resources.
> Additional layer of abstraction will allow us to cache const. without
> recomputing them every time.
>
> For built-in scalar types these functions will be one-liners without any
> overhead.
>
> Also it has sense to include Inf(), Nan() as special values (similar
> to std::numeric_limits<Scalar> ).
>
> Would appreciate any comments.
>
> (Boost has similar library - e.g. boost::math::constants::pi<Scalar>();)