Commit 104fd3ee authored by Robert Kimball's avatar Robert Kimball Committed by Scott Cyphers

add missing unit tests (#1373)

parent 0bddb26d
......@@ -156,7 +156,29 @@ NGRAPH_TEST(${BACKEND_NAME}, parameter_as_output)
EXPECT_EQ(read_vector<float>(result), expected);
}
NGRAPH_TEST(${BACKEND_NAME}, ab)
NGRAPH_TEST(${BACKEND_NAME}, add)
{
Shape shape{2, 2};
auto A = make_shared<op::Parameter>(element::f32, shape);
auto B = make_shared<op::Parameter>(element::f32, shape);
auto f = make_shared<Function>(make_shared<op::Add>(A, B), op::ParameterVector{A, B});
auto backend = runtime::Backend::create("${BACKEND_NAME}");
// Create some tensors for input/output
shared_ptr<runtime::TensorView> a = backend->create_tensor(element::f32, shape);
shared_ptr<runtime::TensorView> b = backend->create_tensor(element::f32, shape);
shared_ptr<runtime::TensorView> result = backend->create_tensor(element::f32, shape);
copy_data(a, test::NDArray<float, 2>({{1, 2}, {3, 4}}).get_vector());
copy_data(b, test::NDArray<float, 2>({{5, 6}, {7, 8}}).get_vector());
backend->call(f, {result}, {a, b});
EXPECT_EQ(read_vector<float>(result),
(test::NDArray<float, 2>({{6, 8}, {10, 12}})).get_vector());
}
NGRAPH_TEST(${BACKEND_NAME}, add_overload)
{
Shape shape{2, 2};
auto A = make_shared<op::Parameter>(element::f32, shape);
......@@ -178,6 +200,50 @@ NGRAPH_TEST(${BACKEND_NAME}, ab)
(test::NDArray<float, 2>({{6, 8}, {10, 12}})).get_vector());
}
NGRAPH_TEST(${BACKEND_NAME}, multiply)
{
Shape shape{2, 2};
auto A = make_shared<op::Parameter>(element::f32, shape);
auto B = make_shared<op::Parameter>(element::f32, shape);
auto f = make_shared<Function>(make_shared<op::Multiply>(A, B), op::ParameterVector{A, B});
auto backend = runtime::Backend::create("${BACKEND_NAME}");
// Create some tensors for input/output
shared_ptr<runtime::TensorView> a = backend->create_tensor(element::f32, shape);
shared_ptr<runtime::TensorView> b = backend->create_tensor(element::f32, shape);
shared_ptr<runtime::TensorView> result = backend->create_tensor(element::f32, shape);
copy_data(a, test::NDArray<float, 2>({{1, 2}, {3, 4}}).get_vector());
copy_data(b, test::NDArray<float, 2>({{5, 6}, {7, 8}}).get_vector());
backend->call(f, {result}, {a, b});
EXPECT_EQ(read_vector<float>(result),
(test::NDArray<float, 2>({{5, 12}, {21, 32}})).get_vector());
}
NGRAPH_TEST(${BACKEND_NAME}, multiply_overload)
{
Shape shape{2, 2};
auto A = make_shared<op::Parameter>(element::f32, shape);
auto B = make_shared<op::Parameter>(element::f32, shape);
auto f = make_shared<Function>(A * B, op::ParameterVector{A, B});
auto backend = runtime::Backend::create("${BACKEND_NAME}");
// Create some tensors for input/output
shared_ptr<runtime::TensorView> a = backend->create_tensor(element::f32, shape);
shared_ptr<runtime::TensorView> b = backend->create_tensor(element::f32, shape);
shared_ptr<runtime::TensorView> result = backend->create_tensor(element::f32, shape);
copy_data(a, test::NDArray<float, 2>({{1, 2}, {3, 4}}).get_vector());
copy_data(b, test::NDArray<float, 2>({{5, 6}, {7, 8}}).get_vector());
backend->call(f, {result}, {a, b});
EXPECT_EQ(read_vector<float>(result),
(test::NDArray<float, 2>({{5, 12}, {21, 32}})).get_vector());
}
NGRAPH_TEST(${BACKEND_NAME}, abc)
{
Shape shape{2, 2};
......@@ -784,6 +850,27 @@ NGRAPH_TEST(${BACKEND_NAME}, divide)
EXPECT_EQ((vector<float>{2, 2, 2, 2}), read_vector<float>(result));
}
NGRAPH_TEST(${BACKEND_NAME}, divide_overload)
{
Shape shape{2, 2};
auto A = make_shared<op::Parameter>(element::f32, shape);
auto B = make_shared<op::Parameter>(element::f32, shape);
auto f = make_shared<Function>(A / B, op::ParameterVector{A, B});
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>{2, 4, 8, 16});
auto b = backend->create_tensor(element::f32, shape);
copy_data(b, vector<float>{1, 2, 4, 8});
auto result = backend->create_tensor(element::f32, shape);
backend->call(f, {result}, {a, b});
EXPECT_EQ((vector<float>{2, 2, 2, 2}), read_vector<float>(result));
}
NGRAPH_TEST(${BACKEND_NAME}, divide_adjoint_stability)
{
auto backend = runtime::Backend::create("${BACKEND_NAME}");
......@@ -1616,6 +1703,26 @@ NGRAPH_TEST(${BACKEND_NAME}, subtract)
EXPECT_EQ((vector<float>{1, 2, 4, 8}), read_vector<float>(result));
}
NGRAPH_TEST(${BACKEND_NAME}, subtract_overload)
{
Shape shape{2, 2};
auto A = make_shared<op::Parameter>(element::f32, shape);
auto B = make_shared<op::Parameter>(element::f32, shape);
auto f = make_shared<Function>(A - B, op::ParameterVector{A, B});
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>{2, 4, 8, 16});
auto b = backend->create_tensor(element::f32, shape);
copy_data(b, vector<float>{1, 2, 4, 8});
auto result = backend->create_tensor(element::f32, shape);
backend->call(f, {result}, {a, b});
EXPECT_EQ((vector<float>{1, 2, 4, 8}), read_vector<float>(result));
}
NGRAPH_TEST(${BACKEND_NAME}, tensor_constant)
{
Shape shape{2, 2, 2};
......
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