Clamp function returns corrupted result with -O3

Issue #210 closed
Former user created an issue

The following test program returns corrupted results with -O3 but it is ok with -O0 with GCC 7.3.

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

int main()
{
    using namespace blaze;
    DynamicMatrix<float> a{{0.0f,1.0f}, {10000.0f,30000.0f} };
    DynamicMatrix<float> d{{0.0f,0.5f}, {0.9f,0.3f} };
    auto b = a - d;
    auto res = blaze::clamp(b, 0.0f, 20000.0f);
    std::cout << "res:\n" << res;
    auto res2 = map(b, [](float d)->float{return clamp(d,0.0f,20000.0f);});
    std::cout << "res2:\n" << res2;

    return 0;
}

I compile as follows:

g++ -c -mavx -O3 -DBLAZE_BLAS_MODE=0 -DBLAZE_USE_VECTORIZATION=1 -DBLAZE_CACHE_SIZE=6291456UL -std=c++1z -I. -I../blaze-3.4 -o main.o main.cpp
g++ -Wl,-O1 -o blazeClamp main.o

My compiler is:

$ g++ --version
g++ (Ubuntu 7.3.0-27ubuntu1~18.04) 7.3.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

A few results from running the above program when compiled with -O3:

$ ./blazeClamp 
res:
(  3.07081e-41  3.07081e-41 )
(  3.07081e-41        20000 )
res2:
(            0          0.5 )
(       9999.1        20000 )

$ ./blazeClamp 
res:
(  3.07207e-41  3.07207e-41 )
(  3.07207e-41        20000 )
res2:
(            0          0.5 )
(       9999.1        20000 )
$ ./blazeClamp 
res:
(  3.07655e-41  3.07655e-41 )
(  3.07655e-41        20000 )
res2:
(            0          0.5 )
(       9999.1        20000 )

As you can see the result using the blaze::map(..) function works fine.

I use blaze 3.4.

Comments (3)

  1. Former user Account Deleted reporter

    I will close this issue as I found that in issue #133, it is explained that I must use evaluate(..) in order to get a matrix (instead of the expression template).

  2. Log in to comment