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 //*****************************************************************************
22 #include "gtest/gtest.h"
23 #include "ngraph/log.hpp"
24 #include "ngraph/ngraph.hpp"
25 #include "runtime/interpreter/int_executable.hpp"
26 #include "util/test_tools.hpp"
28 NGRAPH_SUPPRESS_DEPRECATED_START
31 using namespace ngraph;
33 TEST(INTERPRETER, nan_check_input)
36 auto A = make_shared<op::Parameter>(element::f32, shape);
37 auto B = make_shared<op::Parameter>(element::f32, shape);
38 auto f = make_shared<Function>(make_shared<op::Divide>(A, B), ParameterVector{A, B});
40 shared_ptr<runtime::Backend> backend = runtime::Backend::create("INTERPRETER");
42 // Create some tensors for input/output
43 auto a = backend->create_tensor(element::f32, shape);
44 copy_data(a, vector<float>{2, 4, NAN, 16});
45 auto b = backend->create_tensor(element::f32, shape);
46 copy_data(b, vector<float>{1, 2, 1, 8});
47 auto result = backend->create_tensor(element::f32, shape);
49 shared_ptr<runtime::Executable> handle = backend->compile(f);
51 shared_ptr<runtime::interpreter::INTExecutable> ihandle =
52 static_pointer_cast<runtime::interpreter::INTExecutable>(handle);
53 ihandle->set_nan_check(true);
54 EXPECT_ANY_THROW(handle->call_with_validate({result}, {a, b}));
57 TEST(INTERPRETER, nan_check_output)
60 auto A = make_shared<op::Parameter>(element::f32, shape);
61 auto B = make_shared<op::Parameter>(element::f32, shape);
62 auto f = make_shared<Function>(make_shared<op::Divide>(A, B), ParameterVector{A, B});
64 shared_ptr<runtime::Backend> backend = runtime::Backend::create("INTERPRETER");
66 // Create some tensors for input/output
67 auto a = backend->create_tensor(element::f32, shape);
68 copy_data(a, vector<float>{2, 4, 0, 16});
69 auto b = backend->create_tensor(element::f32, shape);
70 copy_data(b, vector<float>{1, 2, 0, 8});
71 auto result = backend->create_tensor(element::f32, shape);
73 shared_ptr<runtime::Executable> handle = backend->compile(f);
74 shared_ptr<runtime::interpreter::INTExecutable> ihandle =
75 static_pointer_cast<runtime::interpreter::INTExecutable>(handle);
76 ihandle->set_nan_check(true);
77 EXPECT_ANY_THROW(handle->call_with_validate({result}, {a, b}));