Skip to content

Commit

Permalink
remove dot test for floats because of bug in Apple Accelerate BLAS
Browse files Browse the repository at this point in the history
  • Loading branch information
alfC committed Apr 19, 2024
1 parent 76bf020 commit b77f0fe
Showing 1 changed file with 77 additions and 76 deletions.
153 changes: 77 additions & 76 deletions include/multi/adaptors/blas/test/dot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,44 +33,45 @@ BOOST_AUTO_TEST_CASE(blas_dot_no_context_double) {
}

BOOST_AUTO_TEST_CASE(blas_dot_no_context_out_param_double) {
multi::array<float, 1> const x = {1.0F, 2.0F, 3.0F}; // NOLINT(readability-identifier-length) BLAS naming
multi::array<float, 1> const y = {1.0F, 2.0F, 3.0F}; // NOLINT(readability-identifier-length) BLAS naming
multi::array<double, 1> const x = {1.0, 2.0, 3.0}; // NOLINT(readability-identifier-length) BLAS naming
multi::array<double, 1> const y = {1.0, 2.0, 3.0}; // NOLINT(readability-identifier-length) BLAS naming

float res = NAN;

blas::dot(x, y, multi::array_ref<float, 0>(res));
BOOST_TEST( res == std::inner_product(begin(x), end(x), begin(y), 0.0F) );
BOOST_TEST( res == std::inner_product(begin(x), end(x), begin(y), 0.0) );
}

BOOST_AUTO_TEST_CASE(blas_dot_context) {
multi::array<float, 1> const x = {1.0F, 2.0F, 3.0F}; // NOLINT(readability-identifier-length) BLAS naming
multi::array<float, 1> const y = {1.0F, 2.0F, 3.0F}; // NOLINT(readability-identifier-length) BLAS naming
// float uses of dot are disabled because of a bug in Apple Accelerate BLAS
// BOOST_AUTO_TEST_CASE(blas_dot_context) {
// multi::array<float, 1> const x = {1.0F, 2.0F, 3.0F}; // NOLINT(readability-identifier-length) BLAS naming
// multi::array<float, 1> const y = {1.0F, 2.0F, 3.0F}; // NOLINT(readability-identifier-length) BLAS naming

blas::context const ctxt;
// blas::context const ctxt;

auto res1 = +blas::dot(&ctxt, x, y);
BOOST_TEST( res1 == std::inner_product(begin(x), end(x), begin(y), 0.0F) );
// auto res1 = +blas::dot(&ctxt, x, y);
// BOOST_TEST( res1 == std::inner_product(begin(x), end(x), begin(y), 0.0F) );

auto const res2 = +blas::dot(&ctxt, x, y);
BOOST_TEST( res2 == std::inner_product(begin(x), end(x), begin(y), 0.0F) );
}
// auto const res2 = +blas::dot(&ctxt, x, y);
// BOOST_TEST( res2 == std::inner_product(begin(x), end(x), begin(y), 0.0F) );
// }

BOOST_AUTO_TEST_CASE(blas_dot_no_context) {
multi::array<float, 1> const x = {1.0F, 2.0F, 3.0F}; // NOLINT(readability-identifier-length) BLAS naming
multi::array<float, 1> const y = {1.0F, 2.0F, 3.0F}; // NOLINT(readability-identifier-length) BLAS naming
// BOOST_AUTO_TEST_CASE(blas_dot_no_context) {
// multi::array<float, 1> const x = {1.0F, 2.0F, 3.0F}; // NOLINT(readability-identifier-length) BLAS naming
// multi::array<float, 1> const y = {1.0F, 2.0F, 3.0F}; // NOLINT(readability-identifier-length) BLAS naming

auto res = +blas::dot(x, y);
// auto res = +blas::dot(x, y);

BOOST_TEST( res == std::inner_product(begin(x), end(x), begin(y), 0.0F) );
}
// BOOST_TEST( res == std::inner_product(begin(x), end(x), begin(y), 0.0F) );
// }

BOOST_AUTO_TEST_CASE(blas_dot_no_context_out_param) {
multi::array<float, 1> const x = {1.0F, 2.0F, 3.0F}; // NOLINT(readability-identifier-length) BLAS naming
multi::array<float, 1> const y = {1.0F, 2.0F, 3.0F}; // NOLINT(readability-identifier-length) BLAS naming
float res = NAN;
blas::dot(x, y, multi::array_ref<float, 0>(res));
BOOST_TEST( res == std::inner_product(begin(x), end(x), begin(y), 0.0F) );
}
// BOOST_AUTO_TEST_CASE(blas_dot_no_context_out_param) {
// multi::array<float, 1> const x = {1.0F, 2.0F, 3.0F}; // NOLINT(readability-identifier-length) BLAS naming
// multi::array<float, 1> const y = {1.0F, 2.0F, 3.0F}; // NOLINT(readability-identifier-length) BLAS naming
// float res = NAN;
// blas::dot(x, y, multi::array_ref<float, 0>(res));
// BOOST_TEST( res == std::inner_product(begin(x), end(x), begin(y), 0.0F) );
// }

