1 //*****************************************************************************
2 // Copyright 2017-2020 Intel Corporation
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://www.apache.org/licenses/LICENSE-2.0
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //*****************************************************************************
25 #ifdef ${BACKEND_NAME}_FLOAT_TOLERANCE_BITS
26 #define DEFAULT_FLOAT_TOLERANCE_BITS ${BACKEND_NAME}_FLOAT_TOLERANCE_BITS
29 #ifdef ${BACKEND_NAME}_DOUBLE_TOLERANCE_BITS
30 #define DEFAULT_DOUBLE_TOLERANCE_BITS ${BACKEND_NAME}_DOUBLE_TOLERANCE_BITS
34 #include "gtest/gtest.h"
35 #include "runtime/backend.hpp"
36 #include "ngraph/runtime/tensor.hpp"
37 #include "ngraph/ngraph.hpp"
38 #include "util/all_close.hpp"
39 #include "util/all_close_f.hpp"
40 #include "util/ndarray.hpp"
41 #include "util/test_control.hpp"
42 #include "util/test_tools.hpp"
44 NGRAPH_SUPPRESS_DEPRECATED_START
47 using namespace ngraph;
49 static string s_manifest = "${MANIFEST}";
51 NGRAPH_TEST(${BACKEND_NAME}, minimum)
54 auto A = make_shared<op::Parameter>(element::f32, shape);
55 auto B = make_shared<op::Parameter>(element::f32, shape);
56 auto f = make_shared<Function>(make_shared<op::Minimum>(A, B), ParameterVector{A, B});
58 auto backend = runtime::Backend::create("${BACKEND_NAME}");
60 // Create some tensors for input/output
61 auto a = backend->create_tensor(element::f32, shape);
62 copy_data(a, vector<float>{1, 8, -8, 17, -0.5, 0.5, 2, 1});
63 auto b = backend->create_tensor(element::f32, shape);
64 copy_data(b, vector<float>{1, 2, 4, 8, 0, 0, 1, 1.5});
65 auto result = backend->create_tensor(element::f32, shape);
67 auto handle = backend->compile(f);
68 handle->call_with_validate({result}, {a, b});
70 test::all_close_f((vector<float>{1, 2, -8, 8, -.5, 0, 1, 1}), read_vector<float>(result)));
73 NGRAPH_TEST(${BACKEND_NAME}, minimum_int32)
76 auto A = make_shared<op::Parameter>(element::i32, shape);
77 auto B = make_shared<op::Parameter>(element::i32, shape);
78 auto f = make_shared<Function>(make_shared<op::Minimum>(A, B), ParameterVector{A, B});
80 auto backend = runtime::Backend::create("${BACKEND_NAME}");
82 // Create some tensors for input/output
83 auto a = backend->create_tensor(element::i32, shape);
84 copy_data(a, vector<int32_t>{1, 8, -8, 17, -5, 67635216, 2, 1});
85 auto b = backend->create_tensor(element::i32, shape);
86 copy_data(b, vector<int32_t>{1, 2, 4, 8, 0, 18448, 1, 6});
87 auto result = backend->create_tensor(element::i32, shape);
89 auto handle = backend->compile(f);
90 handle->call_with_validate({result}, {a, b});
91 EXPECT_EQ((vector<int32_t>{1, 2, -8, 8, -5, 18448, 1, 1}), read_vector<int32_t>(result));
94 NGRAPH_TEST(${BACKEND_NAME}, minimum_int64)
97 auto A = make_shared<op::Parameter>(element::i64, shape);
98 auto B = make_shared<op::Parameter>(element::i64, shape);
99 auto f = make_shared<Function>(make_shared<op::Minimum>(A, B), ParameterVector{A, B});
101 auto backend = runtime::Backend::create("${BACKEND_NAME}");
103 // Create some tensors for input/output
104 auto a = backend->create_tensor(element::i64, shape);
105 copy_data(a, vector<int64_t>{1, 8, -8, 17, -5, 67635216, 2, 17179887632});
106 auto b = backend->create_tensor(element::i64, shape);
107 copy_data(b, vector<int64_t>{1, 2, 4, 8, 0, 18448, 1, 280592});
108 auto result = backend->create_tensor(element::i64, shape);
110 auto handle = backend->compile(f);
111 handle->call_with_validate({result}, {a, b});
112 EXPECT_EQ((vector<int64_t>{1, 2, -8, 8, -5, 18448, 1, 280592}), read_vector<int64_t>(result));