Re: [eigen] inverse unit test
• To: eigen@xxxxxxxxxxxxxxxxxxx
• Subject: Re: [eigen] inverse unit test
• From: Gael Guennebaud <gael.guennebaud@xxxxxxxxx>
• Date: Thu, 10 Jun 2010 10:44:18 +0200
• Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; b=qfk785gcumQJji8fyhrf+nZrPPpXpi8gxBneHh/jDWS9450rVLI7yI9ztOUi3c9GHU VMWmYkLT+hENC5bYk43JS8E1DNXfQT7XIr3zXzCV9MQhuce+bSex2rC7Ojg9bFJJWJ98 88XfY49DYA+mBRG0fF4tAx+rGj/RxnrpzcNdA=

On Thu, Jun 10, 2010 at 9:42 AM, Manuel Yguel wrote:
I hit the same problem several times and the implementation of
isMuchSmallerThan for float is:

inline bool ei_isMuchSmallerThan(float a, float b, float prec =
NumTraits<float>::dummy_precision())
{
return ei_abs(a) <= ei_abs(b) * prec;
}

if b is zero, then whatever prec is, it will failed if a is not zero,
so I do agree with Hauke that his implementation is needed.
So in fact in my own code I finally used the function he proposed.

Here's my 2 cents.

The VectorBase and MatrixBase classes apart from implementing the isApprox(...) method, implement the very convenient:

bool isZero       (const T & precision = Util::epsilon<T>()) const
bool isNegligible (const T & other, const T &  precision = Util::epsilon<T>()) const
bool isNegligible (const Derived & other, const T &  precision = Util::epsilon<T>()) const

Where did you find the isNegligible functions? Anyway isNegligible would be an alias for isMuchSmallerThan.

Regarding isZero, yes we added it for "convenience" but I think it is more difficult to use than isMuchSmallerThan unless you are in the specific case where your values are in the order of 1. Otherwise you have to compute yourself what is the ideal epsilon matching your case, and this is more difficult than simply specifying a reference value of your non zeros because this "ideal" epsilon depends on the scalar type. In other word, with isMuchSmallerThan you only have to bother about the typical range of your non zeros, while with a isZero function you also have to take care at the scalar type.

Now I acknowledge that in many cases, 1 is a good reference value, and so yes why not adding such a isZero for scalars as well nut with a big warning because it has to be used with care. Let's see what Benoit thinks about that.

gael

For convenience and parallelism with the Vector and Matrix types classes, it would be nice to have the isZero(....) and isNegligible(...) functions defined for Scalar types as well. Granted, isZero(val, prec) == isMuchSmallerThan(val,1.0, prec), but the former is less verbose and much easier to understand.

- cheers,

Manu

--