BOOST_AUTO_TEST_CASE(blas_dot_no_context_out_param_complex) { // if you get a segfaut here, your system may require -DRETURN_BY_STACK
using complex = std::complex<double>;
Expand Down Expand Up @@ -154,7 +155,7 @@ BOOST_AUTO_TEST_CASE(blas_dot_no_context_out_param_complex_C_thrust) {
}
#endif

BOOST_AUTO_TEST_CASE(multi_blas_dot_strided) {
BOOST_AUTO_TEST_CASE(multi_blas_dot_strided_double) {
multi::array<double, 2> const CA = {
{1.0, 2.0, 3.0, 4.0},
{5.0, 6.0, 7.0, 8.0},
Expand All @@ -168,19 +169,19 @@ BOOST_AUTO_TEST_CASE(multi_blas_dot_strided) {
BOOST_REQUIRE( res == res2 );
}

BOOST_AUTO_TEST_CASE(multi_blas_dot_strided_float) {
multi::array<float, 2> const CA = {
{1.0F, 2.0F, 3.0F, 4.0F},
{5.0F, 6.0F, 7.0F, 8.0F},
{9.0F, 10.0F, 11.0F, 12.0F},
};
auto res = std::numeric_limits<float>::quiet_NaN();
blas::dot_n(begin(CA[1]), size(CA[1]), begin(CA[2]), &res);
BOOST_REQUIRE( res == std::inner_product(begin(CA[1]), begin(CA[2]), end(CA[1]), 0.0F) );
// BOOST_AUTO_TEST_CASE(multi_blas_dot_strided_float) {
// multi::array<float, 2> const CA = {
// {1.0F, 2.0F, 3.0F, 4.0F},
// {5.0F, 6.0F, 7.0F, 8.0F},
// {9.0F, 10.0F, 11.0F, 12.0F},
// };
// auto res = std::numeric_limits<float>::quiet_NaN();
// blas::dot_n(begin(CA[1]), size(CA[1]), begin(CA[2]), &res);
// BOOST_REQUIRE( res == std::inner_product(begin(CA[1]), begin(CA[2]), end(CA[1]), 0.0F) );

double const res2 = blas::dot(CA[1], CA[2]);
BOOST_REQUIRE( res == res2 );
}
// double const res2 = blas::dot(CA[1], CA[2]);
// BOOST_REQUIRE( res == res2 );
// }

BOOST_AUTO_TEST_CASE(multi_blas_dot_strided_context) {
multi::array<double, 2> const CA = {
Expand All @@ -197,22 +198,22 @@ BOOST_AUTO_TEST_CASE(multi_blas_dot_strided_context) {
BOOST_REQUIRE( res == res2 );
}

BOOST_AUTO_TEST_CASE(multi_blas_dot_strided_context_float) {
multi::array<float, 2> const CA = {
{1.0F, 2.0F, 3.0F, 4.0F},
{5.0F, 6.0F, 7.0F, 8.0F},
{9.0F, 10.0F, 11.0F, 12.0F},
};
float res = std::numeric_limits<double>::quiet_NaN();
// BOOST_AUTO_TEST_CASE(multi_blas_dot_strided_context_float) {
// multi::array<float, 2> const CA = {
// {1.0F, 2.0F, 3.0F, 4.0F},
// {5.0F, 6.0F, 7.0F, 8.0F},
// {9.0F, 10.0F, 11.0F, 12.0F},
// };
// float res = std::numeric_limits<double>::quiet_NaN();

blas::context ctxt;
blas::dot_n(&ctxt, begin(CA[1]), size(CA[1]), begin(CA[2]), &res);
// blas::context ctxt;
// blas::dot_n(&ctxt, begin(CA[1]), size(CA[1]), begin(CA[2]), &res);

BOOST_REQUIRE( res == std::inner_product(begin(CA[1]), begin(CA[2]), end(CA[1]), 0.0) );
// BOOST_REQUIRE( res == std::inner_product(begin(CA[1]), begin(CA[2]), end(CA[1]), 0.0) );

float const res2 = blas::dot(CA[1], CA[2]);
BOOST_REQUIRE( res == res2 );
}
// float const res2 = blas::dot(CA[1], CA[2]);
// BOOST_REQUIRE( res == res2 );
// }

BOOST_AUTO_TEST_CASE(multi_blas_dot_1d_real_double) {
multi::array<double, 1> const x = {1.0, 2.0, 3.0}; // NOLINT(readability-identifier-length) BLAS naming
Expand All @@ -223,14 +224,14 @@ BOOST_AUTO_TEST_CASE(multi_blas_dot_1d_real_double) {
BOOST_TEST( dot(x, y) == 14.0F );
}

BOOST_AUTO_TEST_CASE(multi_blas_dot_1d_real_float) {
multi::array<float, 1> const x = {1.0F, 2.0F, 3.0F}; // NOLINT(readability-identifier-length) BLAS naming
multi::array<float, 1> const y = {1.0F, 2.0F, 3.0F}; // NOLINT(readability-identifier-length) BLAS naming
// BOOST_AUTO_TEST_CASE(multi_blas_dot_1d_real_float) {
// multi::array<float, 1> const x = {1.0F, 2.0F, 3.0F}; // NOLINT(readability-identifier-length) BLAS naming
// multi::array<float, 1> const y = {1.0F, 2.0F, 3.0F}; // NOLINT(readability-identifier-length) BLAS naming

using blas::dot;
BOOST_TEST( 14.0F == dot(x, y) );
BOOST_TEST( dot(x, y) == 14.0F );
}
// using blas::dot;
// BOOST_TEST( 14.0F == dot(x, y) );
// BOOST_TEST( dot(x, y) == 14.0F );
// }

BOOST_AUTO_TEST_CASE(multi_blas_dot_impl_real_double) {
multi::array<double, 2> const cA = {
Expand All @@ -255,29 +256,29 @@ BOOST_AUTO_TEST_CASE(multi_blas_dot_impl_real_double) {
BOOST_REQUIRE( blas::dot(cA[1], cA[2]) == blas::dot(cA[2], cA[1]) );
}

BOOST_AUTO_TEST_CASE(multi_blas_dot_impl_real_float) {
multi::array<float, 2> const cA = {
{1.0F, 2.0F, 3.0F, 4.0F},
{5.0F, 6.0F, 7.0F, 8.0F},
{9.0F, 10.0F, 11.0F, 12.0F},
};
// BOOST_AUTO_TEST_CASE(multi_blas_dot_impl_real_float) {
// multi::array<float, 2> const cA = {
// {1.0F, 2.0F, 3.0F, 4.0F},
// {5.0F, 6.0F, 7.0F, 8.0F},
// {9.0F, 10.0F, 11.0F, 12.0F},
// };

float const res1 = blas::dot(cA[1], cA[2]);
BOOST_REQUIRE( res1 == std::inner_product(begin(cA[1]), begin(cA[2]), end(cA[1]), 0.0F) );
// float const res1 = blas::dot(cA[1], cA[2]);
// BOOST_REQUIRE( res1 == std::inner_product(begin(cA[1]), begin(cA[2]), end(cA[1]), 0.0F) );

float res2 = NAN;
blas::dot(cA[1], cA[2], res2);
BOOST_REQUIRE( res2 == std::inner_product(begin(cA[1]), begin(cA[2]), end(cA[1]), 0.0F) );
// float res2 = NAN;
// blas::dot(cA[1], cA[2], res2);
// BOOST_REQUIRE( res2 == std::inner_product(begin(cA[1]), begin(cA[2]), end(cA[1]), 0.0F) );

float res_nan = NAN;
float const res3 = blas::dot(cA[1], cA[2], res_nan);
// float res_nan = NAN;
// float const res3 = blas::dot(cA[1], cA[2], res_nan);

BOOST_REQUIRE( res3 == res2 );
// BOOST_REQUIRE( res3 == res2 );

float const res4 = blas::dot(cA[1], cA[2]);
BOOST_REQUIRE( res4 == std::inner_product(begin(cA[1]), begin(cA[2]), end(cA[1]), 0.0F) );
BOOST_REQUIRE( blas::dot(cA[1], cA[2]) == blas::dot(cA[2], cA[1]) );
}
// float const res4 = blas::dot(cA[1], cA[2]);
// BOOST_REQUIRE( res4 == std::inner_product(begin(cA[1]), begin(cA[2]), end(cA[1]), 0.0F) );
// BOOST_REQUIRE( blas::dot(cA[1], cA[2]) == blas::dot(cA[2], cA[1]) );
// }

BOOST_AUTO_TEST_CASE(inq_case) {
multi::array<double, 1> const x(multi::extensions_t<1>{multi::iextension{10}}, +1.0); // NOLINT(readability-identifier-length) BLAS naming
Expand Down

0 comments on commit b77f0fe

Please sign in to comment.