Commit 56e160ba authored by Robert Kimball's avatar Robert Kimball Committed by Scott Cyphers

Change floating point comparisons from == to all_close_f (#2620)

* change float comparisons from == to all_close_f

* style

* address a few more direct float comparisons

* add missing include

* specify tightest tolerance for Broadcast and Reshape tests

* Increased tightness of float testing

Increased tightness of float testing via MIN_FLOAT_TOLERANCE_BITS parameter

* style
parent 665b9c95
......@@ -51,7 +51,7 @@ NGRAPH_TEST(${BACKEND_NAME}, create_tensor_1)
auto handle = backend->compile(f);
handle->call_with_validate({result}, {a, b});
vector<float> expected = {6, 8, 10, 12};
EXPECT_EQ(read_vector<float>(result), expected);
EXPECT_TRUE(test::all_close_f(read_vector<float>(result), expected, MIN_FLOAT_TOLERANCE_BITS));
}
// This tests a backend's implementation of the three parameter version of create_tensor
......@@ -74,7 +74,7 @@ NGRAPH_TEST(${BACKEND_NAME}, create_tensor_2)
auto handle = backend->compile(f);
handle->call_with_validate({result}, {a, b});
vector<float> expected = {6, 8, 10, 12};
EXPECT_EQ(read_vector<float>(result), expected);
EXPECT_TRUE(test::all_close_f(read_vector<float>(result), expected, MIN_FLOAT_TOLERANCE_BITS));
}
// This tests a backend's implementation of the copy_from for tensor
......
......@@ -53,8 +53,8 @@ NGRAPH_TEST(${BACKEND_NAME}, add)
auto handle = backend->compile(f);
handle->call_with_validate({result}, {a, b});
EXPECT_EQ(read_vector<float>(result),
(test::NDArray<float, 2>({{6, 8}, {10, 12}})).get_vector());
EXPECT_TRUE(test::all_close_f(read_vector<float>(result),
(test::NDArray<float, 2>({{6, 8}, {10, 12}})).get_vector()));
}
NGRAPH_TEST(${BACKEND_NAME}, add_overload)
......@@ -76,8 +76,8 @@ NGRAPH_TEST(${BACKEND_NAME}, add_overload)
auto handle = backend->compile(f);
handle->call_with_validate({result}, {a, b});
EXPECT_EQ(read_vector<float>(result),
(test::NDArray<float, 2>({{6, 8}, {10, 12}})).get_vector());
EXPECT_TRUE(test::all_close_f(read_vector<float>(result),
(test::NDArray<float, 2>({{6, 8}, {10, 12}})).get_vector()));
}
NGRAPH_TEST(${BACKEND_NAME}, multiply)
......@@ -99,8 +99,8 @@ NGRAPH_TEST(${BACKEND_NAME}, multiply)
auto handle = backend->compile(f);
handle->call_with_validate({result}, {a, b});
EXPECT_EQ(read_vector<float>(result),
(test::NDArray<float, 2>({{5, 12}, {21, 32}})).get_vector());
EXPECT_TRUE(test::all_close_f(read_vector<float>(result),
(test::NDArray<float, 2>({{5, 12}, {21, 32}})).get_vector()));
}
NGRAPH_TEST(${BACKEND_NAME}, multiply_overload)
......@@ -122,8 +122,8 @@ NGRAPH_TEST(${BACKEND_NAME}, multiply_overload)
auto handle = backend->compile(f);
handle->call_with_validate({result}, {a, b});
EXPECT_EQ(read_vector<float>(result),
(test::NDArray<float, 2>({{5, 12}, {21, 32}})).get_vector());
EXPECT_TRUE(test::all_close_f(read_vector<float>(result),
(test::NDArray<float, 2>({{5, 12}, {21, 32}})).get_vector()));
}
NGRAPH_TEST(${BACKEND_NAME}, divide)
......@@ -145,7 +145,7 @@ NGRAPH_TEST(${BACKEND_NAME}, divide)
auto handle = backend->compile(f);
handle->call_with_validate({result}, {a, b});
EXPECT_EQ((vector<float>{2, 2, 2, 2}), read_vector<float>(result));
EXPECT_TRUE(test::all_close_f((vector<float>{2, 2, 2, 2}), read_vector<float>(result)));
}
NGRAPH_TEST(${BACKEND_NAME}, divide_int32)
......@@ -189,7 +189,7 @@ NGRAPH_TEST(${BACKEND_NAME}, divide_overload)
auto handle = backend->compile(f);
handle->call_with_validate({result}, {a, b});
EXPECT_EQ((vector<float>{2, 2, 2, 2}), read_vector<float>(result));
EXPECT_TRUE(test::all_close_f((vector<float>{2, 2, 2, 2}), read_vector<float>(result)));
}
NGRAPH_TEST(${BACKEND_NAME}, divide_adjoint_stability)
......@@ -235,8 +235,10 @@ NGRAPH_TEST(${BACKEND_NAME}, divide_adjoint_stability)
auto handle = backend->compile(bf);
handle->call_with_validate({resulta, resultb}, {a, b, c});
EXPECT_EQ((vector<float>{0.5, 0.5, 0.5, 0.5}), read_vector<float>(resulta));
EXPECT_EQ((vector<float>{-0.0, -0.0, -0.25, -0.25}), read_vector<float>(resultb));
EXPECT_TRUE(
test::all_close_f((vector<float>{0.5, 0.5, 0.5, 0.5}), read_vector<float>(resulta)));
EXPECT_TRUE(
test::all_close_f((vector<float>{-0.0, -0.0, -0.25, -0.25}), read_vector<float>(resultb)));
}
NGRAPH_TEST(${BACKEND_NAME}, divide_by_zero_float32)
......@@ -283,7 +285,8 @@ NGRAPH_TEST(${BACKEND_NAME}, maximum)
auto handle = backend->compile(f);
handle->call_with_validate({result}, {a, b});
EXPECT_EQ((vector<float>{1, 8, 4, 17, 0, 0.5, 2, 1.5}), read_vector<float>(result));
EXPECT_TRUE(test::all_close_f((vector<float>{1, 8, 4, 17, 0, 0.5, 2, 1.5}),
read_vector<float>(result)));
}
NGRAPH_TEST(${BACKEND_NAME}, minimum)
......@@ -304,7 +307,8 @@ NGRAPH_TEST(${BACKEND_NAME}, minimum)
auto handle = backend->compile(f);
handle->call_with_validate({result}, {a, b});
EXPECT_EQ((vector<float>{1, 2, -8, 8, -.5, 0, 1, 1}), read_vector<float>(result));
EXPECT_TRUE(
test::all_close_f((vector<float>{1, 2, -8, 8, -.5, 0, 1, 1}), read_vector<float>(result)));
}
NGRAPH_TEST(${BACKEND_NAME}, minimum_int32)
......@@ -410,7 +414,7 @@ NGRAPH_TEST(${BACKEND_NAME}, power)
auto handle = backend->compile(f);
handle->call_with_validate({result}, {a, b});
EXPECT_TRUE(test::all_close(vector<float>{1, 1, 729, 125}, read_vector<float>(result)));
EXPECT_TRUE(test::all_close_f(vector<float>{1, 1, 729, 125}, read_vector<float>(result)));
}
NGRAPH_TEST(${BACKEND_NAME}, subtract)
......@@ -431,7 +435,7 @@ NGRAPH_TEST(${BACKEND_NAME}, subtract)
auto handle = backend->compile(f);
handle->call_with_validate({result}, {a, b});
EXPECT_EQ((vector<float>{1, 2, 4, 8}), read_vector<float>(result));
EXPECT_TRUE(test::all_close_f((vector<float>{1, 2, 4, 8}), read_vector<float>(result)));
}
NGRAPH_TEST(${BACKEND_NAME}, subtract_overload)
......@@ -452,5 +456,5 @@ NGRAPH_TEST(${BACKEND_NAME}, subtract_overload)
auto handle = backend->compile(f);
handle->call_with_validate({result}, {a, b});
EXPECT_EQ((vector<float>{1, 2, 4, 8}), read_vector<float>(result));
EXPECT_TRUE(test::all_close_f((vector<float>{1, 2, 4, 8}), read_vector<float>(result)));
}
......@@ -51,7 +51,8 @@ NGRAPH_TEST(${BACKEND_NAME}, broadcast_scalar_vector)
auto handle = backend->compile(f);
handle->call_with_validate({result}, {a});
EXPECT_EQ((vector<float>{6, 6, 6, 6}), read_vector<float>(result));
EXPECT_TRUE(test::all_close_f(
(vector<float>{6, 6, 6, 6}), read_vector<float>(result), MIN_FLOAT_TOLERANCE_BITS));
}
NGRAPH_TEST(${BACKEND_NAME}, broadcast_scalar_matrix)
......@@ -71,7 +72,8 @@ NGRAPH_TEST(${BACKEND_NAME}, broadcast_scalar_matrix)
auto handle = backend->compile(f);
handle->call_with_validate({result}, {a});
EXPECT_EQ((vector<float>{6, 6, 6, 6}), read_vector<float>(result));
EXPECT_TRUE(test::all_close_f(
(vector<float>{6, 6, 6, 6}), read_vector<float>(result), MIN_FLOAT_TOLERANCE_BITS));
}
NGRAPH_TEST(${BACKEND_NAME}, broadcast_scalar_tensor)
......@@ -91,7 +93,9 @@ NGRAPH_TEST(${BACKEND_NAME}, broadcast_scalar_tensor)
auto handle = backend->compile(f);
handle->call_with_validate({result}, {a});
EXPECT_EQ((vector<float>{6, 6, 6, 6, 6, 6, 6, 6}), read_vector<float>(result));
EXPECT_TRUE(test::all_close_f((vector<float>{6, 6, 6, 6, 6, 6, 6, 6}),
read_vector<float>(result),
MIN_FLOAT_TOLERANCE_BITS));
}
NGRAPH_TEST(${BACKEND_NAME}, broadcast_trivial)
......@@ -110,7 +114,9 @@ NGRAPH_TEST(${BACKEND_NAME}, broadcast_trivial)
auto handle = backend->compile(f);
handle->call_with_validate({result}, {a});
EXPECT_EQ((vector<float>{2, 4, 6, 8, 16, 32, 64, 128}), read_vector<float>(result));
EXPECT_TRUE(test::all_close_f((vector<float>{2, 4, 6, 8, 16, 32, 64, 128}),
read_vector<float>(result),
MIN_FLOAT_TOLERANCE_BITS));
}
NGRAPH_TEST(${BACKEND_NAME}, broadcast_vector_colwise)
......@@ -130,7 +136,9 @@ NGRAPH_TEST(${BACKEND_NAME}, broadcast_vector_colwise)
auto handle = backend->compile(f);
handle->call_with_validate({result}, {a});
EXPECT_EQ((vector<float>{1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3}), read_vector<float>(result));
EXPECT_TRUE(test::all_close_f((vector<float>{1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3}),
read_vector<float>(result),
MIN_FLOAT_TOLERANCE_BITS));
}
NGRAPH_TEST(${BACKEND_NAME}, broadcast_vector_rowwise)
......@@ -150,7 +158,9 @@ NGRAPH_TEST(${BACKEND_NAME}, broadcast_vector_rowwise)
auto handle = backend->compile(f);
handle->call_with_validate({result}, {a});
EXPECT_EQ((vector<float>{1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4}), read_vector<float>(result));
EXPECT_TRUE(test::all_close_f((vector<float>{1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4}),
read_vector<float>(result),
MIN_FLOAT_TOLERANCE_BITS));
}
// Test hybrid mechanism after broadcast
......@@ -172,7 +182,9 @@ NGRAPH_TEST(${BACKEND_NAME}, broadcast_vector_rowwise_reversed)
auto handle = backend->compile(f);
handle->call_with_validate({result}, {a});
EXPECT_EQ((vector<float>{4, 3, 2, 1, 4, 3, 2, 1, 4, 3, 2, 1}), read_vector<float>(result));
EXPECT_TRUE(test::all_close_f((vector<float>{4, 3, 2, 1, 4, 3, 2, 1, 4, 3, 2, 1}),
read_vector<float>(result),
MIN_FLOAT_TOLERANCE_BITS));
}
NGRAPH_TEST(${BACKEND_NAME}, broadcast_vector_rowwise_int64)
......@@ -261,7 +273,8 @@ static void broadcast_test_helper(const Shape& shape_a, const Shape& shape_r, co
auto ref_handle = ref_backend->compile(f);
wrk_handle->call_with_validate({wrk_result}, {wrk_a});
ref_handle->call_with_validate({ref_result}, {ref_a});
EXPECT_EQ(read_vector<float>(ref_result), read_vector<float>(wrk_result));
EXPECT_TRUE(test::all_close_f(
read_vector<float>(ref_result), read_vector<float>(wrk_result), MIN_FLOAT_TOLERANCE_BITS));
}
NGRAPH_TEST(${BACKEND_NAME}, broadcast_algo_vector_middle)
......@@ -400,7 +413,9 @@ NGRAPH_TEST(${BACKEND_NAME}, broadcast_matrix_0)
auto handle = backend->compile(f);
handle->call_with_validate({result}, {a});
EXPECT_EQ((vector<float>{1, 2, 3, 4, 1, 2, 3, 4}), read_vector<float>(result));
EXPECT_TRUE(test::all_close_f((vector<float>{1, 2, 3, 4, 1, 2, 3, 4}),
read_vector<float>(result),
MIN_FLOAT_TOLERANCE_BITS));
}
NGRAPH_TEST(${BACKEND_NAME}, broadcast_matrix_1)
......@@ -420,7 +435,9 @@ NGRAPH_TEST(${BACKEND_NAME}, broadcast_matrix_1)
auto handle = backend->compile(f);
handle->call_with_validate({result}, {a});
EXPECT_EQ((vector<float>{1, 2, 1, 2, 3, 4, 3, 4}), read_vector<float>(result));
EXPECT_TRUE(test::all_close_f((vector<float>{1, 2, 1, 2, 3, 4, 3, 4}),
read_vector<float>(result),
MIN_FLOAT_TOLERANCE_BITS));
}
NGRAPH_TEST(${BACKEND_NAME}, broadcast_matrix_2)
......@@ -440,7 +457,9 @@ NGRAPH_TEST(${BACKEND_NAME}, broadcast_matrix_2)
auto handle = backend->compile(f);
handle->call_with_validate({result}, {a});
EXPECT_EQ((vector<float>{1, 1, 2, 2, 3, 3, 4, 4}), read_vector<float>(result));
EXPECT_TRUE(test::all_close_f((vector<float>{1, 1, 2, 2, 3, 3, 4, 4}),
read_vector<float>(result),
MIN_FLOAT_TOLERANCE_BITS));
}
NGRAPH_TEST(${BACKEND_NAME}, constant_broadcast)
......
......@@ -93,7 +93,7 @@ NGRAPH_TEST(${BACKEND_NAME}, dot_4d_5d_multi_axis)
auto handle = backend->compile(f);
handle->call_with_validate({result}, {a, b});
EXPECT_EQ(
EXPECT_TRUE(test::all_close_f(
(vector<float>{6942., 7020., 7098., 7176., 7254., 7332., 7410., 7488., 7566.,
7644., 7722., 7800., 16590., 16812., 17034., 17256., 17478., 17700.,
17922., 18144., 18366., 18588., 18810., 19032., 26238., 26604., 26970.,
......@@ -102,7 +102,7 @@ NGRAPH_TEST(${BACKEND_NAME}, dot_4d_5d_multi_axis)
40476., 40986., 41496., 45534., 46188., 46842., 47496., 48150., 48804.,
49458., 50112., 50766., 51420., 52074., 52728., 55182., 55980., 56778.,
57576., 58374., 59172., 59970., 60768., 61566., 62364., 63162., 63960.}),
read_vector<float>(result));
read_vector<float>(result)));
}
//
......@@ -153,7 +153,7 @@ NGRAPH_TEST(${BACKEND_NAME}, dot_4d_5d_multi_axis_more)
auto handle = backend->compile(f);
handle->call_with_validate({result}, {a, b});
EXPECT_EQ((vector<float>{251412., 254040.}), read_vector<float>(result));
EXPECT_TRUE(test::all_close_f((vector<float>{251412., 254040.}), read_vector<float>(result)));
}
//
......@@ -216,7 +216,7 @@ NGRAPH_TEST(DISABLED_${BACKEND_NAME}, dot_4d_5d_multi_axis_big_fp64_VERY_SLOW)
auto handle = backend->compile(f);
handle->call_with_validate({result}, {a, b});
EXPECT_TRUE(test::all_close(
EXPECT_TRUE(test::all_close_f(
vector<double>{
2.48832025919525478400e+18, 2.48832051839533977600e+18, 2.48832077759658444800e+18,
2.48832103679413504000e+18, 2.48832129599669350400e+18, 2.48832155519793971200e+18,
......@@ -250,7 +250,7 @@ NGRAPH_TEST(${BACKEND_NAME}, dot_0_0)
auto handle = backend->compile(f);
handle->call_with_validate({result}, {a, b});
EXPECT_EQ((vector<float>{0}), read_vector<float>(result));
EXPECT_TRUE(test::all_close_f((vector<float>{0}), read_vector<float>(result)));
}
NGRAPH_TEST(${BACKEND_NAME}, dot_matrix_2x0_0x2)
......@@ -277,7 +277,7 @@ NGRAPH_TEST(${BACKEND_NAME}, dot_matrix_2x0_0x2)
auto handle = backend->compile(f);
handle->call_with_validate({result}, {a, b});
EXPECT_EQ((vector<float>{0, 0, 0, 0}), read_vector<float>(result));
EXPECT_TRUE(test::all_close_f((vector<float>{0, 0, 0, 0}), read_vector<float>(result)));
}
NGRAPH_TEST(${BACKEND_NAME}, dot_matrix_0x2_2x0)
......@@ -301,7 +301,7 @@ NGRAPH_TEST(${BACKEND_NAME}, dot_matrix_0x2_2x0)
auto handle = backend->compile(f);
handle->call_with_validate({result}, {a, b});
EXPECT_EQ((vector<float>{}), read_vector<float>(result));
EXPECT_TRUE(test::all_close_f((vector<float>{}), read_vector<float>(result)));
}
NGRAPH_TEST(${BACKEND_NAME}, dot_matrix_3x2_2x0)
......@@ -325,7 +325,7 @@ NGRAPH_TEST(${BACKEND_NAME}, dot_matrix_3x2_2x0)
auto handle = backend->compile(f);
handle->call_with_validate({result}, {a, b});
EXPECT_EQ((vector<float>{}), read_vector<float>(result));
EXPECT_TRUE(test::all_close_f((vector<float>{}), read_vector<float>(result)));
}
NGRAPH_TEST(${BACKEND_NAME}, dot_scalar_0x2)
......@@ -348,7 +348,7 @@ NGRAPH_TEST(${BACKEND_NAME}, dot_scalar_0x2)
auto handle = backend->compile(f);
handle->call_with_validate({result}, {a, b});
EXPECT_EQ((vector<float>{}), read_vector<float>(result));
EXPECT_TRUE(test::all_close_f((vector<float>{}), read_vector<float>(result)));
}
NGRAPH_TEST(${BACKEND_NAME}, dot_2x0_0)
......@@ -374,7 +374,7 @@ NGRAPH_TEST(${BACKEND_NAME}, dot_2x0_0)
auto handle = backend->compile(f);
handle->call_with_validate({result}, {a, b});
EXPECT_EQ((vector<float>{0, 0}), read_vector<float>(result));
EXPECT_TRUE(test::all_close_f((vector<float>{0, 0}), read_vector<float>(result)));
}
NGRAPH_TEST(${BACKEND_NAME}, dot1d)
......@@ -396,7 +396,7 @@ NGRAPH_TEST(${BACKEND_NAME}, dot1d)
auto handle = backend->compile(f);
handle->call_with_validate({result}, {a, b});
EXPECT_EQ((vector<float>{170}), read_vector<float>(result));
EXPECT_TRUE(test::all_close_f((vector<float>{170}), read_vector<float>(result)));
}
NGRAPH_TEST(${BACKEND_NAME}, dot2d)
......@@ -418,7 +418,7 @@ NGRAPH_TEST(${BACKEND_NAME}, dot2d)
auto handle = backend->compile(f);
handle->call_with_validate({result}, {a, b});
EXPECT_EQ((vector<float>{19, 22, 43, 50}), read_vector<float>(result));
EXPECT_TRUE(test::all_close_f((vector<float>{19, 22, 43, 50}), read_vector<float>(result)));
}
//
......@@ -463,8 +463,9 @@ NGRAPH_TEST(${BACKEND_NAME}, dot3d_3d)
auto handle = backend->compile(f);
handle->call_with_validate({result}, {a, b});
EXPECT_EQ((vector<float>{11, 14, 17, 20, 23, 30, 37, 44, 35, 46, 57, 68, 47, 62, 77, 92}),
read_vector<float>(result));
EXPECT_TRUE(test::all_close_f(
(vector<float>{11, 14, 17, 20, 23, 30, 37, 44, 35, 46, 57, 68, 47, 62, 77, 92}),
read_vector<float>(result)));
}
//
......@@ -511,10 +512,11 @@ NGRAPH_TEST(${BACKEND_NAME}, dot3d_2d)
auto handle = backend->compile(f);
handle->call_with_validate({result}, {a, b});
EXPECT_EQ((vector<float>{20, 23, 26, 29, 56, 68, 80, 92, 92, 113, 134,
155, 128, 158, 188, 218, 164, 203, 242, 281, 200, 248,
296, 344, 236, 293, 350, 407, 272, 338, 404, 470}),
read_vector<float>(result));
EXPECT_TRUE(
test::all_close_f((vector<float>{20, 23, 26, 29, 56, 68, 80, 92, 92, 113, 134,
155, 128, 158, 188, 218, 164, 203, 242, 281, 200, 248,
296, 344, 236, 293, 350, 407, 272, 338, 404, 470}),
read_vector<float>(result)));
}
NGRAPH_TEST(${BACKEND_NAME}, dot_scalar_tensor_arg0)
......@@ -536,7 +538,8 @@ NGRAPH_TEST(${BACKEND_NAME}, dot_scalar_tensor_arg0)
auto handle = backend->compile(f);
handle->call_with_validate({result}, {a, b});
EXPECT_EQ((vector<float>{6, 12, 18, 24, 30, 36, 42, 48}), read_vector<float>(result));
EXPECT_TRUE(test::all_close_f((vector<float>{6, 12, 18, 24, 30, 36, 42, 48}),
read_vector<float>(result)));
}
NGRAPH_TEST(${BACKEND_NAME}, dot_scalar_tensor_arg1)
......@@ -558,7 +561,8 @@ NGRAPH_TEST(${BACKEND_NAME}, dot_scalar_tensor_arg1)
auto handle = backend->compile(f);
handle->call_with_validate({result}, {a, b});
EXPECT_EQ((vector<float>{6, 12, 18, 24, 30, 36, 42, 48}), read_vector<float>(result));
EXPECT_TRUE(test::all_close_f((vector<float>{6, 12, 18, 24, 30, 36, 42, 48}),
read_vector<float>(result)));
}
NGRAPH_TEST(${BACKEND_NAME}, dot_scalar_scalar)
......@@ -579,7 +583,7 @@ NGRAPH_TEST(${BACKEND_NAME}, dot_scalar_scalar)
auto handle = backend->compile(f);
handle->call_with_validate({result}, {a, b});
EXPECT_EQ((vector<float>{48}), read_vector<float>(result));
EXPECT_TRUE(test::all_close_f((vector<float>{48}), read_vector<float>(result)));
}
NGRAPH_TEST(${BACKEND_NAME}, dot_matrix_vector_4_3)
......@@ -602,7 +606,7 @@ NGRAPH_TEST(${BACKEND_NAME}, dot_matrix_vector_4_3)
auto handle = backend->compile(f);
handle->call_with_validate({result}, {a, b});
EXPECT_EQ((vector<float>{110, 272, 434, 596}), read_vector<float>(result));
EXPECT_TRUE(test::all_close_f((vector<float>{110, 272, 434, 596}), read_vector<float>(result)));
}
NGRAPH_TEST(${BACKEND_NAME}, dot_matrix_vector)
......@@ -625,7 +629,8 @@ NGRAPH_TEST(${BACKEND_NAME}, dot_matrix_vector)
auto handle = backend->compile(f);
handle->call_with_validate({result}, {a, b});
EXPECT_EQ((vector<float>{190, 486, 782, 1078}), read_vector<float>(result));
EXPECT_TRUE(
test::all_close_f((vector<float>{190, 486, 782, 1078}), read_vector<float>(result)));
}
NGRAPH_TEST(${BACKEND_NAME}, dot_matrix_vector_int64)
......@@ -700,8 +705,9 @@ NGRAPH_TEST(${BACKEND_NAME}, dot_3d_multi_axis)
auto handle = backend->compile(f);
handle->call_with_validate({result}, {a, b});
EXPECT_EQ((vector<float>{2938., 3016., 3094., 3172., 3250., 7042., 7264., 7486., 7708., 7930.}),
read_vector<float>(result));
EXPECT_TRUE(test::all_close_f(
(vector<float>{2938., 3016., 3094., 3172., 3250., 7042., 7264., 7486., 7708., 7930.}),
read_vector<float>(result)));
}
//
......@@ -750,10 +756,11 @@ NGRAPH_TEST(${BACKEND_NAME}, dot_3d_one_axis_arbitrary)
auto handle = backend->compile(f);
handle->call_with_validate({result}, {a, b});
EXPECT_EQ((vector<float>{483, 189, 331, 86, 85, 1262, 2155, 354, 83, 18, 58, 543, 77,
241, 325, 286, 859, 144, 438, 1025, 317, 973, 1041, 2930, 163, 69,
117, 50, 29, 472, 819, 62, 785, 236, 476, 235, 175, 1521, 2387,
1402, 97, 29, 69, 412, 63, 286, 429, 218, 45, 11, 29, 162,
27, 106, 149, 126, 65, 25, 44, 6, 11, 165, 281, 52}),
read_vector<float>(result));
EXPECT_TRUE(test::all_close_f(
(vector<float>{483, 189, 331, 86, 85, 1262, 2155, 354, 83, 18, 58, 543, 77,
241, 325, 286, 859, 144, 438, 1025, 317, 973, 1041, 2930, 163, 69,
117, 50, 29, 472, 819, 62, 785, 236, 476, 235, 175, 1521, 2387,
1402, 97, 29, 69, 412, 63, 286, 429, 218, 45, 11, 29, 162,
27, 106, 149, 126, 65, 25, 44, 6, 11, 165, 281, 52}),
read_vector<float>(result)));
}
......@@ -57,7 +57,7 @@ NGRAPH_TEST(${BACKEND_NAME}, embedding_lookup_4x5_reverse)
auto handle = backend->compile(f0);
handle->call_with_validate({result0}, {a, b});
vector<float> expected{16, 17, 18, 19, 20, 11, 12, 13, 14, 15, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5};
EXPECT_TRUE(test::all_close(expected, read_vector<float>(result0)));
EXPECT_TRUE(test::all_close_f(expected, read_vector<float>(result0), MIN_FLOAT_TOLERANCE_BITS));
}
NGRAPH_TEST(${BACKEND_NAME}, embedding_lookup_10x1_arbitrary)
......@@ -80,7 +80,7 @@ NGRAPH_TEST(${BACKEND_NAME}, embedding_lookup_10x1_arbitrary)
auto handle = backend->compile(f0);
handle->call_with_validate({result0}, {a, b});
vector<float> expected{9, 2, 1, 0, 3, 5, 4, 6, 8, 7};
EXPECT_TRUE(test::all_close(expected, read_vector<float>(result0)));
EXPECT_TRUE(test::all_close_f(expected, read_vector<float>(result0), MIN_FLOAT_TOLERANCE_BITS));
}
NGRAPH_TEST(${BACKEND_NAME}, embedding_lookup_10x1_arbitrary_index_type_int)
......@@ -104,5 +104,5 @@ NGRAPH_TEST(${BACKEND_NAME}, embedding_lookup_10x1_arbitrary_index_type_int)
handle->call_with_validate({result0}, {a, b});
//vector<float> expected{9.5, 2.5, 1.5, 0.5, 3.5, 5.5, 4.5, 6.5, 8.5, 7.5};
vector<float> expected{9.5, 2.5, 1.5, 0.5, 3.5, 5.5, 4.5, 6.5, 8.5, 7.5};
EXPECT_TRUE(test::all_close(expected, read_vector<float>(result0)));
EXPECT_TRUE(test::all_close_f(expected, read_vector<float>(result0), MIN_FLOAT_TOLERANCE_BITS));
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -49,7 +49,8 @@ NGRAPH_TEST(${BACKEND_NAME}, abs)
auto handle = backend->compile(f);
handle->call_with_validate({result}, {a});
EXPECT_EQ((vector<float>{1, 2, 0, 4.75f}), read_vector<float>(result));
EXPECT_TRUE(test::all_close_f(
(vector<float>{1, 2, 0, 4.75f}), read_vector<float>(result), MIN_FLOAT_TOLERANCE_BITS));
}
NGRAPH_TEST(${BACKEND_NAME}, acos)
......@@ -154,7 +155,9 @@ NGRAPH_TEST(${BACKEND_NAME}, ceiling)
auto handle = backend->compile(f);
handle->call_with_validate({result}, {a});
EXPECT_EQ((vector<float>{-2.0f, -2.0f, 1.0f, 5.0f}), read_vector<float>(result));
EXPECT_TRUE(test::all_close_f((vector<float>{-2.0f, -2.0f, 1.0f, 5.0f}),
read_vector<float>(result),
MIN_FLOAT_TOLERANCE_BITS));
}
NGRAPH_TEST(${BACKEND_NAME}, cos)
......@@ -243,7 +246,9 @@ NGRAPH_TEST(${BACKEND_NAME}, floor)
auto handle = backend->compile(f);
handle->call_with_validate({result}, {a});
EXPECT_EQ((vector<float>{-3.0f, -2.0f, 0.0f, 4.0f}), read_vector<float>(result));
EXPECT_TRUE(test::all_close_f((vector<float>{-3.0f, -2.0f, 0.0f, 4.0f}),
read_vector<float>(result),
MIN_FLOAT_TOLERANCE_BITS));
}
NGRAPH_TEST(${BACKEND_NAME}, floor_int32)
......@@ -306,7 +311,9 @@ NGRAPH_TEST(${BACKEND_NAME}, negative)
auto handle = backend->compile(f);
handle->call_with_validate({result}, {a});
EXPECT_EQ((vector<float>{-1, 2, 0, 4.75f, -8.75f, 8.75f}), read_vector<float>(result));
EXPECT_TRUE(test::all_close_f((vector<float>{-1, 2, 0, 4.75f, -8.75f, 8.75f}),
read_vector<float>(result),
MIN_FLOAT_TOLERANCE_BITS));
}
NGRAPH_TEST(${BACKEND_NAME}, not)
......@@ -342,7 +349,8 @@ NGRAPH_TEST(${BACKEND_NAME}, sign)
auto handle = backend->compile(f);
handle->call_with_validate({result}, {a});
EXPECT_EQ((vector<float>{1, -1, 0, -1, 1, 0}), read_vector<float>(result));
EXPECT_TRUE(test::all_close_f(
(vector<float>{1, -1, 0, -1, 1, 0}), read_vector<float>(result), MIN_FLOAT_TOLERANCE_BITS));
}
NGRAPH_TEST(${BACKEND_NAME}, sin)
......
......@@ -18,6 +18,7 @@
#include "gtest/gtest.h"
#include "ngraph/ngraph.hpp"
#include "ngraph/pass/manager.hpp"
#include "util/all_close_f.hpp"
#include "util/test_tools.hpp"
using namespace ngraph;
......@@ -45,7 +46,7 @@ TEST(constant_folding, constant_reshape)
ASSERT_TRUE(new_const);
auto values_out = new_const->get_vector<float>();
ASSERT_EQ(values_in, values_out);
ASSERT_TRUE(test::all_close_f(values_in, values_out, MIN_FLOAT_TOLERANCE_BITS));
}
TEST(constant_folding, constant_reshape_permute)
......@@ -71,7 +72,7 @@ TEST(constant_folding, constant_reshape_permute)
auto values_out = new_const->get_vector<double>();
vector<double> values_permute{0, 4, 1, 5, 2, 6, 3, 7};
ASSERT_EQ(values_permute, values_out);
ASSERT_TRUE(test::all_close_f(values_permute, values_out, MIN_FLOAT_TOLERANCE_BITS));
}
TEST(constant_folding, constant_broadcast)
......
......@@ -16,7 +16,7 @@
#include "gtest/gtest.h"
#include "ngraph/ngraph.hpp"
#include "util/all_close.hpp"
#include "util/all_close_f.hpp"
#include "util/ndarray.hpp"
using namespace ngraph;
......@@ -45,14 +45,17 @@ TEST(cpu_codegen, abc)
ngraph::pass::PassConfig pass_config{ngraph::pass::CompilationMode::CODEGEN};
auto handle = backend->compile(f, pass_config);
handle->call_with_validate({result}, {a, b, c});
EXPECT_EQ(read_vector<float>(result),
(test::NDArray<float, 2>({{54, 80}, {110, 144}})).get_vector());
EXPECT_TRUE(test::all_close_f(read_vector<float>(result),
(test::NDArray<float, 2>({{54, 80}, {110, 144}})).get_vector(),
MIN_FLOAT_TOLERANCE_BITS));
handle->call_with_validate({result}, {b, a, c});
EXPECT_EQ(read_vector<float>(result),
(test::NDArray<float, 2>({{54, 80}, {110, 144}})).get_vector());
EXPECT_TRUE(test::all_close_f(read_vector<float>(result),
(test::NDArray<float, 2>({{54, 80}, {110, 144}})).get_vector(),
MIN_FLOAT_TOLERANCE_BITS));
handle->call_with_validate({result}, {a, c, b});
EXPECT_EQ(read_vector<float>(result),
(test::NDArray<float, 2>({{50, 72}, {98, 128}})).get_vector());
EXPECT_TRUE(test::all_close_f(read_vector<float>(result),
(test::NDArray<float, 2>({{50, 72}, {98, 128}})).get_vector(),
MIN_FLOAT_TOLERANCE_BITS));
}
......@@ -81,6 +81,7 @@
#include "ngraph/util.hpp"
#include "nlohmann/json.hpp"
#include "util/all_close.hpp"
#include "util/all_close_f.hpp"
#include "util/autodiff/backprop_function.hpp"
#include "util/autodiff/numeric_compare.hpp"
#include "util/matcher.hpp"
......@@ -167,7 +168,7 @@ TEST(cpu_fusion, gemm_cpu_broadcast_row)
auto handle = backend->compile(f);
handle->call_with_validate({result}, {a, b});
vector<float> expected{11, 30, 38, 111};
EXPECT_EQ(read_vector<float>(result), expected);
EXPECT_TRUE(test::all_close_f(read_vector<float>(result), expected, MIN_FLOAT_TOLERANCE_BITS));
}
TEST(cpu_fusion, gemm_cpu_broadcast_column)
......@@ -199,7 +200,7 @@ TEST(cpu_fusion, gemm_cpu_broadcast_column)
auto handle = backend->compile(f);
handle->call_with_validate({result}, {a, b});
vector<float> expected{11, 29, 39, 111};
EXPECT_EQ(read_vector<float>(result), expected);
EXPECT_TRUE(test::all_close_f(read_vector<float>(result), expected, MIN_FLOAT_TOLERANCE_BITS));
}
TEST(cpu_fusion, gemm_cpu_broadcast_matrix)
......@@ -235,7 +236,7 @@ TEST(cpu_fusion, gemm_cpu_broadcast_matrix)
auto handle = backend->compile(f);
handle->call_with_validate({result}, {a, b});
vector<float> expected{10, 28, 37, 109};
ASSERT_TRUE(read_vector<float>(result) == expected);
EXPECT_TRUE(test::all_close_f(read_vector<float>(result), expected, MIN_FLOAT_TOLERANCE_BITS));
}
TEST(cpu_fusion, gemm_cpu_no_bias)
......@@ -268,7 +269,7 @@ TEST(cpu_fusion, gemm_cpu_no_bias)
auto handle = backend->compile(f);
handle->call_with_validate({result}, {a, b});
vector<float> expected{9, 27, 36, 108};
ASSERT_TRUE(read_vector<float>(result) == expected);
EXPECT_TRUE(test::all_close_f(read_vector<float>(result), expected, MIN_FLOAT_TOLERANCE_BITS));
}
TEST(cpu_fusion, cpu_fusion_pass_basic)
......@@ -1500,7 +1501,7 @@ TEST(cpu_fusion, backwards_maxpool_with_indices_n4_c1_hw4_2x2_max)
auto handle = backend->compile(df);
handle->call_with_validate({output}, {input, ep});
ASSERT_TRUE(read_vector<float>(output) == expected);
EXPECT_TRUE(test::all_close_f(read_vector<float>(output), expected, MIN_FLOAT_TOLERANCE_BITS));
}
#if defined(NGRAPH_HALIDE)
......@@ -1587,7 +1588,7 @@ TEST(cpu_fusion, loop_kernel_embedded_graph_halide)
vector<float> expected{-2, -6, -4, -8};
auto handle = backend->compile(f);
handle->call_with_validate({result}, {a, b});
EXPECT_EQ(read_vector<float>(result), expected);
EXPECT_TRUE(test::all_close_f(read_vector<float>(result), expected, MIN_FLOAT_TOLERANCE_BITS));
}
TEST(cpu_fusion, loop_kernel_two_inputs_one_output_halide)
......@@ -1614,7 +1615,7 @@ TEST(cpu_fusion, loop_kernel_two_inputs_one_output_halide)
auto handle = backend->compile(f);
handle->call_with_validate({result}, {a, b});
EXPECT_EQ(read_vector<float>(result), expected);
EXPECT_TRUE(test::all_close_f(read_vector<float>(result), expected, MIN_FLOAT_TOLERANCE_BITS));
}
TEST(cpu_fusion, loop_kernel_multiple_outputs_halide)
......@@ -1670,9 +1671,9 @@ TEST(cpu_fusion, loop_kernel_multiple_outputs_halide)
vector<float> expected1{5, 11, 5, 17};
vector<float> expected2{2, 7, 5, 14};
vector<float> expected3{-3, -3, -3, -9};
EXPECT_EQ(read_vector<float>(r1), expected1);
EXPECT_EQ(read_vector<float>(r2), expected2);
EXPECT_EQ(read_vector<float>(r3), expected3);
EXPECT_TRUE(test::all_close_f(read_vector<float>(r1), expected1, MIN_FLOAT_TOLERANCE_BITS));
EXPECT_TRUE(test::all_close_f(read_vector<float>(r2), expected2, MIN_FLOAT_TOLERANCE_BITS));
EXPECT_TRUE(test::all_close_f(read_vector<float>(r3), expected3, MIN_FLOAT_TOLERANCE_BITS));
}
TEST(cpu_fusion, loop_kernel_copy_with_new_args)
......@@ -2167,7 +2168,7 @@ TEST(cpu_fusion, group_convolution)
auto handle = backend->compile(f);
handle->call_with_validate({group_result, lower_result, upper_result},
{a_, b_, c_, d_, e_, f_});
ASSERT_EQ(rv, erv);
EXPECT_TRUE(test::all_close_f(rv, erv));
}
TEST(cpu_fusion, rnn_fprop_1_lstm_cell)
......
......@@ -38,6 +38,7 @@
#include "ngraph/util.hpp"
#include "nlohmann/json.hpp"
#include "util/all_close.hpp"
#include "util/all_close_f.hpp"
#include "util/autodiff/backprop_function.hpp"
#include "util/autodiff/numeric_compare.hpp"
#include "util/ndarray.hpp"
......@@ -149,16 +150,16 @@ TEST(cpu_test, abc_tbb)
auto handle = backend->compile(f);
handle->call_with_validate({result}, {a, b, c});
EXPECT_EQ(read_vector<float>(result),
(test::NDArray<float, 2>({{54, 80}, {110, 144}})).get_vector());
EXPECT_TRUE(test::all_close_f(read_vector<float>(result),
(test::NDArray<float, 2>({{54, 80}, {110, 144}})).get_vector()));
handle->call_with_validate({result}, {b, a, c});
EXPECT_EQ(read_vector<float>(result),
(test::NDArray<float, 2>({{54, 80}, {110, 144}})).get_vector());
EXPECT_TRUE(test::all_close_f(read_vector<float>(result),
(test::NDArray<float, 2>({{54, 80}, {110, 144}})).get_vector()));
handle->call_with_validate({result}, {a, c, b});
EXPECT_EQ(read_vector<float>(result),
(test::NDArray<float, 2>({{50, 72}, {98, 128}})).get_vector());
EXPECT_TRUE(test::all_close_f(read_vector<float>(result),
(test::NDArray<float, 2>({{50, 72}, {98, 128}})).get_vector()));
if (!use_tbb)
{
......@@ -219,7 +220,7 @@ TEST(cpu_test, mkldnn_layouts)
auto handle = backend->compile(f);
handle->call_with_validate({result}, {a, b});
EXPECT_EQ(vector<float>{expected_result}, rv);
EXPECT_TRUE(test::all_close_f(vector<float>{expected_result}, rv));
}
TEST(cpu_test, reshape_layout_optimizations1)
......@@ -776,7 +777,7 @@ TEST(cpu_test, memory_reuse_destructive_oi_relu)
shared_ptr<runtime::Executable> handle = backend->compile(f);
handle->call_with_validate({result}, {a, b, c});
ASSERT_NE(handle, nullptr);
EXPECT_EQ(read_vector<float>(result), expected);
EXPECT_TRUE(test::all_close_f(read_vector<float>(result), expected));
}
TEST(cpu_test, memory_reuse_cacheable_no_destructive_oi_relu)
......@@ -805,12 +806,12 @@ TEST(cpu_test, memory_reuse_cacheable_no_destructive_oi_relu)
shared_ptr<runtime::Executable> handle = backend->compile(f);
ASSERT_NE(handle, nullptr);
handle->call_with_validate({result}, {a, b, c});
EXPECT_EQ(read_vector<float>(result), expected);
EXPECT_TRUE(test::all_close_f(read_vector<float>(result), expected));
a->set_stale(false);
b->set_stale(false);
handle->call_with_validate({result}, {a, b, c});
EXPECT_EQ(read_vector<float>(result), expected);
EXPECT_TRUE(test::all_close_f(read_vector<float>(result), expected));
}
TEST(cpu_test, memory_reuse_in_place_concat_after_in_place_slice)
......@@ -833,8 +834,9 @@ TEST(cpu_test, memory_reuse_in_place_concat_after_in_place_slice)
shared_ptr<runtime::Executable> handle = backend->compile(f);
handle->call_with_validate({result}, {a});
EXPECT_EQ((vector<float>{1, 2, 3, 4, 5, 6, 7, 8, 5, 6, 7, 8, 9, 10, 11, 12}),
read_vector<float>(result));
EXPECT_TRUE(
test::all_close_f((vector<float>{1, 2, 3, 4, 5, 6, 7, 8, 5, 6, 7, 8, 9, 10, 11, 12}),
read_vector<float>(result)));
}
TEST(cpu_test, memory_reuse_in_place_slice_after_in_place_concat)
......@@ -868,7 +870,7 @@ TEST(cpu_test, memory_reuse_in_place_slice_after_in_place_concat)
shared_ptr<runtime::Executable> handle = backend->compile(f);
ASSERT_NE(handle, nullptr);
handle->call_with_validate({result}, {a, b, c, d});
EXPECT_EQ((vector<float>{3, 7}), read_vector<float>(result));
EXPECT_TRUE(test::all_close_f((vector<float>{3, 7}), read_vector<float>(result)));
}
TEST(cpu_test, convert_inplace)
......
......@@ -24,6 +24,7 @@
#include "ngraph/file_util.hpp"
#include "ngraph/ngraph.hpp"
#include "ngraph/serializer.hpp"
#include "util/all_close_f.hpp"
#include "util/random.hpp"
using namespace std;
......@@ -52,6 +53,6 @@ TEST(distributed_${BACKEND_NAME}, allreduce)
auto handle = backend->compile(f);
handle->call_with_validate({result}, {a});
EXPECT_EQ(v, read_vector<float>(result));
EXPECT_TRUE(test::all_close_f(v, read_vector<float>(result)));
}
}
......@@ -131,5 +131,6 @@ TEST(HYBRID, abc)
auto handle = backend->compile(f);
handle->call_with_validate({result1, result2}, {a, b, c, d});
EXPECT_EQ(read_vector<float>(result2), (vector<float>{150, 576, 1176, 1536}));
EXPECT_TRUE(
test::all_close_f(read_vector<float>(result2), (vector<float>{150, 576, 1176, 1536})));
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment