operator== for Blaze types is not transitive

Issue #258 wontfix
Mikhail Katliar created an issue

Consider an example:

#include <blaze/Math.h>
#include <iostream>

int main(int, char **)
{
    blaze::DynamicVector<double> a {1.00000000};
    blaze::DynamicVector<double> b {1.00000001};
    blaze::DynamicVector<double> c {1.000000011};

    std::cout << "(a == b) == " << (a == b) << std::endl;
    std::cout << "(b == c) == " << (b == c) << std::endl;
    std::cout << "(a == c) == " << (a == c) << std::endl;

    return 0;
}

Output:

(a == b) == 1
(b == c) == 1
(a == c) == 0

It looks like Blaze performs equality comparison with some (not explicitly specified) tolerance. This breaks the transitivity property of the equality operator.

I would assume operator==()for linear algebra types to perform exact comparison (and hence to be transitive). This is also important in tests, since test frameworks rely on operator==() to perform equality checks.

Comments (3)

  1. Klaus Iglberger

    Hi Mikhail!

    Thanks a lot for creating this issue. You are correct, for vector and matrices with floating point element type operator==() is not transitive. Blaze indeed uses a threshold/tolerance to perform the comparison.

    Please note that these comparison semantics are a deliberate choice. Although these semantics may be counter-intuitive from a pure mathematical point of view, we will not change the behavior for three reasons. First, and probably most importantly, operator==() would become virtually useless for practical purposes if it would perform a strict comparison for floating point values. This argument even holds true for tests, since only for the most basic of tests involving floating point numbers an equality comparison would work. Therefore it is our expectation that most people would assume operator==() to perform an approximate comparison for floating point numbers.

    Second, changing these semantics could have a significant impact on exisiting code. For this reason alone we couldn't change it and could only provide an alternative.

    Last but not least, we already provide the alternative functionality to perform a strict comparison by means of the equal() function. With the fix provided for issue #259 you are able to perform a strictly equality comparison for all kinds of vectors and matrices (thanks again for pointing out the defect for dense matrices).

    Hopefully this gives some insight into the design decisions and answers the question on how to perform strict equality comparisons. Thanks again for creating this issue,

    Best regards,

    Klaus!

  2. Log in to comment