#include "gtest/gtest.h"
#include "ngraph/ngraph.hpp"
-#include "ngraph/runtime/tensor.hpp"
-#include "runtime/backend.hpp"
-#include "util/all_close.hpp"
-#include "util/all_close_f.hpp"
-#include "util/known_element_types.hpp"
-#include "util/ndarray.hpp"
+#include "util/engine/test_engines.hpp"
+#include "util/test_case.hpp"
#include "util/test_control.hpp"
-#include "util/test_tools.hpp"
NGRAPH_SUPPRESS_DEPRECATED_START
using namespace ngraph;
static string s_manifest = "${MANIFEST}";
+using TestEngine = test::ENGINE_CLASS_NAME(${BACKEND_NAME});
// Trivial case with no reduced axes.
NGRAPH_TEST(${BACKEND_NAME}, max_trivial)
auto A = make_shared<op::Parameter>(element::f32, shape);
auto f = make_shared<Function>(make_shared<op::Max>(A, AxisSet{}), ParameterVector{A});
- auto backend = runtime::Backend::create("${BACKEND_NAME}");
+ std::vector<float> a{1, 2, 3, 4};
- // Create some tensors for input/output
- auto a = backend->create_tensor(element::f32, shape);
- copy_data(a, vector<float>{1, 2, 3, 4});
- auto result = backend->create_tensor(element::f32, shape);
-
- auto handle = backend->compile(f);
- handle->call_with_validate({result}, {a});
- EXPECT_TRUE(test::all_close_f(
- (vector<float>{1, 2, 3, 4}), read_vector<float>(result), MIN_FLOAT_TOLERANCE_BITS));
+ auto test_case = test::TestCase<TestEngine>(f);
+ test_case.add_input<float>({a});
+ test_case.add_expected_output<float>(shape, {1, 2, 3, 4});
+ test_case.run(MIN_FLOAT_TOLERANCE_BITS);
}
NGRAPH_TEST(${BACKEND_NAME}, max_trivial_int8)
auto A = make_shared<op::Parameter>(element::i8, shape);
auto f = make_shared<Function>(make_shared<op::Max>(A, AxisSet{}), ParameterVector{A});
- auto backend = runtime::Backend::create("${BACKEND_NAME}");
-
- // Create some tensors for input/output
- auto a = backend->create_tensor(element::i8, shape);
- copy_data(a, vector<int8_t>{1, 2, 3, 4});
- auto result = backend->create_tensor(element::i8, shape);
+ std::vector<int8_t> a{1, 2, 3, 4};
- auto handle = backend->compile(f);
- handle->call_with_validate({result}, {a});
- EXPECT_EQ((vector<int8_t>{1, 2, 3, 4}), read_vector<int8_t>(result));
+ auto test_case = test::TestCase<TestEngine>(f);
+ test_case.add_input<int8_t>({a});
+ test_case.add_expected_output<int8_t>(shape, {1, 2, 3, 4});
+ test_case.run();
}
// Failure has been reported at 5D for some reason
auto A = make_shared<op::Parameter>(element::f32, shape);
auto f = make_shared<Function>(make_shared<op::Max>(A, AxisSet{}), ParameterVector{A});
- auto backend = runtime::Backend::create("${BACKEND_NAME}");
+ std::vector<float> a{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
- // Create some tensors for input/output
- auto a = backend->create_tensor(element::f32, shape);
- copy_data(a, vector<float>{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1});
- auto result = backend->create_tensor(element::f32, shape);
-
- auto handle = backend->compile(f);
- handle->call_with_validate({result}, {a});
- EXPECT_TRUE(test::all_close_f((vector<float>{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}),
- read_vector<float>(result),
- MIN_FLOAT_TOLERANCE_BITS));
+ auto test_case = test::TestCase<TestEngine>(f);
+ test_case.add_input<float>({a});
+ test_case.add_expected_output<float>(shape, {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1});
+ test_case.run(MIN_FLOAT_TOLERANCE_BITS);
}
NGRAPH_TEST(${BACKEND_NAME}, max_trivial_5d_int32)
auto A = make_shared<op::Parameter>(element::i32, shape);
auto f = make_shared<Function>(make_shared<op::Max>(A, AxisSet{}), ParameterVector{A});
- auto backend = runtime::Backend::create("${BACKEND_NAME}");
-
- // Create some tensors for input/output
- auto a = backend->create_tensor(element::i32, shape);
- copy_data(a, vector<int32_t>{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1});
- auto result = backend->create_tensor(element::i32, shape);
+ std::vector<int32_t> a{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
- auto handle = backend->compile(f);
- handle->call_with_validate({result}, {a});
- EXPECT_EQ((vector<int32_t>{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}),
- read_vector<int32_t>(result));
+ auto test_case = test::TestCase<TestEngine>(f);
+ test_case.add_input<int32_t>({a});
+ test_case.add_expected_output<int32_t>(shape, {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1});
+ test_case.run();
}
NGRAPH_TEST(${BACKEND_NAME}, max_to_scalar)
auto A = make_shared<op::Parameter>(element::f32, shape);
auto f = make_shared<Function>(make_shared<op::Max>(A, AxisSet{0, 1}), ParameterVector{A});
- auto backend = runtime::Backend::create("${BACKEND_NAME}");
+ std::vector<float> a{1, 2, 3, 4};
- // Create some tensors for input/output
- auto a = backend->create_tensor(element::f32, shape);
- copy_data(a, vector<float>{1, 2, 3, 4});
- auto result = backend->create_tensor(element::f32, Shape{});
-
- auto handle = backend->compile(f);
- handle->call_with_validate({result}, {a});
- EXPECT_TRUE(test::all_close_f((vector<float>{4}), read_vector<float>(result)));
-
- // For some reason I'm feeling extra paranoid about making sure reduction doesn't clobber the
- // input tensors, so let's do this too.
- EXPECT_TRUE(test::all_close_f(
- (vector<float>{1, 2, 3, 4}), read_vector<float>(a), MIN_FLOAT_TOLERANCE_BITS));
+ auto test_case = test::TestCase<TestEngine>(f);
+ test_case.add_input<float>(a);
+ test_case.add_expected_output<float>(Shape{}, {4});
+ test_case.run();
}
NGRAPH_TEST(${BACKEND_NAME}, max_to_scalar_int8)
auto A = make_shared<op::Parameter>(element::i8, shape);
auto f = make_shared<Function>(make_shared<op::Max>(A, AxisSet{0, 1}), ParameterVector{A});
- auto backend = runtime::Backend::create("${BACKEND_NAME}");
+ std::vector<int8_t> a{1, 2, 3, 4};
- // Create some tensors for input/output
- auto a = backend->create_tensor(element::i8, shape);
- copy_data(a, vector<int8_t>{1, 2, 3, 4});
- auto result = backend->create_tensor(element::i8, Shape{});
-
- auto handle = backend->compile(f);
- handle->call_with_validate({result}, {a});
- EXPECT_EQ((vector<int8_t>{4}), read_vector<int8_t>(result));
+ auto test_case = test::TestCase<TestEngine>(f);
+ test_case.add_input<int8_t>({a});
+ test_case.add_expected_output<int8_t>(shape, {4});
+ test_case.run();
}
NGRAPH_TEST(${BACKEND_NAME}, max_matrix_columns)
Shape shape_rt{2};
auto f = make_shared<Function>(make_shared<op::Max>(A, AxisSet{0}), ParameterVector{A});
- auto backend = runtime::Backend::create("${BACKEND_NAME}");
-
- // Create some tensors for input/output
- auto a = backend->create_tensor(element::f32, shape_a);
- copy_data(a, vector<float>{1, 2, 3, 4, 5, 6});
- auto result = backend->create_tensor(element::f32, shape_rt);
+ std::vector<float> a{1, 2, 3, 4, 5, 6};
- auto handle = backend->compile(f);
- handle->call_with_validate({result}, {a});
- EXPECT_TRUE(test::all_close_f((vector<float>{5, 6}), read_vector<float>(result)));
-
- // For some reason I'm feeling extra paranoid about making sure reduction doesn't clobber the
- // input tensors, so let's do this too.
- EXPECT_TRUE(test::all_close_f(
- (vector<float>{1, 2, 3, 4, 5, 6}), read_vector<float>(a), MIN_FLOAT_TOLERANCE_BITS));
+ auto test_case = test::TestCase<TestEngine>(f);
+ test_case.add_input<float>({a});
+ test_case.add_expected_output<float>(shape_rt, {5, 6});
+ test_case.run();
}
NGRAPH_TEST(${BACKEND_NAME}, max_matrix_rows)
Shape shape_rt{3};
auto f = make_shared<Function>(make_shared<op::Max>(A, AxisSet{1}), ParameterVector{A});
- auto backend = runtime::Backend::create("${BACKEND_NAME}");
-
- // Create some tensors for input/output
- auto a = backend->create_tensor(element::f32, shape_a);
- copy_data(a, vector<float>{1, 2, 3, 4, 5, 6});
- auto result = backend->create_tensor(element::f32, shape_rt);
+ std::vector<float> a{1, 2, 3, 4, 5, 6};
- auto handle = backend->compile(f);
- handle->call_with_validate({result}, {a});
- EXPECT_TRUE(test::all_close_f((vector<float>{2, 4, 6}), read_vector<float>(result)));
-
- // For some reason I'm feeling extra paranoid about making sure reduction doesn't clobber the
- // input tensors, so let's do this too.
- EXPECT_TRUE(test::all_close_f(
- (vector<float>{1, 2, 3, 4, 5, 6}), read_vector<float>(a), MIN_FLOAT_TOLERANCE_BITS));
+ auto test_case = test::TestCase<TestEngine>(f);
+ test_case.add_input<float>({a});
+ test_case.add_expected_output<float>(shape_rt, {2, 4, 6});
+ test_case.run();
}
NGRAPH_TEST(${BACKEND_NAME}, max_matrix_rows_int32)
Shape shape_rt{3};
auto f = make_shared<Function>(make_shared<op::Max>(A, AxisSet{1}), ParameterVector{A});
- auto backend = runtime::Backend::create("${BACKEND_NAME}");
-
- // Create some tensors for input/output
- auto a = backend->create_tensor(element::i32, shape_a);
- copy_data(a, vector<int32_t>{1, 2, 3, 4, 5, 6});
- auto result = backend->create_tensor(element::i32, shape_rt);
+ std::vector<int32_t> a{1, 2, 3, 4, 5, 6};
- auto handle = backend->compile(f);
- handle->call_with_validate({result}, {a});
- EXPECT_EQ((vector<int32_t>{2, 4, 6}), read_vector<int32_t>(result));
-
- // For some reason I'm feeling extra paranoid about making sure reduction doesn't clobber the
- // input tensors, so let's do this too.
- EXPECT_EQ((vector<int32_t>{1, 2, 3, 4, 5, 6}), read_vector<int32_t>(a));
+ auto test_case = test::TestCase<TestEngine>(f);
+ test_case.add_input<int32_t>({a});
+ test_case.add_expected_output<int32_t>(shape_rt, {2, 4, 6});
+ test_case.run();
}
NGRAPH_TEST(${BACKEND_NAME}, max_matrix_rows_zero)
Shape shape_rt{3};
auto f = make_shared<Function>(make_shared<op::Max>(A, AxisSet{1}), ParameterVector{A});
- auto backend = runtime::Backend::create("${BACKEND_NAME}");
-
- // Create some tensors for input/output
- auto a = backend->create_tensor(element::f32, shape_a);
- copy_data(a, vector<float>{});
- auto result = backend->create_tensor(element::f32, shape_rt);
- copy_data(result, vector<float>({3, 3, 3}));
-
- auto handle = backend->compile(f);
- handle->call_with_validate({result}, {a});
- EXPECT_EQ((vector<float>{-std::numeric_limits<float>::infinity(),
- -std::numeric_limits<float>::infinity(),
- -std::numeric_limits<float>::infinity()}),
- read_vector<float>(result));
-
- // For some reason I'm feeling extra paranoid about making sure reduction doesn't clobber the
- // input tensors, so let's do this too.
- EXPECT_TRUE(
- test::all_close_f((vector<float>{}), read_vector<float>(a), MIN_FLOAT_TOLERANCE_BITS));
+ std::vector<float> a{};
+
+ auto test_case = test::TestCase<TestEngine>(f);
+ test_case.add_input<float>({a});
+ test_case.add_expected_output<float>(shape_rt,
+ {-std::numeric_limits<float>::infinity(),
+ -std::numeric_limits<float>::infinity(),
+ -std::numeric_limits<float>::infinity()});
+ test_case.run();
}
NGRAPH_TEST(${BACKEND_NAME}, max_matrix_rows_zero_int32)
Shape shape_rt{3};
auto f = make_shared<Function>(make_shared<op::Max>(A, AxisSet{1}), ParameterVector{A});
- auto backend = runtime::Backend::create("${BACKEND_NAME}");
-
- // Create some tensors for input/output
- auto a = backend->create_tensor(element::i32, shape_a);
- copy_data(a, vector<int32_t>{});
- auto result = backend->create_tensor(element::i32, shape_rt);
- copy_data(result, vector<int32_t>({3, 3, 3}));
+ std::vector<int32_t> a{};
int32_t minval = std::numeric_limits<int32_t>::has_infinity
? -std::numeric_limits<int32_t>::infinity()
: std::numeric_limits<int32_t>::min();
- auto handle = backend->compile(f);
- handle->call_with_validate({result}, {a});
- EXPECT_EQ((vector<int32_t>{minval, minval, minval}), read_vector<int32_t>(result));
- EXPECT_EQ((vector<int32_t>{}), read_vector<int32_t>(a));
+ auto test_case = test::TestCase<TestEngine>(f);
+ test_case.add_input<int32_t>({a});
+ test_case.add_expected_output<int32_t>(shape_rt, {minval, minval, minval});
+ test_case.run();
}
NGRAPH_TEST(${BACKEND_NAME}, max_matrix_cols_zero)
Shape shape_rt{2};
auto f = make_shared<Function>(make_shared<op::Max>(A, AxisSet{0}), ParameterVector{A});
- auto backend = runtime::Backend::create("${BACKEND_NAME}");
-
- // Create some tensors for input/output
- auto a = backend->create_tensor(element::f32, shape_a);
- copy_data(a, vector<float>{});
- auto result = backend->create_tensor(element::f32, shape_rt);
- copy_data(result, vector<float>({3, 3}));
+ std::vector<float> a{};
- auto handle = backend->compile(f);
- handle->call_with_validate({result}, {a});
- EXPECT_EQ((vector<float>{-std::numeric_limits<float>::infinity(),
- -std::numeric_limits<float>::infinity()}),
- read_vector<float>(result));
-
- // For some reason I'm feeling extra paranoid about making sure reduction doesn't clobber the
- // input tensors, so let's do this too.
- EXPECT_TRUE(
- test::all_close_f((vector<float>{}), read_vector<float>(a), MIN_FLOAT_TOLERANCE_BITS));
+ auto test_case = test::TestCase<TestEngine>(f);
+ test_case.add_input<float>({a});
+ test_case.add_expected_output<float>(
+ shape_rt,
+ {-std::numeric_limits<float>::infinity(), -std::numeric_limits<float>::infinity()});
+ test_case.run();
}
NGRAPH_TEST(${BACKEND_NAME}, max_vector_zero)
Shape shape_rt{};
auto f = make_shared<Function>(make_shared<op::Max>(A, AxisSet{0}), ParameterVector{A});
- auto backend = runtime::Backend::create("${BACKEND_NAME}");
-
- // Create some tensors for input/output
- auto a = backend->create_tensor(element::f32, shape_a);
- copy_data(a, vector<float>{});
- auto result = backend->create_tensor(element::f32, shape_rt);
- copy_data(result, vector<float>({3}));
+ std::vector<float> a{};
- auto handle = backend->compile(f);
- handle->call_with_validate({result}, {a});
- EXPECT_EQ((vector<float>{-std::numeric_limits<float>::infinity()}), read_vector<float>(result));
-
- // For some reason I'm feeling extra paranoid about making sure reduction doesn't clobber the
- // input tensors, so let's do this too.
- EXPECT_TRUE(
- test::all_close_f((vector<float>{}), read_vector<float>(a), MIN_FLOAT_TOLERANCE_BITS));
+ auto test_case = test::TestCase<TestEngine>(f);
+ test_case.add_input<float>({a});
+ test_case.add_expected_output<float>(shape_rt, {-std::numeric_limits<float>::infinity()});
+ test_case.run();
}
NGRAPH_TEST(${BACKEND_NAME}, max_matrix_to_scalar_zero_by_zero)
Shape shape_rt{};
auto f = make_shared<Function>(make_shared<op::Max>(A, AxisSet{0, 1}), ParameterVector{A});
- auto backend = runtime::Backend::create("${BACKEND_NAME}");
-
- // Create some tensors for input/output
- auto a = backend->create_tensor(element::f32, shape_a);
- copy_data(a, vector<float>{});
- auto result = backend->create_tensor(element::f32, shape_rt);
- copy_data(result, vector<float>({3}));
+ std::vector<float> a{};
- auto handle = backend->compile(f);
- handle->call_with_validate({result}, {a});
- EXPECT_EQ((vector<float>{-std::numeric_limits<float>::infinity()}), read_vector<float>(result));
-
- // For some reason I'm feeling extra paranoid about making sure reduction doesn't clobber the
- // input tensors, so let's do this too.
- EXPECT_TRUE(
- test::all_close_f((vector<float>{}), read_vector<float>(a), MIN_FLOAT_TOLERANCE_BITS));
+ auto test_case = test::TestCase<TestEngine>(f);
+ test_case.add_input<float>({a});
+ test_case.add_expected_output<float>(shape_rt, {-std::numeric_limits<float>::infinity()});
+ test_case.run();
}
NGRAPH_TEST(${BACKEND_NAME}, max_3d_to_matrix_most_sig)
Shape shape_rt{3, 3};
auto f = make_shared<Function>(make_shared<op::Max>(A, AxisSet{0}), ParameterVector{A});
- auto backend = runtime::Backend::create("${BACKEND_NAME}");
-
- // Create some tensors for input/output
- auto a = backend->create_tensor(element::f32, shape_a);
- copy_data(a, vector<float>{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
- 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27});
- auto result = backend->create_tensor(element::f32, shape_rt);
+ std::vector<float> a{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
+ 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27};
- auto handle = backend->compile(f);
- handle->call_with_validate({result}, {a});
- EXPECT_TRUE(test::all_close_f((vector<float>{19, 20, 21, 22, 23, 24, 25, 26, 27}),
- read_vector<float>(result),
- MIN_FLOAT_TOLERANCE_BITS));
+ auto test_case = test::TestCase<TestEngine>(f);
+ test_case.add_input<float>({a});
+ test_case.add_expected_output<float>(shape_rt, {19, 20, 21, 22, 23, 24, 25, 26, 27});
+ test_case.run(MIN_FLOAT_TOLERANCE_BITS);
}
NGRAPH_TEST(${BACKEND_NAME}, max_3d_to_matrix_least_sig)
Shape shape_rt{3, 3};
auto f = make_shared<Function>(make_shared<op::Max>(A, AxisSet{2}), ParameterVector{A});
- auto backend = runtime::Backend::create("${BACKEND_NAME}");
+ std::vector<float> a{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
+ 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27};
- // Create some tensors for input/output
- auto a = backend->create_tensor(element::f32, shape_a);
- copy_data(a, vector<float>{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
- 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27});
- auto result = backend->create_tensor(element::f32, shape_rt);
-
- auto handle = backend->compile(f);
- handle->call_with_validate({result}, {a});
- EXPECT_TRUE(test::all_close_f((vector<float>{3, 6, 9, 12, 15, 18, 21, 24, 27}),
- read_vector<float>(result),
- MIN_FLOAT_TOLERANCE_BITS));
+ auto test_case = test::TestCase<TestEngine>(f);
+ test_case.add_input<float>({a});
+ test_case.add_expected_output<float>(shape_rt, {3, 6, 9, 12, 15, 18, 21, 24, 27});
+ test_case.run(MIN_FLOAT_TOLERANCE_BITS);
}
NGRAPH_TEST(${BACKEND_NAME}, max_3d_to_vector)
auto A = make_shared<op::Parameter>(element::f32, shape_a);
Shape shape_rt{3};
auto f = make_shared<Function>(make_shared<op::Max>(A, AxisSet{0, 1}), ParameterVector{A});
+ std::vector<float> a{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
+ 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27};
- auto backend = runtime::Backend::create("${BACKEND_NAME}");
-
- // Create some tensors for input/output
- auto a = backend->create_tensor(element::f32, shape_a);
- copy_data(a, vector<float>{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
- 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27});
- auto result = backend->create_tensor(element::f32, shape_rt);
-
- auto handle = backend->compile(f);
- handle->call_with_validate({result}, {a});
- EXPECT_TRUE(test::all_close_f((vector<float>{25.0f, 26.0f, 27.0f}),
- read_vector<float>(result),
- MIN_FLOAT_TOLERANCE_BITS));
+ auto test_case = test::TestCase<TestEngine>(f);
+ test_case.add_input<float>({a});
+ test_case.add_expected_output<float>(shape_rt, {25.0f, 26.0f, 27.0f});
+ test_case.run(MIN_FLOAT_TOLERANCE_BITS);
}
NGRAPH_TEST(${BACKEND_NAME}, max_3d_to_scalar)
Shape shape_rt{};
auto f = make_shared<Function>(make_shared<op::Max>(A, AxisSet{0, 1, 2}), ParameterVector{A});
- auto backend = runtime::Backend::create("${BACKEND_NAME}");
-
- // Create some tensors for input/output
- auto a = backend->create_tensor(element::f32, shape_a);
- copy_data(a, vector<float>{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
- 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1});
- auto result = backend->create_tensor(element::f32, shape_rt);
+ std::vector<float> a{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
+ 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1};
- auto handle = backend->compile(f);
- handle->call_with_validate({result}, {a});
- EXPECT_TRUE(test::all_close_f(
- (vector<float>{14.0f}), read_vector<float>(result), MIN_FLOAT_TOLERANCE_BITS));
+ auto test_case = test::TestCase<TestEngine>(f);
+ test_case.add_input<float>({a});
+ test_case.add_expected_output<float>(shape_rt, {14.0f});
+ test_case.run(MIN_FLOAT_TOLERANCE_BITS);
}
NGRAPH_TEST(${BACKEND_NAME}, max_3d_to_scalar_int32)
Shape shape_rt{};
auto f = make_shared<Function>(make_shared<op::Max>(A, AxisSet{0, 1, 2}), ParameterVector{A});
- auto backend = runtime::Backend::create("${BACKEND_NAME}");
+ std::vector<int32_t> a{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
+ 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1};
- // Create some tensors for input/output
- auto a = backend->create_tensor(element::i32, shape_a);
- copy_data(a, vector<int32_t>{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
- 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1});
- auto result = backend->create_tensor(element::i32, shape_rt);
-
- auto handle = backend->compile(f);
- handle->call_with_validate({result}, {a});
- EXPECT_EQ((vector<int32_t>{14}), read_vector<int32_t>(result));
+ auto test_case = test::TestCase<TestEngine>(f);
+ test_case.add_input<int32_t>({a});
+ test_case.add_expected_output<int32_t>(shape_rt, {14});
+ test_case.run();
}
NGRAPH_TEST(${BACKEND_NAME}, max_3d_to_scalar_double)
Shape shape_rt{};
auto f = make_shared<Function>(make_shared<op::Max>(A, AxisSet{0, 1, 2}), ParameterVector{A});
- auto backend = runtime::Backend::create("${BACKEND_NAME}");
-
- // Create some tensors for input/output
- auto a = backend->create_tensor(element::f64, shape_a);
- copy_data(a, vector<double>{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
- 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1});
- auto result = backend->create_tensor(element::f64, shape_rt);
+std:
+ vector<double> a{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
+ 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1};
- auto handle = backend->compile(f);
- handle->call_with_validate({result}, {a});
- EXPECT_TRUE(test::all_close_f((vector<double>{14}), read_vector<double>(result)));
+ auto test_case = test::TestCase<TestEngine>(f);
+ test_case.add_input<double>({a});
+ test_case.add_expected_output<double>(shape_rt, {14});
+ test_case.run();
}
NGRAPH_TEST(${BACKEND_NAME}, max_3d_eliminate_zero_dim)
Shape shape_rt{3, 2};
auto f = make_shared<Function>(make_shared<op::Max>(A, AxisSet{1}), ParameterVector{A});
- auto backend = runtime::Backend::create("${BACKEND_NAME}");
-
- // Create some tensors for input/output
- auto a = backend->create_tensor(element::f32, shape_a);
- copy_data(a, vector<float>{});
- auto result = backend->create_tensor(element::f32, shape_rt);
-
- // Overwrite the initial result vector to make sure we're not just coincidentally getting the
- // right value.
- copy_data(result, vector<float>{2112, 2112, 2112, 2112, 2112, 2112});
-
- float mi = -std::numeric_limits<float>::infinity();
-
- auto handle = backend->compile(f);
- handle->call_with_validate({result}, {a});
- EXPECT_EQ((vector<float>{mi, mi, mi, mi, mi, mi}), read_vector<float>(result));
+ std::vector<float> a{};
+
+ auto test_case = test::TestCase<TestEngine>(f);
+ test_case.add_input<float>({a});
+ test_case.add_expected_output<float>(shape_rt,
+ {-std::numeric_limits<float>::infinity(),
+ -std::numeric_limits<float>::infinity(),
+ -std::numeric_limits<float>::infinity(),
+ -std::numeric_limits<float>::infinity(),
+ -std::numeric_limits<float>::infinity(),
+ -std::numeric_limits<float>::infinity()});
+ test_case.run();
}
#include "gtest/gtest.h"
#include "ngraph/ngraph.hpp"
-#include "ngraph/runtime/tensor.hpp"
-#include "runtime/backend.hpp"
-#include "util/all_close.hpp"
-#include "util/all_close_f.hpp"
-#include "util/known_element_types.hpp"
-#include "util/ndarray.hpp"
+#include "util/engine/test_engines.hpp"
+#include "util/test_case.hpp"
#include "util/test_control.hpp"
-#include "util/test_tools.hpp"
NGRAPH_SUPPRESS_DEPRECATED_START
using namespace ngraph;
static string s_manifest = "${MANIFEST}";
+using TestEngine = test::ENGINE_CLASS_NAME(${BACKEND_NAME});
// Trivial case with no reduced axes.
NGRAPH_TEST(${BACKEND_NAME}, min_trivial)
auto A = make_shared<op::Parameter>(element::f32, shape);
auto f = make_shared<Function>(make_shared<op::Min>(A, AxisSet{}), ParameterVector{A});
- auto backend = runtime::Backend::create("${BACKEND_NAME}");
+ std::vector<float> a{1, 2, 3, 4};
- // Create some tensors for input/output
- auto a = backend->create_tensor(element::f32, shape);
- copy_data(a, vector<float>{1, 2, 3, 4});
- auto result = backend->create_tensor(element::f32, shape);
-
- auto handle = backend->compile(f);
- handle->call_with_validate({result}, {a});
- EXPECT_TRUE(test::all_close_f(
- (vector<float>{1, 2, 3, 4}), read_vector<float>(result), MIN_FLOAT_TOLERANCE_BITS));
+ auto test_case = test::TestCase<TestEngine>(f);
+ test_case.add_input<float>({a});
+ test_case.add_expected_output<float>(shape, {1, 2, 3, 4});
+ test_case.run(MIN_FLOAT_TOLERANCE_BITS);
}
// Failure has been reported at 5D for some reason
Shape shape{2, 2, 2, 2, 2};
auto A = make_shared<op::Parameter>(element::f32, shape);
auto f = make_shared<Function>(make_shared<op::Min>(A, AxisSet{}), ParameterVector{A});
-
- auto backend = runtime::Backend::create("${BACKEND_NAME}");
-
- // Create some tensors for input/output
- auto a = backend->create_tensor(element::f32, shape);
- copy_data(a, vector<float>{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1});
- auto result = backend->create_tensor(element::f32, shape);
-
- auto handle = backend->compile(f);
- handle->call_with_validate({result}, {a});
- EXPECT_TRUE(test::all_close_f((vector<float>{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}),
- read_vector<float>(result),
- MIN_FLOAT_TOLERANCE_BITS));
+ std::vector<float> a{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
+
+ auto test_case = test::TestCase<TestEngine>(f);
+ test_case.add_input<float>({a});
+ test_case.add_expected_output<float>(shape, {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1});
+ test_case.run(MIN_FLOAT_TOLERANCE_BITS);
}
NGRAPH_TEST(${BACKEND_NAME}, min_trivial_5d_int32)
auto A = make_shared<op::Parameter>(element::i32, shape);
auto f = make_shared<Function>(make_shared<op::Min>(A, AxisSet{}), ParameterVector{A});
- auto backend = runtime::Backend::create("${BACKEND_NAME}");
+ std::vector<int32_t> a{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
- // Create some tensors for input/output
- auto a = backend->create_tensor(element::i32, shape);
- copy_data(a, vector<int32_t>{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1});
- auto result = backend->create_tensor(element::i32, shape);
-
- auto handle = backend->compile(f);
- handle->call_with_validate({result}, {a});
- EXPECT_EQ((vector<int32_t>{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}),
- read_vector<int32_t>(result));
+ auto test_case = test::TestCase<TestEngine>(f);
+ test_case.add_input<int32_t>({a});
+ test_case.add_expected_output<int32_t>(shape, {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1});
+ test_case.run();
}
NGRAPH_TEST(${BACKEND_NAME}, min_to_scalar)
auto A = make_shared<op::Parameter>(element::f32, shape);
auto f = make_shared<Function>(make_shared<op::Min>(A, AxisSet{0, 1}), ParameterVector{A});
- auto backend = runtime::Backend::create("${BACKEND_NAME}");
-
- // Create some tensors for input/output
- auto a = backend->create_tensor(element::f32, shape);
- copy_data(a, vector<float>{1, 2, 3, 4});
- auto result = backend->create_tensor(element::f32, Shape{});
+ std::vector<float> a{1, 2, 3, 4};
- auto handle = backend->compile(f);
- handle->call_with_validate({result}, {a});
- EXPECT_TRUE(test::all_close_f(
- (vector<float>{1}), read_vector<float>(result), MIN_FLOAT_TOLERANCE_BITS));
-
- // For some reason I'm feeling extra paranoid about making sure reduction doesn't clobber the
- // input tensors, so let's do this too.
- EXPECT_TRUE(test::all_close_f(
- (vector<float>{1, 2, 3, 4}), read_vector<float>(a), MIN_FLOAT_TOLERANCE_BITS));
+ auto test_case = test::TestCase<TestEngine>(f);
+ test_case.add_input<float>({a});
+ test_case.add_expected_output<float>(Shape{}, {1});
+ test_case.run(MIN_FLOAT_TOLERANCE_BITS);
}
NGRAPH_TEST(${BACKEND_NAME}, min_to_scalar_int8)
auto A = make_shared<op::Parameter>(element::i8, shape);
auto f = make_shared<Function>(make_shared<op::Min>(A, AxisSet{0, 1}), ParameterVector{A});
- auto backend = runtime::Backend::create("${BACKEND_NAME}");
-
- // Create some tensors for input/output
- auto a = backend->create_tensor(element::i8, shape);
- copy_data(a, vector<int8_t>{1, 2, 3, 4});
- auto result = backend->create_tensor(element::i8, Shape{});
+ std::vector<int8_t> a{1, 2, 3, 4};
- auto handle = backend->compile(f);
- handle->call_with_validate({result}, {a});
- EXPECT_EQ((vector<int8_t>{1}), read_vector<int8_t>(result));
-
- // For some reason I'm feeling extra paranoid about making sure reduction doesn't clobber the
- // input tensors, so let's do this too.
- EXPECT_EQ((vector<int8_t>{1, 2, 3, 4}), read_vector<int8_t>(a));
+ auto test_case = test::TestCase<TestEngine>(f);
+ test_case.add_input<int8_t>({a});
+ test_case.add_expected_output<int8_t>(Shape{}, {1});
+ test_case.run();
}
NGRAPH_TEST(${BACKEND_NAME}, min_matrix_columns)
Shape shape_rt{2};
auto f = make_shared<Function>(make_shared<op::Min>(A, AxisSet{0}), ParameterVector{A});
- auto backend = runtime::Backend::create("${BACKEND_NAME}");
-
- // Create some tensors for input/output
- auto a = backend->create_tensor(element::f32, shape_a);
- copy_data(a, vector<float>{1, 2, 3, 4, 5, 6});
- auto result = backend->create_tensor(element::f32, shape_rt);
+ std::vector<float> a{1, 2, 3, 4, 5, 6};
- auto handle = backend->compile(f);
- handle->call_with_validate({result}, {a});
- EXPECT_TRUE(test::all_close_f(
- (vector<float>{1, 2}), read_vector<float>(result), MIN_FLOAT_TOLERANCE_BITS));
-
- // For some reason I'm feeling extra paranoid about making sure reduction doesn't clobber the
- // input tensors, so let's do this too.
- EXPECT_TRUE(test::all_close_f(
- (vector<float>{1, 2, 3, 4, 5, 6}), read_vector<float>(a), MIN_FLOAT_TOLERANCE_BITS));
+ auto test_case = test::TestCase<TestEngine>(f);
+ test_case.add_input<float>({a});
+ test_case.add_expected_output<float>(shape_rt, {1, 2});
+ test_case.run(MIN_FLOAT_TOLERANCE_BITS);
}
NGRAPH_TEST(${BACKEND_NAME}, min_matrix_rows)
Shape shape_rt{3};
auto f = make_shared<Function>(make_shared<op::Min>(A, AxisSet{1}), ParameterVector{A});
- auto backend = runtime::Backend::create("${BACKEND_NAME}");
-
- // Create some tensors for input/output
- auto a = backend->create_tensor(element::f32, shape_a);
- copy_data(a, vector<float>{1, 2, 3, 4, 5, 6});
- auto result = backend->create_tensor(element::f32, shape_rt);
+ std::vector<float> a{1, 2, 3, 4, 5, 6};
- auto handle = backend->compile(f);
- handle->call_with_validate({result}, {a});
- EXPECT_TRUE(test::all_close_f(
- (vector<float>{1, 3, 5}), read_vector<float>(result), MIN_FLOAT_TOLERANCE_BITS));
-
- // For some reason I'm feeling extra paranoid about making sure reduction doesn't clobber the
- // input tensors, so let's do this too.
- EXPECT_TRUE(test::all_close_f(
- (vector<float>{1, 2, 3, 4, 5, 6}), read_vector<float>(a), MIN_FLOAT_TOLERANCE_BITS));
+ auto test_case = test::TestCase<TestEngine>(f);
+ test_case.add_input<float>({a});
+ test_case.add_expected_output<float>(shape_rt, {1, 3, 5});
+ test_case.run(MIN_FLOAT_TOLERANCE_BITS);
}
NGRAPH_TEST(${BACKEND_NAME}, min_matrix_rows_int32)
Shape shape_rt{3};
auto f = make_shared<Function>(make_shared<op::Min>(A, AxisSet{1}), ParameterVector{A});
- auto backend = runtime::Backend::create("${BACKEND_NAME}");
-
- // Create some tensors for input/output
- auto a = backend->create_tensor(element::i32, shape_a);
- copy_data(a, vector<int32_t>{1, 2, 3, 4, 5, 6});
- auto result = backend->create_tensor(element::i32, shape_rt);
-
- auto handle = backend->compile(f);
- handle->call_with_validate({result}, {a});
- EXPECT_EQ((vector<int32_t>{1, 3, 5}), read_vector<int32_t>(result));
+ std::vector<int32_t> a{1, 2, 3, 4, 5, 6};
- // For some reason I'm feeling extra paranoid about making sure reduction doesn't clobber the
- // input tensors, so let's do this too.
- EXPECT_EQ((vector<int32_t>{1, 2, 3, 4, 5, 6}), read_vector<int32_t>(a));
+ auto test_case = test::TestCase<TestEngine>(f);
+ test_case.add_input<int32_t>({a});
+ test_case.add_expected_output<int32_t>(shape_rt, {1, 3, 5});
+ test_case.run();
}
NGRAPH_TEST(${BACKEND_NAME}, min_matrix_rows_zero)
Shape shape_rt{3};
auto f = make_shared<Function>(make_shared<op::Min>(A, AxisSet{1}), ParameterVector{A});
- auto backend = runtime::Backend::create("${BACKEND_NAME}");
-
- // Create some tensors for input/output
- auto a = backend->create_tensor(element::f32, shape_a);
- copy_data(a, vector<float>{});
- auto result = backend->create_tensor(element::f32, shape_rt);
- copy_data(result, vector<float>({3, 3, 3}));
-
- auto handle = backend->compile(f);
- handle->call_with_validate({result}, {a});
- EXPECT_EQ((vector<float>{std::numeric_limits<float>::infinity(),
- std::numeric_limits<float>::infinity(),
- std::numeric_limits<float>::infinity()}),
- read_vector<float>(result));
-
- // For some reason I'm feeling extra paranoid about making sure reduction doesn't clobber the
- // input tensors, so let's do this too.
- EXPECT_TRUE(
- test::all_close_f((vector<float>{}), read_vector<float>(a), MIN_FLOAT_TOLERANCE_BITS));
+ std::vector<float> a{};
+
+ auto test_case = test::TestCase<TestEngine>(f);
+ test_case.add_input<float>({a});
+ test_case.add_expected_output<float>(shape_rt,
+ {std::numeric_limits<float>::infinity(),
+ std::numeric_limits<float>::infinity(),
+ std::numeric_limits<float>::infinity()});
+ test_case.run();
}
NGRAPH_TEST(${BACKEND_NAME}, min_matrix_cols_zero)
Shape shape_rt{2};
auto f = make_shared<Function>(make_shared<op::Min>(A, AxisSet{0}), ParameterVector{A});
- auto backend = runtime::Backend::create("${BACKEND_NAME}");
-
- // Create some tensors for input/output
- auto a = backend->create_tensor(element::f32, shape_a);
- copy_data(a, vector<float>{});
- auto result = backend->create_tensor(element::f32, shape_rt);
- copy_data(result, vector<float>({3, 3}));
+ std::vector<float> a{};
- auto handle = backend->compile(f);
- handle->call_with_validate({result}, {a});
- EXPECT_EQ((vector<float>{std::numeric_limits<float>::infinity(),
- std::numeric_limits<float>::infinity()}),
- read_vector<float>(result));
-
- // For some reason I'm feeling extra paranoid about making sure reduction doesn't clobber the
- // input tensors, so let's do this too.
- EXPECT_TRUE(
- test::all_close_f((vector<float>{}), read_vector<float>(a), MIN_FLOAT_TOLERANCE_BITS));
+ auto test_case = test::TestCase<TestEngine>(f);
+ test_case.add_input<float>({a});
+ test_case.add_expected_output<float>(
+ shape_rt, {std::numeric_limits<float>::infinity(), std::numeric_limits<float>::infinity()});
+ test_case.run();
}
NGRAPH_TEST(${BACKEND_NAME}, min_vector_zero)
Shape shape_rt{};
auto f = make_shared<Function>(make_shared<op::Min>(A, AxisSet{0}), ParameterVector{A});
- auto backend = runtime::Backend::create("${BACKEND_NAME}");
-
- // Create some tensors for input/output
- auto a = backend->create_tensor(element::f32, shape_a);
- copy_data(a, vector<float>{});
- auto result = backend->create_tensor(element::f32, shape_rt);
- copy_data(result, vector<float>({3}));
+ std::vector<float> a{};
- auto handle = backend->compile(f);
- handle->call_with_validate({result}, {a});
- EXPECT_EQ((vector<float>{std::numeric_limits<float>::infinity()}), read_vector<float>(result));
-
- // For some reason I'm feeling extra paranoid about making sure reduction doesn't clobber the
- // input tensors, so let's do this too.
- EXPECT_TRUE(
- test::all_close_f((vector<float>{}), read_vector<float>(a), MIN_FLOAT_TOLERANCE_BITS));
+ auto test_case = test::TestCase<TestEngine>(f);
+ test_case.add_input<float>({a});
+ test_case.add_expected_output<float>(shape_rt, {std::numeric_limits<float>::infinity()});
+ test_case.run();
}
NGRAPH_TEST(${BACKEND_NAME}, min_matrix_to_scalar_zero_by_zero)
Shape shape_rt{};
auto f = make_shared<Function>(make_shared<op::Min>(A, AxisSet{0, 1}), ParameterVector{A});
- auto backend = runtime::Backend::create("${BACKEND_NAME}");
-
- // Create some tensors for input/output
- auto a = backend->create_tensor(element::f32, shape_a);
- copy_data(a, vector<float>{});
- auto result = backend->create_tensor(element::f32, shape_rt);
- copy_data(result, vector<float>({3}));
-
- auto handle = backend->compile(f);
- handle->call_with_validate({result}, {a});
- EXPECT_EQ((vector<float>{std::numeric_limits<float>::infinity()}), read_vector<float>(result));
+ std::vector<float> a{};
- // For some reason I'm feeling extra paranoid about making sure reduction doesn't clobber the
- // input tensors, so let's do this too.
- EXPECT_TRUE(
- test::all_close_f((vector<float>{}), read_vector<float>(a), MIN_FLOAT_TOLERANCE_BITS));
+ auto test_case = test::TestCase<TestEngine>(f);
+ test_case.add_input<float>({a});
+ test_case.add_expected_output<float>(shape_rt, {std::numeric_limits<float>::infinity()});
+ test_case.run();
}
NGRAPH_TEST(${BACKEND_NAME}, min_3d_to_matrix_most_sig)
Shape shape_rt{3, 3};
auto f = make_shared<Function>(make_shared<op::Min>(A, AxisSet{0}), ParameterVector{A});
- auto backend = runtime::Backend::create("${BACKEND_NAME}");
+ std::vector<float> a{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
+ 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27};
- // Create some tensors for input/output
- auto a = backend->create_tensor(element::f32, shape_a);
- copy_data(a, vector<float>{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
- 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27});
- auto result = backend->create_tensor(element::f32, shape_rt);
-
- auto handle = backend->compile(f);
- handle->call_with_validate({result}, {a});
- EXPECT_TRUE(test::all_close_f((vector<float>{1, 2, 3, 4, 5, 6, 7, 8, 9}),
- read_vector<float>(result),
- MIN_FLOAT_TOLERANCE_BITS));
+ auto test_case = test::TestCase<TestEngine>(f);
+ test_case.add_input<float>({a});
+ test_case.add_expected_output<float>(shape_rt, {1, 2, 3, 4, 5, 6, 7, 8, 9});
+ test_case.run(MIN_FLOAT_TOLERANCE_BITS);
}
NGRAPH_TEST(${BACKEND_NAME}, min_3d_to_matrix_least_sig)
Shape shape_rt{3, 3};
auto f = make_shared<Function>(make_shared<op::Min>(A, AxisSet{2}), ParameterVector{A});
- auto backend = runtime::Backend::create("${BACKEND_NAME}");
-
- // Create some tensors for input/output
- auto a = backend->create_tensor(element::f32, shape_a);
- copy_data(a, vector<float>{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
- 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27});
- auto result = backend->create_tensor(element::f32, shape_rt);
+ std::vector<float> a{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
+ 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27};
- auto handle = backend->compile(f);
- handle->call_with_validate({result}, {a});
- EXPECT_TRUE(test::all_close_f((vector<float>{1, 4, 7, 10, 13, 16, 19, 22, 25}),
- read_vector<float>(result),
- MIN_FLOAT_TOLERANCE_BITS));
+ auto test_case = test::TestCase<TestEngine>(f);
+ test_case.add_input<float>({a});
+ test_case.add_expected_output<float>(shape_rt, {1, 4, 7, 10, 13, 16, 19, 22, 25});
+ test_case.run(MIN_FLOAT_TOLERANCE_BITS);
}
NGRAPH_TEST(${BACKEND_NAME}, min_3d_to_vector)
Shape shape_rt{3};
auto f = make_shared<Function>(make_shared<op::Min>(A, AxisSet{0, 1}), ParameterVector{A});
- auto backend = runtime::Backend::create("${BACKEND_NAME}");
+ std::vector<float> a{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
+ 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27};
- // Create some tensors for input/output
- auto a = backend->create_tensor(element::f32, shape_a);
- copy_data(a, vector<float>{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
- 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27});
- auto result = backend->create_tensor(element::f32, shape_rt);
-
- auto handle = backend->compile(f);
- handle->call_with_validate({result}, {a});
- EXPECT_TRUE(test::all_close_f(
- (vector<float>{1, 2, 3}), read_vector<float>(result), MIN_FLOAT_TOLERANCE_BITS));
+ auto test_case = test::TestCase<TestEngine>(f);
+ test_case.add_input<float>({a});
+ test_case.add_expected_output<float>(shape_rt, {1, 2, 3});
+ test_case.run(MIN_FLOAT_TOLERANCE_BITS);
}
NGRAPH_TEST(${BACKEND_NAME}, min_3d_to_scalar)
Shape shape_rt{};
auto f = make_shared<Function>(make_shared<op::Min>(A, AxisSet{0, 1, 2}), ParameterVector{A});
- auto backend = runtime::Backend::create("${BACKEND_NAME}");
-
- // Create some tensors for input/output
- auto a = backend->create_tensor(element::f32, shape_a);
- copy_data(a, vector<float>{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
- 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1});
- auto result = backend->create_tensor(element::f32, shape_rt);
+ std::vector<float> a{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
+ 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1};
- auto handle = backend->compile(f);
- handle->call_with_validate({result}, {a});
- EXPECT_TRUE(test::all_close_f(
- (vector<float>{1}), read_vector<float>(result), MIN_FLOAT_TOLERANCE_BITS));
+ auto test_case = test::TestCase<TestEngine>(f);
+ test_case.add_input<float>({a});
+ test_case.add_expected_output<float>(shape_rt, {1});
+ test_case.run(MIN_FLOAT_TOLERANCE_BITS);
}
NGRAPH_TEST(${BACKEND_NAME}, min_3d_to_scalar_int32)
Shape shape_rt{};
auto f = make_shared<Function>(make_shared<op::Min>(A, AxisSet{0, 1, 2}), ParameterVector{A});
- auto backend = runtime::Backend::create("${BACKEND_NAME}");
+ std::vector<int32_t> a{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
+ 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1};
- // Create some tensors for input/output
- auto a = backend->create_tensor(element::i32, shape_a);
- copy_data(a, vector<int32_t>{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
- 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1});
- auto result = backend->create_tensor(element::i32, shape_rt);
-
- auto handle = backend->compile(f);
- handle->call_with_validate({result}, {a});
- EXPECT_EQ((vector<int32_t>{1}), read_vector<int32_t>(result));
+ auto test_case = test::TestCase<TestEngine>(f);
+ test_case.add_input<int32_t>({a});
+ test_case.add_expected_output<int32_t>(shape_rt, {1});
+ test_case.run();
}
NGRAPH_TEST(${BACKEND_NAME}, min_3d_eliminate_zero_dim)
Shape shape_rt{3, 2};
auto f = make_shared<Function>(make_shared<op::Min>(A, AxisSet{1}), ParameterVector{A});
- auto backend = runtime::Backend::create("${BACKEND_NAME}");
-
- // Create some tensors for input/output
- auto a = backend->create_tensor(element::f32, shape_a);
- copy_data(a, vector<float>{});
- auto result = backend->create_tensor(element::f32, shape_rt);
-
- // Overwrite the initial result vector to make sure we're not just coincidentally getting the
- // right value.
- copy_data(result, vector<float>{2112, 2112, 2112, 2112, 2112, 2112});
+ std::vector<float> a{};
float inf = std::numeric_limits<float>::infinity();
- auto handle = backend->compile(f);
- handle->call_with_validate({result}, {a});
- EXPECT_EQ((vector<float>{inf, inf, inf, inf, inf, inf}), read_vector<float>(result));
+ auto test_case = test::TestCase<TestEngine>(f);
+ test_case.add_input<float>({a});
+ test_case.add_expected_output<float>(shape_rt, {inf, inf, inf, inf, inf, inf});
+ test_case.run();
}
// clang-format on
#include "gtest/gtest.h"
-#include "runtime/backend.hpp"
-#include "ngraph/runtime/tensor.hpp"
#include "ngraph/ngraph.hpp"
-#include "util/all_close.hpp"
-#include "util/all_close_f.hpp"
-#include "util/ndarray.hpp"
+#include "util/engine/test_engines.hpp"
+#include "util/test_case.hpp"
#include "util/test_control.hpp"
-#include "util/test_tools.hpp"
NGRAPH_SUPPRESS_DEPRECATED_START
using namespace ngraph;
static string s_manifest = "${MANIFEST}";
+using TestEngine = test::ENGINE_CLASS_NAME(${BACKEND_NAME});
NGRAPH_TEST(${BACKEND_NAME}, minimum)
{
auto B = make_shared<op::Parameter>(element::f32, shape);
auto f = make_shared<Function>(make_shared<op::Minimum>(A, B), ParameterVector{A, B});
- auto backend = runtime::Backend::create("${BACKEND_NAME}");
+ std::vector<float> a{1, 8, -8, 17, -0.5, 0.5, 2, 1};
+ std::vector<float> b{1, 2, 4, 8, 0, 0, 1, 1.5};
- // Create some tensors for input/output
- auto a = backend->create_tensor(element::f32, shape);
- copy_data(a, vector<float>{1, 8, -8, 17, -0.5, 0.5, 2, 1});
- auto b = backend->create_tensor(element::f32, shape);
- copy_data(b, vector<float>{1, 2, 4, 8, 0, 0, 1, 1.5});
- auto result = backend->create_tensor(element::f32, shape);
-
- auto handle = backend->compile(f);
- handle->call_with_validate({result}, {a, b});
- EXPECT_TRUE(
- test::all_close_f((vector<float>{1, 2, -8, 8, -.5, 0, 1, 1}), read_vector<float>(result)));
+ auto test_case = test::TestCase<TestEngine>(f);
+ test_case.add_multiple_inputs<float>({a, b});
+ test_case.add_expected_output<float>(shape, {1, 2, -8, 8, -.5, 0, 1, 1});
+ test_case.run();
}
NGRAPH_TEST(${BACKEND_NAME}, minimum_int32)
auto B = make_shared<op::Parameter>(element::i32, shape);
auto f = make_shared<Function>(make_shared<op::Minimum>(A, B), ParameterVector{A, B});
- auto backend = runtime::Backend::create("${BACKEND_NAME}");
-
- // Create some tensors for input/output
- auto a = backend->create_tensor(element::i32, shape);
- copy_data(a, vector<int32_t>{1, 8, -8, 17, -5, 67635216, 2, 1});
- auto b = backend->create_tensor(element::i32, shape);
- copy_data(b, vector<int32_t>{1, 2, 4, 8, 0, 18448, 1, 6});
- auto result = backend->create_tensor(element::i32, shape);
+ std::vector<int32_t> a{1, 8, -8, 17, -5, 67635216, 2, 1};
+ std::vector<int32_t> b{1, 2, 4, 8, 0, 18448, 1, 6};
- auto handle = backend->compile(f);
- handle->call_with_validate({result}, {a, b});
- EXPECT_EQ((vector<int32_t>{1, 2, -8, 8, -5, 18448, 1, 1}), read_vector<int32_t>(result));
+ auto test_case = test::TestCase<TestEngine>(f);
+ test_case.add_multiple_inputs<int32_t>({a, b});
+ test_case.add_expected_output<int32_t>(shape, {1, 2, -8, 8, -5, 18448, 1, 1});
+ test_case.run();
}
NGRAPH_TEST(${BACKEND_NAME}, minimum_int64)
auto B = make_shared<op::Parameter>(element::i64, shape);
auto f = make_shared<Function>(make_shared<op::Minimum>(A, B), ParameterVector{A, B});
- auto backend = runtime::Backend::create("${BACKEND_NAME}");
-
- // Create some tensors for input/output
- auto a = backend->create_tensor(element::i64, shape);
- copy_data(a, vector<int64_t>{1, 8, -8, 17, -5, 67635216, 2, 17179887632});
- auto b = backend->create_tensor(element::i64, shape);
- copy_data(b, vector<int64_t>{1, 2, 4, 8, 0, 18448, 1, 280592});
- auto result = backend->create_tensor(element::i64, shape);
+ std::vector<int64_t> a{1, 8, -8, 17, -5, 67635216, 2, 17179887632};
+ std::vector<int64_t> b{1, 2, 4, 8, 0, 18448, 1, 280592};
- auto handle = backend->compile(f);
- handle->call_with_validate({result}, {a, b});
- EXPECT_EQ((vector<int64_t>{1, 2, -8, 8, -5, 18448, 1, 280592}), read_vector<int64_t>(result));
+ auto test_case = test::TestCase<TestEngine>(f);
+ test_case.add_multiple_inputs<int64_t>({a, b});
+ test_case.add_expected_output<int64_t>(shape, {1, 2, -8, 8, -5, 18448, 1, 280592});
+ test_case.run();
}
#include "gtest/gtest.h"
#include "ngraph/ngraph.hpp"
-#include "ngraph/runtime/tensor.hpp"
-#include "runtime/backend.hpp"
-#include "util/all_close.hpp"
-#include "util/all_close_f.hpp"
-#include "util/known_element_types.hpp"
-#include "util/ndarray.hpp"
+#include "util/engine/test_engines.hpp"
+#include "util/test_case.hpp"
#include "util/test_control.hpp"
-#include "util/test_tools.hpp"
NGRAPH_SUPPRESS_DEPRECATED_START
using namespace ngraph;
static string s_manifest = "${MANIFEST}";
+using TestEngine = test::ENGINE_CLASS_NAME(${BACKEND_NAME});
NGRAPH_TEST(${BACKEND_NAME}, quantize)
{
make_shared<op::Quantize>(X, scale, offset, output_type, quantization_axes, round_mode);
auto f = make_shared<Function>(quantize, ParameterVector{X});
- auto backend = runtime::Backend::create("${BACKEND_NAME}");
- auto x = backend->create_tensor(input_type, input_shape);
- auto y = backend->create_tensor(output_type, input_shape);
-
- copy_data(x, vector<input_c_type>{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11});
+ std::vector<input_c_type> x{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
// divide by scale 2 2 2 2 2 2 2 2 2 2 2 2
// equals (rounded) 0 0 1 2 2 2 3 4 4 4 5 6
// plus offset 1 1 1 1 1 1 1 1 1 1 1 1
// equals 1 1 2 3 3 3 4 5 5 5 6 7
- auto handle = backend->compile(f);
- handle->call_with_validate({y}, {x});
- EXPECT_EQ((vector<output_c_type>{1, 1, 2, 3, 3, 3, 4, 5, 5, 5, 6, 7}),
- read_vector<output_c_type>(y));
+ auto test_case = test::TestCase<TestEngine>(f);
+ test_case.add_input<input_c_type>({x});
+ test_case.add_expected_output<output_c_type>(input_shape, {1, 1, 2, 3, 3, 3, 4, 5, 5, 5, 6, 7});
+ test_case.run();
}
NGRAPH_TEST(${BACKEND_NAME}, dequantize)
auto dequantize = make_shared<op::Dequantize>(X, scale, offset, output_type, quantization_axes);
auto f = make_shared<Function>(dequantize, ParameterVector{X});
- auto backend = runtime::Backend::create("${BACKEND_NAME}");
- auto x = backend->create_tensor(input_type, input_shape);
- auto y = backend->create_tensor(output_type, input_shape);
-
- copy_data(x, vector<input_c_type>{1, 1, 2, 3, 3, 3, 4, 5, 5, 5, 6, 7});
+ std::vector<input_c_type> x{{1, 1, 2, 3, 3, 3, 4, 5, 5, 5, 6, 7}};
// minus offset 1 1 1 1 1 1 1 1 1 1 1 1
// eqauls 0 0 1 2 2 2 3 4 4 4 5 6
// multiplied by scale 2 2 2 2 2 2 2 2 2 2 2 2
// equals 0 0 2 4 4 4 6 8 8 8 10 12
- auto handle = backend->compile(f);
- handle->call_with_validate({y}, {x});
- EXPECT_TRUE(test::all_close_f((vector<output_c_type>{0, 0, 2, 4, 4, 4, 6, 8, 8, 8, 10, 12}),
- read_vector<output_c_type>(y),
- MIN_FLOAT_TOLERANCE_BITS));
+ auto test_case = test::TestCase<TestEngine>(f);
+ test_case.add_input<input_c_type>({x});
+ test_case.add_expected_output<output_c_type>(input_shape,
+ {0, 0, 2, 4, 4, 4, 6, 8, 8, 8, 10, 12});
+ test_case.run(MIN_FLOAT_TOLERANCE_BITS);
}
NGRAPH_TEST(${BACKEND_NAME}, quantize_zero_offset)
make_shared<op::Quantize>(X, scale, offset, output_type, quantization_axes, round_mode);
auto f = make_shared<Function>(quantize, ParameterVector{X});
- auto backend = runtime::Backend::create("${BACKEND_NAME}");
- auto x = backend->create_tensor(input_type, input_shape);
- auto y = backend->create_tensor(output_type, input_shape);
-
- copy_data(x, vector<input_c_type>{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11});
+ std::vector<input_c_type> x{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
// divide by scale 2 2 2 2 2 2 2 2 2 2 2 2
// equals (rounded) 0 0 1 2 2 2 3 4 4 4 5 6
// plus offset 0 0 0 0 0 0 0 0 0 0 0 0
// equals 0 0 1 2 2 2 3 4 4 4 5 6
- auto handle = backend->compile(f);
- handle->call_with_validate({y}, {x});
- EXPECT_EQ((vector<output_c_type>{0, 0, 1, 2, 2, 2, 3, 4, 4, 4, 5, 6}),
- read_vector<output_c_type>(y));
+ auto test_case = test::TestCase<TestEngine>(f);
+ test_case.add_input<input_c_type>({x});
+ test_case.add_expected_output<output_c_type>(input_shape, {0, 0, 1, 2, 2, 2, 3, 4, 4, 4, 5, 6});
+ test_case.run();
}
NGRAPH_TEST(${BACKEND_NAME}, dequantize_zero_offset)
auto dequantize = make_shared<op::Dequantize>(X, scale, offset, output_type, quantization_axes);
auto f = make_shared<Function>(dequantize, ParameterVector{X});
- auto backend = runtime::Backend::create("${BACKEND_NAME}");
- auto x = backend->create_tensor(input_type, input_shape);
- auto y = backend->create_tensor(output_type, input_shape);
-
- copy_data(x, vector<input_c_type>{0, 0, 1, 2, 2, 2, 3, 4, 4, 4, 5, 6});
+ std::vector<input_c_type> x{0, 0, 1, 2, 2, 2, 3, 4, 4, 4, 5, 6};
// minus offset 0 0 0 0 0 0 0 0 0 0 0 0
// equals 0 0 1 2 2 2 3 4 4 4 5 6
// multiplied by scale 2 2 2 2 2 2 2 2 2 2 2 2
// equals 0 0 2 4 4 4 6 8 8 8 10 12
- auto handle = backend->compile(f);
- handle->call_with_validate({y}, {x});
- EXPECT_TRUE(test::all_close_f((vector<output_c_type>{0, 0, 2, 4, 4, 4, 6, 8, 8, 8, 10, 12}),
- read_vector<output_c_type>(y),
- MIN_FLOAT_TOLERANCE_BITS));
+ auto test_case = test::TestCase<TestEngine>(f);
+ test_case.add_input<input_c_type>({x});
+ test_case.add_expected_output<output_c_type>(input_shape,
+ {0, 0, 2, 4, 4, 4, 6, 8, 8, 8, 10, 12});
+ test_case.run(MIN_FLOAT_TOLERANCE_BITS);
}
NGRAPH_TEST(${BACKEND_NAME}, quantize_axes)
make_shared<op::Quantize>(X, scale, offset, output_type, quantization_axes, round_mode);
auto f = make_shared<Function>(quantize, ParameterVector{X});
- auto backend = runtime::Backend::create("${BACKEND_NAME}");
- auto x = backend->create_tensor(input_type, input_shape);
- auto y = backend->create_tensor(output_type, input_shape);
-
- copy_data(x, vector<input_c_type>{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11});
+ std::vector<input_c_type> x{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
// divided by scale 2 2 2 3 3 3 4 4 4 5 5 5
// equals (rounded) 0 1 1 1 1 2 2 2 2 2 2 2
// plus offset 10 10 10 20 20 20 30 30 30 40 40 40
// equals 10 11 11 21 21 22 32 32 32 42 42 42
- auto handle = backend->compile(f);
- handle->call_with_validate({y}, {x});
- EXPECT_EQ((vector<output_c_type>{10, 11, 11, 21, 21, 22, 32, 32, 32, 42, 42, 42}),
- read_vector<output_c_type>(y));
+ auto test_case = test::TestCase<TestEngine>(f);
+ test_case.add_input<input_c_type>({x});
+ test_case.add_expected_output<output_c_type>(input_shape,
+ {10, 11, 11, 21, 21, 22, 32, 32, 32, 42, 42, 42});
+ test_case.run();
}
NGRAPH_TEST(${BACKEND_NAME}, dequantize_axes)
auto dequantize = make_shared<op::Dequantize>(X, scale, offset, output_type, quantization_axes);
auto f = make_shared<Function>(dequantize, ParameterVector{X});
- auto backend = runtime::Backend::create("${BACKEND_NAME}");
- auto x = backend->create_tensor(input_type, input_shape);
- auto y = backend->create_tensor(output_type, input_shape);
-
- copy_data(x, vector<input_c_type>{10, 11, 11, 21, 21, 22, 32, 32, 32, 42, 42, 42});
+ std::vector<input_c_type> x{10, 11, 11, 21, 21, 22, 32, 32, 32, 42, 42, 42};
// minus offset 10 10 10 20 20 20 30 30 30 40 40 40
// equals 0 1 1 1 1 2 2 2 2 2 2 2
// multiplied by scale 2 2 2 3 3 3 4 4 4 5 5 5
// equals 0 2 2 3 3 6 8 8 8 10 10 10
- auto handle = backend->compile(f);
- handle->call_with_validate({y}, {x});
- EXPECT_TRUE(test::all_close_f((vector<output_c_type>{0, 2, 2, 3, 3, 6, 8, 8, 8, 10, 10, 10}),
- read_vector<output_c_type>(y),
- MIN_FLOAT_TOLERANCE_BITS));
+ auto test_case = test::TestCase<TestEngine>(f);
+ test_case.add_input<input_c_type>({x});
+ test_case.add_expected_output<output_c_type>(input_shape,
+ {0, 2, 2, 3, 3, 6, 8, 8, 8, 10, 10, 10});
+ test_case.run(MIN_FLOAT_TOLERANCE_BITS);
}
NGRAPH_TEST(${BACKEND_NAME}, quantize_int8)
make_shared<op::Quantize>(X, scale, offset, output_type, quantization_axes, round_mode);
auto f = make_shared<Function>(quantize, ParameterVector{X});
- auto backend = runtime::Backend::create("${BACKEND_NAME}");
- auto x = backend->create_tensor(input_type, input_shape);
- auto y = backend->create_tensor(output_type, input_shape);
-
- copy_data(x, vector<input_c_type>{0, -1, 2, -3, 4, -5, 6, -7, 8, -9, 10, -11});
+ std::vector<input_c_type> x{0, -1, 2, -3, 4, -5, 6, -7, 8, -9, 10, -11};
// divide by scale 2 2 2 2 2 2 2 2 2 2 2 2
// equals (rounded) 0 0 1 -2 2 -2 3 -4 4 -4 5 -6
// plus offset 1 1 1 1 1 1 1 1 1 1 1 1
// equals 1 1 2 -1 3 -1 4 -3 5 -3 6 -5
- auto handle = backend->compile(f);
- handle->call_with_validate({y}, {x});
- EXPECT_EQ((vector<output_c_type>{1, 1, 2, -1, 3, -1, 4, -3, 5, -3, 6, -5}),
- read_vector<output_c_type>(y));
+ auto test_case = test::TestCase<TestEngine>(f);
+ test_case.add_input<input_c_type>({x});
+ test_case.add_expected_output<output_c_type>(input_shape,
+ {1, 1, 2, -1, 3, -1, 4, -3, 5, -3, 6, -5});
+ test_case.run();
}
NGRAPH_TEST(${BACKEND_NAME}, dequantize_int8)
auto dequantize = make_shared<op::Dequantize>(X, scale, offset, output_type, quantization_axes);
auto f = make_shared<Function>(dequantize, ParameterVector{X});
- auto backend = runtime::Backend::create("${BACKEND_NAME}");
- auto x = backend->create_tensor(input_type, input_shape);
- auto y = backend->create_tensor(output_type, input_shape);
-
- copy_data(x, vector<input_c_type>{1, 1, 2, -1, 3, -1, 4, -3, 5, -3, 6, -5});
+ std::vector<input_c_type> x{1, 1, 2, -1, 3, -1, 4, -3, 5, -3, 6, -5};
// minus offset 1 1 1 1 1 1 1 1 1 1 1 1
// equals 0 0 1 -2 2 -2 3 -4 4 -4 5 -6
// multiplied by scale 2 2 2 2 2 2 2 2 2 2 2 2
// equals 0 0 2 -4 4 -4 6 -8 8 -8 10 -12
- auto handle = backend->compile(f);
- handle->call_with_validate({y}, {x});
- EXPECT_TRUE(
- test::all_close_f((vector<output_c_type>{0, 0, 2, -4, 4, -4, 6, -8, 8, -8, 10, -12}),
- read_vector<output_c_type>(y),
- MIN_FLOAT_TOLERANCE_BITS));
+ auto test_case = test::TestCase<TestEngine>(f);
+ test_case.add_input<input_c_type>({x});
+ test_case.add_expected_output<output_c_type>(input_shape,
+ {0, 0, 2, -4, 4, -4, 6, -8, 8, -8, 10, -12});
+ test_case.run(MIN_FLOAT_TOLERANCE_BITS);
}
NGRAPH_TEST(${BACKEND_NAME}, quantize_int8_zero_offset)
make_shared<op::Quantize>(X, scale, offset, output_type, quantization_axes, round_mode);
auto f = make_shared<Function>(quantize, ParameterVector{X});
- auto backend = runtime::Backend::create("${BACKEND_NAME}");
- auto x = backend->create_tensor(input_type, input_shape);
- auto y = backend->create_tensor(output_type, input_shape);
-
- copy_data(x, vector<input_c_type>{0, -1, 2, -3, 4, -5, 6, -7, 8, -9, 10, -11});
+ std::vector<input_c_type> x{0, -1, 2, -3, 4, -5, 6, -7, 8, -9, 10, -11};
// divide by scale 2 2 2 2 2 2 2 2 2 2 2 2
// equals (rounded) 0 0 1 -2 2 -2 3 -4 4 -4 5 -6
// plus offset 0 0 0 0 0 0 0 0 0 0 0 0
// equals 0 0 1 -2 2 -2 3 -4 4 -4 5 -6
- auto handle = backend->compile(f);
- handle->call_with_validate({y}, {x});
- EXPECT_EQ((vector<output_c_type>{0, 0, 1, -2, 2, -2, 3, -4, 4, -4, 5, -6}),
- read_vector<output_c_type>(y));
+ auto test_case = test::TestCase<TestEngine>(f);
+ test_case.add_input<input_c_type>({x});
+ test_case.add_expected_output<output_c_type>(input_shape,
+ {0, 0, 1, -2, 2, -2, 3, -4, 4, -4, 5, -6});
+ test_case.run();
}
NGRAPH_TEST(${BACKEND_NAME}, dequantize_int8_zero_offset)
auto dequantize = make_shared<op::Dequantize>(X, scale, offset, output_type, quantization_axes);
auto f = make_shared<Function>(dequantize, ParameterVector{X});
- auto backend = runtime::Backend::create("${BACKEND_NAME}");
- auto x = backend->create_tensor(input_type, input_shape);
- auto y = backend->create_tensor(output_type, input_shape);
-
- copy_data(x, vector<input_c_type>{0, 0, 1, -2, 2, -2, 3, -4, 4, -4, 5, -6});
+ std::vector<input_c_type> x{0, 0, 1, -2, 2, -2, 3, -4, 4, -4, 5, -6};
// minus offset 0 0 0 0 0 0 0 0 0 0 0 0
// equals 0 0 1 -2 2 -2 3 -4 4 -4 5 -6
// multiplied by scale 2 2 2 2 2 2 2 2 2 2 2 2
// equals 0 0 2 -4 4 -4 6 -8 8 -8 10 -12
- auto handle = backend->compile(f);
- handle->call_with_validate({y}, {x});
- EXPECT_TRUE(
- test::all_close_f((vector<output_c_type>{0, 0, 2, -4, 4, -4, 6, -8, 8, -8, 10, -12}),
- read_vector<output_c_type>(y),
- MIN_FLOAT_TOLERANCE_BITS));
+ auto test_case = test::TestCase<TestEngine>(f);
+ test_case.add_input<input_c_type>({x});
+ test_case.add_expected_output<output_c_type>(input_shape,
+ {0, 0, 2, -4, 4, -4, 6, -8, 8, -8, 10, -12});
+ test_case.run(MIN_FLOAT_TOLERANCE_BITS);
}
NGRAPH_TEST(${BACKEND_NAME}, quantize_int32)
make_shared<op::Quantize>(X, scale, offset, output_type, quantization_axes, round_mode);
auto f = make_shared<Function>(quantize, ParameterVector{X});
- auto backend = runtime::Backend::create("${BACKEND_NAME}");
- auto x = backend->create_tensor(input_type, input_shape);
- auto y = backend->create_tensor(output_type, input_shape);
-
- copy_data(x, vector<input_c_type>{0, -1, 2, -3, 4, -5, 6, -7, 8, -9, 10, -11});
+ std::vector<input_c_type> x{0, -1, 2, -3, 4, -5, 6, -7, 8, -9, 10, -11};
// divide by scale 2 2 2 2 2 2 2 2 2 2 2 2
// equals (rounded) 0 0 1 -2 2 -2 3 -4 4 -4 5 -6
// plus offset 1 1 1 1 1 1 1 1 1 1 1 1
// equals 1 1 2 -1 3 -1 4 -3 5 -3 6 -5
- auto handle = backend->compile(f);
- handle->call_with_validate({y}, {x});
- EXPECT_EQ((vector<output_c_type>{1, 1, 2, -1, 3, -1, 4, -3, 5, -3, 6, -5}),
- read_vector<output_c_type>(y));
+ auto test_case = test::TestCase<TestEngine>(f);
+ test_case.add_input<input_c_type>({x});
+ test_case.add_expected_output<output_c_type>(input_shape,
+ {1, 1, 2, -1, 3, -1, 4, -3, 5, -3, 6, -5});
+ test_case.run();
}
NGRAPH_TEST(${BACKEND_NAME}, dequantize_int32)
auto dequantize = make_shared<op::Dequantize>(X, scale, offset, output_type, quantization_axes);
auto f = make_shared<Function>(dequantize, ParameterVector{X});
- auto backend = runtime::Backend::create("${BACKEND_NAME}");
- auto x = backend->create_tensor(input_type, input_shape);
- auto y = backend->create_tensor(output_type, input_shape);
-
- copy_data(x, vector<input_c_type>{1, 1, 2, -1, 3, -1, 4, -3, 5, -3, 6, -5});
+ std::vector<input_c_type> x{1, 1, 2, -1, 3, -1, 4, -3, 5, -3, 6, -5};
// minus offset 1 1 1 1 1 1 1 1 1 1 1 1
// equals 0 0 1 -2 2 -2 3 -4 4 -4 5 -6
// multiplied by scale 2 2 2 2 2 2 2 2 2 2 2 2
// equals 0 0 2 -4 4 -4 6 -8 8 -8 10 -12
- auto handle = backend->compile(f);
- handle->call_with_validate({y}, {x});
- EXPECT_TRUE(
- test::all_close_f((vector<output_c_type>{0, 0, 2, -4, 4, -4, 6, -8, 8, -8, 10, -12}),
- read_vector<output_c_type>(y),
- MIN_FLOAT_TOLERANCE_BITS));
+ auto test_case = test::TestCase<TestEngine>(f);
+ test_case.add_input<input_c_type>({x});
+ test_case.add_expected_output<output_c_type>(input_shape,
+ {0, 0, 2, -4, 4, -4, 6, -8, 8, -8, 10, -12});
+ test_case.run(MIN_FLOAT_TOLERANCE_BITS);
}
NGRAPH_TEST(${BACKEND_NAME}, quantize_int32_zero_offset)
make_shared<op::Quantize>(X, scale, offset, output_type, quantization_axes, round_mode);
auto f = make_shared<Function>(quantize, ParameterVector{X});
- auto backend = runtime::Backend::create("${BACKEND_NAME}");
- auto x = backend->create_tensor(input_type, input_shape);
- auto y = backend->create_tensor(output_type, input_shape);
-
- copy_data(x, vector<input_c_type>{0, -1, 2, -3, 4, -5, 6, -7, 8, -9, 10, -11});
+ std::vector<input_c_type> x{0, -1, 2, -3, 4, -5, 6, -7, 8, -9, 10, -11};
// divide by scale 2 2 2 2 2 2 2 2 2 2 2 2
// equals (rounded) 0 0 1 -2 2 -2 3 -4 4 -4 5 -6
// plus offset 0 0 0 0 0 0 0 0 0 0 0 0
// equals 0 0 1 -2 2 -2 3 -4 4 -4 5 -6
- auto handle = backend->compile(f);
- handle->call_with_validate({y}, {x});
- EXPECT_EQ((vector<output_c_type>{0, 0, 1, -2, 2, -2, 3, -4, 4, -4, 5, -6}),
- read_vector<output_c_type>(y));
+ auto test_case = test::TestCase<TestEngine>(f);
+ test_case.add_input<input_c_type>({x});
+ test_case.add_expected_output<output_c_type>(input_shape,
+ {0, 0, 1, -2, 2, -2, 3, -4, 4, -4, 5, -6});
+ test_case.run();
}
NGRAPH_TEST(${BACKEND_NAME}, dequantize_int32_zero_offset)
auto dequantize = make_shared<op::Dequantize>(X, scale, offset, output_type, quantization_axes);
auto f = make_shared<Function>(dequantize, ParameterVector{X});
- auto backend = runtime::Backend::create("${BACKEND_NAME}");
- auto x = backend->create_tensor(input_type, input_shape);
- auto y = backend->create_tensor(output_type, input_shape);
-
- copy_data(x, vector<input_c_type>{0, 0, 1, -2, 2, -2, 3, -4, 4, -4, 5, -6});
+ std::vector<input_c_type> x{0, 0, 1, -2, 2, -2, 3, -4, 4, -4, 5, -6};
// minus offset 0 0 0 0 0 0 0 0 0 0 0 0
// equals 0 0 1 -2 2 -2 3 -4 4 -4 5 -6
// multiplied by scale 2 2 2 2 2 2 2 2 2 2 2 2
// equals 0 0 2 -4 4 -4 6 -8 8 -8 10 -12
- auto handle = backend->compile(f);
- handle->call_with_validate({y}, {x});
- EXPECT_TRUE(
- test::all_close_f((vector<output_c_type>{0, 0, 2, -4, 4, -4, 6, -8, 8, -8, 10, -12}),
- read_vector<output_c_type>(y),
- MIN_FLOAT_TOLERANCE_BITS));
+ auto test_case = test::TestCase<TestEngine>(f);
+ test_case.add_input<input_c_type>({x});
+ test_case.add_expected_output<output_c_type>(input_shape,
+ {0, 0, 2, -4, 4, -4, 6, -8, 8, -8, 10, -12});
+ test_case.run(MIN_FLOAT_TOLERANCE_BITS);
}
NGRAPH_TEST(${BACKEND_NAME}, quantize_clamp_uint8)
make_shared<op::Quantize>(X, scale, offset, output_type, quantization_axes, round_mode);
auto f = make_shared<Function>(quantize, ParameterVector{X});
- auto backend = runtime::Backend::create("${BACKEND_NAME}");
- auto x = backend->create_tensor(input_type, input_shape);
- auto y = backend->create_tensor(output_type, input_shape);
-
- copy_data(x, vector<input_c_type>{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11});
+ std::vector<input_c_type> x{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
- auto handle = backend->compile(f);
- handle->call_with_validate({y}, {x});
- EXPECT_EQ((vector<output_c_type>{0, max, max, max, max, max, max, max, max, max, max, max}),
- read_vector<output_c_type>(y));
+ auto test_case = test::TestCase<TestEngine>(f);
+ test_case.add_input<input_c_type>({x});
+ test_case.add_expected_output<output_c_type>(
+ input_shape, {0, max, max, max, max, max, max, max, max, max, max, max});
+ test_case.run();
}
NGRAPH_TEST(${BACKEND_NAME}, quantize_clamp_int8)
make_shared<op::Quantize>(X, scale, offset, output_type, quantization_axes, round_mode);
auto f = make_shared<Function>(quantize, ParameterVector{X});
- auto backend = runtime::Backend::create("${BACKEND_NAME}");
- auto x = backend->create_tensor(input_type, input_shape);
- auto y = backend->create_tensor(output_type, input_shape);
+ std::vector<input_c_type> x{0, -1, 2, -3, 4, -5, 6, -7, 8, -9, 10, -11};
- copy_data(x, vector<input_c_type>{0, -1, 2, -3, 4, -5, 6, -7, 8, -9, 10, -11});
-
- auto handle = backend->compile(f);
- handle->call_with_validate({y}, {x});
- EXPECT_EQ((vector<output_c_type>{0, min, max, min, max, min, max, min, max, min, max, min}),
- read_vector<output_c_type>(y));
+ auto test_case = test::TestCase<TestEngine>(f);
+ test_case.add_input<input_c_type>({x});
+ test_case.add_expected_output<output_c_type>(
+ input_shape, {0, min, max, min, max, min, max, min, max, min, max, min});
+ test_case.run();
}
NGRAPH_TEST(${BACKEND_NAME}, quantize_clamp_int32)
make_shared<op::Quantize>(X, scale, offset, output_type, quantization_axes, round_mode);
auto f = make_shared<Function>(quantize, ParameterVector{X});
- auto backend = runtime::Backend::create("${BACKEND_NAME}");
- auto x = backend->create_tensor(input_type, input_shape);
- auto y = backend->create_tensor(output_type, input_shape);
-
- copy_data(x, vector<input_c_type>{0, -1, 2, -3, 4, -5, 6, -7, 8, -9, 10, -11});
+ std::vector<input_c_type> x{0, -1, 2, -3, 4, -5, 6, -7, 8, -9, 10, -11};
- auto handle = backend->compile(f);
- handle->call_with_validate({y}, {x});
- EXPECT_EQ((vector<output_c_type>{0, min, max, min, max, min, max, min, max, min, max, min}),
- read_vector<output_c_type>(y));
+ auto test_case = test::TestCase<TestEngine>(f);
+ test_case.add_input<input_c_type>({x});
+ test_case.add_expected_output<output_c_type>(
+ input_shape, {0, min, max, min, max, min, max, min, max, min, max, min});
+ test_case.run();
}
NGRAPH_TEST(${BACKEND_NAME}, quantize_ROUND_NEAREST_TOWARD_ZERO)
make_shared<op::Quantize>(X, scale, offset, output_type, quantization_axes, round_mode);
auto f = make_shared<Function>(quantize, ParameterVector{X});
- auto backend = runtime::Backend::create("${BACKEND_NAME}");
- auto x = backend->create_tensor(input_type, input_shape);
- auto y = backend->create_tensor(output_type, input_shape);
-
- copy_data(x, vector<input_c_type>{9, 10, 11, -9, -10, -11, 13, 14, 15, -13, -14, -15});
+ std::vector<input_c_type> x{9, 10, 11, -9, -10, -11, 13, 14, 15, -13, -14, -15};
// divide by scale 4 4 4 4 4 4 4 4 4 4 4 4
// equals (rounded) 2 2 3 -2 -2 -3 3 3 4 -3 -3 -4
- auto handle = backend->compile(f);
- handle->call_with_validate({y}, {x});
- EXPECT_EQ((vector<output_c_type>{2, 2, 3, -2, -2, -3, 3, 3, 4, -3, -3, -4}),
- read_vector<output_c_type>(y));
+ auto test_case = test::TestCase<TestEngine>(f);
+ test_case.add_input<input_c_type>({x});
+ test_case.add_expected_output<output_c_type>(input_shape,
+ {2, 2, 3, -2, -2, -3, 3, 3, 4, -3, -3, -4});
+ test_case.run();
}
NGRAPH_TEST(${BACKEND_NAME}, quantize_ROUND_NEAREST_TOWARD_INFINITY)
make_shared<op::Quantize>(X, scale, offset, output_type, quantization_axes, round_mode);
auto f = make_shared<Function>(quantize, ParameterVector{X});
- auto backend = runtime::Backend::create("${BACKEND_NAME}");
- auto x = backend->create_tensor(input_type, input_shape);
- auto y = backend->create_tensor(output_type, input_shape);
-
- copy_data(x, vector<input_c_type>{9, 10, 11, -9, -10, -11, 13, 14, 15, -13, -14, -15});
+ std::vector<input_c_type> x{9, 10, 11, -9, -10, -11, 13, 14, 15, -13, -14, -15};
// divide by scale 4 4 4 4 4 4 4 4 4 4 4 4
// equals (rounded) 2 3 3 -2 -3 -3 3 4 4 -3 -4 -4
- auto handle = backend->compile(f);
- handle->call_with_validate({y}, {x});
- EXPECT_EQ((vector<output_c_type>{2, 3, 3, -2, -3, -3, 3, 4, 4, -3, -4, -4}),
- read_vector<output_c_type>(y));
+ auto test_case = test::TestCase<TestEngine>(f);
+ test_case.add_input<input_c_type>({x});
+ test_case.add_expected_output<output_c_type>(input_shape,
+ {2, 3, 3, -2, -3, -3, 3, 4, 4, -3, -4, -4});
+ test_case.run();
}
NGRAPH_TEST(${BACKEND_NAME}, quantize_ROUND_NEAREST_UPWARD)
make_shared<op::Quantize>(X, scale, offset, output_type, quantization_axes, round_mode);
auto f = make_shared<Function>(quantize, ParameterVector{X});
- auto backend = runtime::Backend::create("${BACKEND_NAME}");
- auto x = backend->create_tensor(input_type, input_shape);
- auto y = backend->create_tensor(output_type, input_shape);
-
- copy_data(x, vector<input_c_type>{9, 10, 11, -9, -10, -11, 13, 14, 15, -13, -14, -15});
+ std::vector<input_c_type> x{9, 10, 11, -9, -10, -11, 13, 14, 15, -13, -14, -15};
// divide by scale 4 4 4 4 4 4 4 4 4 4 4 4
// equals (rounded) 2 3 3 -2 -2 -3 3 4 4 -3 -3 -4
- auto handle = backend->compile(f);
- handle->call_with_validate({y}, {x});
- EXPECT_EQ((vector<output_c_type>{2, 3, 3, -2, -2, -3, 3, 4, 4, -3, -3, -4}),
- read_vector<output_c_type>(y));
+ auto test_case = test::TestCase<TestEngine>(f);
+ test_case.add_input<input_c_type>({x});
+ test_case.add_expected_output<output_c_type>(input_shape,
+ {2, 3, 3, -2, -2, -3, 3, 4, 4, -3, -3, -4});
+ test_case.run();
}
NGRAPH_TEST(${BACKEND_NAME}, quantize_ROUND_NEAREST_DOWNWARD)
make_shared<op::Quantize>(X, scale, offset, output_type, quantization_axes, round_mode);
auto f = make_shared<Function>(quantize, ParameterVector{X});
- auto backend = runtime::Backend::create("${BACKEND_NAME}");
- auto x = backend->create_tensor(input_type, input_shape);
- auto y = backend->create_tensor(output_type, input_shape);
-
- copy_data(x, vector<input_c_type>{9, 10, 11, -9, -10, -11, 13, 14, 15, -13, -14, -15});
+ std::vector<input_c_type> x{9, 10, 11, -9, -10, -11, 13, 14, 15, -13, -14, -15};
// divide by scale 4 4 4 4 4 4 4 4 4 4 4 4
// equals (rounded) 2 2 3 -2 -3 -3 3 3 4 -3 -4 -4
- auto handle = backend->compile(f);
- handle->call_with_validate({y}, {x});
- EXPECT_EQ((vector<output_c_type>{2, 2, 3, -2, -3, -3, 3, 3, 4, -3, -4, -4}),
- read_vector<output_c_type>(y));
+ auto test_case = test::TestCase<TestEngine>(f);
+ test_case.add_input<input_c_type>({x});
+ test_case.add_expected_output<output_c_type>(input_shape,
+ {2, 2, 3, -2, -3, -3, 3, 3, 4, -3, -4, -4});
+ test_case.run();
}
NGRAPH_TEST(${BACKEND_NAME}, quantize_ROUND_NEAREST_TOWARD_EVEN)
make_shared<op::Quantize>(X, scale, offset, output_type, quantization_axes, round_mode);
auto f = make_shared<Function>(quantize, ParameterVector{X});
- auto backend = runtime::Backend::create("${BACKEND_NAME}");
- auto x = backend->create_tensor(input_type, input_shape);
- auto y = backend->create_tensor(output_type, input_shape);
-
- copy_data(x, vector<input_c_type>{9, 10, 11, -9, -10, -11, 13, 14, 15, -13, -14, -15});
+ std::vector<input_c_type> x{9, 10, 11, -9, -10, -11, 13, 14, 15, -13, -14, -15};
// divide by scale 4 4 4 4 4 4 4 4 4 4 4 4
// equals (rounded) 2 2 3 -2 -2 -3 3 4 4 -3 -4 -4
- auto handle = backend->compile(f);
- handle->call_with_validate({y}, {x});
- EXPECT_EQ((vector<output_c_type>{2, 2, 3, -2, -2, -3, 3, 4, 4, -3, -4, -4}),
- read_vector<output_c_type>(y));
+ auto test_case = test::TestCase<TestEngine>(f);
+ test_case.add_input<input_c_type>({x});
+ test_case.add_expected_output<output_c_type>(input_shape,
+ {2, 2, 3, -2, -2, -3, 3, 4, 4, -3, -4, -4});
+ test_case.run();
}
NGRAPH_TEST(${BACKEND_NAME}, quantize_ROUND_TOWARD_INFINITY)
static_cast<op::Quantize::RoundMode>(static_cast<int>(round_mode)));
auto f = make_shared<Function>(quantize, ParameterVector{X});
- auto backend = runtime::Backend::create("${BACKEND_NAME}");
- auto x = backend->create_tensor(input_type, input_shape);
- auto y = backend->create_tensor(output_type, input_shape);
-
- copy_data(x, vector<input_c_type>{9, 10, 11, -9, -10, -11, 13, 14, 15, -13, -14, -15});
+ std::vector<input_c_type> x{9, 10, 11, -9, -10, -11, 13, 14, 15, -13, -14, -15};
// divide by scale 4 4 4 4 4 4 4 4 4 4 4 4
// equals (rounded) 3 3 3 -3 -3 -3 4 4 4 -4 -4 -4
- auto handle = backend->compile(f);
- handle->call_with_validate({y}, {x});
- EXPECT_EQ((vector<output_c_type>{3, 3, 3, -3, -3, -3, 4, 4, 4, -4, -4, -4}),
- read_vector<output_c_type>(y));
+ auto test_case = test::TestCase<TestEngine>(f);
+ test_case.add_input<input_c_type>({x});
+ test_case.add_expected_output<output_c_type>(input_shape,
+ {3, 3, 3, -3, -3, -3, 4, 4, 4, -4, -4, -4});
+ test_case.run();
}
NGRAPH_TEST(${BACKEND_NAME}, quantize_ROUND_TOWARD_ZERO)
static_cast<op::Quantize::RoundMode>(static_cast<int>(round_mode)));
auto f = make_shared<Function>(quantize, ParameterVector{X});
- auto backend = runtime::Backend::create("${BACKEND_NAME}");
- auto x = backend->create_tensor(input_type, input_shape);
- auto y = backend->create_tensor(output_type, input_shape);
-
- copy_data(x, vector<input_c_type>{9, 10, 11, -9, -10, -11, 13, 14, 15, -13, -14, -15});
+ std::vector<input_c_type> x{9, 10, 11, -9, -10, -11, 13, 14, 15, -13, -14, -15};
// divide by scale 4 4 4 4 4 4 4 4 4 4 4 4
// equals (rounded) 2 2 2 -2 -2 -2 3 3 3 -3 -3 -3
- auto handle = backend->compile(f);
- handle->call_with_validate({y}, {x});
- EXPECT_EQ((vector<output_c_type>{2, 2, 2, -2, -2, -2, 3, 3, 3, -3, -3, -3}),
- read_vector<output_c_type>(y));
+ auto test_case = test::TestCase<TestEngine>(f);
+ test_case.add_input<input_c_type>({x});
+ test_case.add_expected_output<output_c_type>(input_shape,
+ {2, 2, 2, -2, -2, -2, 3, 3, 3, -3, -3, -3});
+ test_case.run();
}
NGRAPH_TEST(${BACKEND_NAME}, quantize_ROUND_UP)
make_shared<op::Quantize>(X, scale, offset, output_type, quantization_axes, round_mode);
auto f = make_shared<Function>(quantize, ParameterVector{X});
- auto backend = runtime::Backend::create("${BACKEND_NAME}");
- auto x = backend->create_tensor(input_type, input_shape);
- auto y = backend->create_tensor(output_type, input_shape);
-
- copy_data(x, vector<input_c_type>{9, 10, 11, -9, -10, -11, 13, 14, 15, -13, -14, -15});
+ std::vector<input_c_type> x{9, 10, 11, -9, -10, -11, 13, 14, 15, -13, -14, -15};
// divide by scale 4 4 4 4 4 4 4 4 4 4 4 4
// equals (rounded) 3 3 3 -2 -2 -2 4 4 4 -3 -3 -3
- auto handle = backend->compile(f);
- handle->call_with_validate({y}, {x});
- EXPECT_EQ((vector<output_c_type>{3, 3, 3, -2, -2, -2, 4, 4, 4, -3, -3, -3}),
- read_vector<output_c_type>(y));
+ auto test_case = test::TestCase<TestEngine>(f);
+ test_case.add_input<input_c_type>({x});
+ test_case.add_expected_output<output_c_type>(input_shape,
+ {3, 3, 3, -2, -2, -2, 4, 4, 4, -3, -3, -3});
+ test_case.run();
}
NGRAPH_TEST(${BACKEND_NAME}, quantize_ROUND_DOWN)
make_shared<op::Quantize>(X, scale, offset, output_type, quantization_axes, round_mode);
auto f = make_shared<Function>(quantize, ParameterVector{X});
- auto backend = runtime::Backend::create("${BACKEND_NAME}");
- auto x = backend->create_tensor(input_type, input_shape);
- auto y = backend->create_tensor(output_type, input_shape);
-
- copy_data(x, vector<input_c_type>{9, 10, 11, -9, -10, -11, 13, 14, 15, -13, -14, -15});
+ std::vector<input_c_type> x{9, 10, 11, -9, -10, -11, 13, 14, 15, -13, -14, -15};
// divide by scale 4 4 4 4 4 4 4 4 4 4 4 4
// equals (rounded) 2 2 2 -3 -3 -3 3 3 3 -4 -4 -4
- auto handle = backend->compile(f);
- handle->call_with_validate({y}, {x});
- EXPECT_EQ((vector<output_c_type>{2, 2, 2, -3, -3, -3, 3, 3, 3, -4, -4, -4}),
- read_vector<output_c_type>(y));
+ auto test_case = test::TestCase<TestEngine>(f);
+ test_case.add_input<input_c_type>({x});
+ test_case.add_expected_output<output_c_type>(input_shape,
+ {2, 2, 2, -3, -3, -3, 3, 3, 3, -4, -4, -4});
+ test_case.run();
}
NGRAPH_TEST(${BACKEND_NAME}, dequantize_dynamic_offset)
auto dequantize = make_shared<op::Dequantize>(X, scale, offset, output_type, quantization_axes);
auto f = make_shared<Function>(dequantize, ParameterVector{X, scale, offset});
- auto backend = runtime::Backend::create("${BACKEND_NAME}");
- auto x = backend->create_tensor(input_type, input_shape);
- auto y = backend->create_tensor(output_type, input_shape);
- auto Scale = backend->create_tensor(output_type, scale_offset_shape);
- auto Offset = backend->create_tensor(input_type, scale_offset_shape);
-
- copy_data(x, vector<input_c_type>{0, 3, 128, 255});
- copy_data(Scale, vector<output_c_type>{2});
- copy_data(Offset, vector<input_c_type>{128});
-
- auto handle = backend->compile(f);
- handle->call_with_validate({y}, {x, Scale, Offset});
- EXPECT_TRUE(test::all_close_f((vector<output_c_type>{-256.0f, -250.0f, 0.0f, 254.0f}),
- read_vector<output_c_type>(y),
- MIN_FLOAT_TOLERANCE_BITS));
+ std::vector<input_c_type> x{0, 3, 128, 255};
+ std::vector<output_c_type> Scale{2};
+ std::vector<input_c_type> Offset{128};
+
+ auto test_case = test::TestCase<TestEngine>(f);
+ test_case.add_input<input_c_type>({x});
+ test_case.add_input<output_c_type>({Scale});
+ test_case.add_input<input_c_type>({Offset});
+
+ test_case.add_expected_output<output_c_type>(input_shape, {-256.0f, -250.0f, 0.0f, 254.0f});
+ test_case.run(MIN_FLOAT_TOLERANCE_BITS);
}
NGRAPH_TEST(${BACKEND_NAME}, quantize_dynamic_offset)
make_shared<op::Quantize>(X, scale, offset, output_type, quantization_axes, round_mode);
auto f = make_shared<Function>(quantize, ParameterVector{X, scale, offset});
- auto backend = runtime::Backend::create("${BACKEND_NAME}");
- auto x = backend->create_tensor(input_type, input_shape);
- auto y = backend->create_tensor(output_type, input_shape);
- auto Scale = backend->create_tensor(input_type, scale_offset_shape);
- auto Offset = backend->create_tensor(output_type, scale_offset_shape);
-
- copy_data(x, vector<input_c_type>{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11});
+ std::vector<input_c_type> x{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
// divide by scale 2 2 2 2 2 2 2 2 2 2 2 2
// equals (rounded) 0 0 1 2 2 2 3 4 4 4 5 6
// plus offset 1 1 1 1 1 1 1 1 1 1 1 1
// equals 1 1 2 3 3 3 4 5 5 5 6 7
- copy_data(Scale, vector<input_c_type>{2});
- copy_data(Offset, vector<output_c_type>{1});
+ std::vector<input_c_type> Scale{2};
+ std::vector<output_c_type> Offset{1};
+
+ auto test_case = test::TestCase<TestEngine>(f);
+ test_case.add_input<input_c_type>({x});
+ test_case.add_input<input_c_type>({Scale});
+ test_case.add_input<output_c_type>({Offset});
- auto handle = backend->compile(f);
- handle->call_with_validate({y}, {x, Scale, Offset});
- EXPECT_EQ((vector<output_c_type>{1, 1, 2, 3, 3, 3, 4, 5, 5, 5, 6, 7}),
- read_vector<output_c_type>(y));
+ test_case.add_expected_output<output_c_type>(input_shape, {1, 1, 2, 3, 3, 3, 4, 5, 5, 5, 6, 7});
+ test_case.run();
}