forked from openvinotoolkit/openvino
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_tf_FloorDiv.py
133 lines (106 loc) · 5.21 KB
/
test_tf_FloorDiv.py
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# Copyright (C) 2018-2025 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
import numpy as np
import pytest
import platform
from common.tf_layer_test_class import CommonTFLayerTest
rng = np.random.default_rng()
def list_arm_platforms():
return ['arm', 'armv7l', 'aarch64', 'arm64', 'ARM64']
class TestFloorDiv(CommonTFLayerTest):
def create_add_placeholder_const_net(self, x_shape, dtype, ir_version, use_legacy_frontend):
import tensorflow as tf
self.dtype = dtype
tf.compat.v1.reset_default_graph()
# Create the graph and model
with tf.compat.v1.Session() as sess:
x = tf.compat.v1.placeholder(dtype, x_shape, 'Input')
constant_value = np.array(-10).astype(dtype)
y = tf.constant(constant_value)
res = tf.raw_ops.FloorDiv(x=x, y=y)
tf.compat.v1.global_variables_initializer()
tf_net = sess.graph_def
ref_net = None
return tf_net, ref_net
def _prepare_input(self, inputs_info):
tensor_name = list(inputs_info.keys())[0]
x_shape = inputs_info[tensor_name]
inputs_data = {}
if np.issubdtype(self.dtype, np.floating):
inputs_data[tensor_name] = rng.uniform(-5.0, 5.0, x_shape).astype(self.dtype)
elif np.issubdtype(self.dtype, np.signedinteger):
inputs_data[tensor_name] = rng.integers(-8, 8, x_shape).astype(self.dtype)
else:
inputs_data[tensor_name] = rng.integers(0, 8, x_shape).astype(self.dtype)
return inputs_data
# TODO: implement tests for 2 Consts + Add
test_data_1D = [
dict(x_shape=[], dtype=np.int32),
dict(x_shape=[2], dtype=np.int64),
dict(x_shape=[2, 4, 5], dtype=np.int32),
dict(x_shape=[2, 4, 5], dtype=np.uint32),
dict(x_shape=[2, 4, 5], dtype=np.uint64),
dict(x_shape=[], dtype=np.float32),
dict(x_shape=[2], dtype=np.float64),
dict(x_shape=[2, 4, 5], dtype=np.float32),
]
@pytest.mark.parametrize("params", test_data_1D)
@pytest.mark.nightly
@pytest.mark.precommit
def test_add_placeholder_const_1D(self, params, ie_device, precision, ir_version, temp_dir,
use_legacy_frontend):
if platform.system() == 'Linux' and platform.machine() in list_arm_platforms() and np.issubdtype(params['dtype'], np.signedinteger):
pytest.xfail(reason='Ticket CVS-132377 - Divide inconsistent behavior on different systems')
elif platform.system() == 'Darwin' and platform.machine() in list_arm_platforms():
pytest.xfail(reason='Ticket - 132699')
self._test(*self.create_add_placeholder_const_net(**params, ir_version=ir_version,
use_legacy_frontend=use_legacy_frontend),
ie_device, precision, ir_version, temp_dir=temp_dir,
use_legacy_frontend=use_legacy_frontend)
class TestFloorDivStaticInput(CommonTFLayerTest):
min = -100
max = 200
step = 1
dtype = np.int32
def create_flordiv_tf_net(self, min, max, step, y, dtype, ir_version, use_legacy_frontend):
import tensorflow as tf
x = np.arange(min, max, step, dtype=dtype)
self.min = min
self.max = max
self.step = step
self.dtype = dtype
tf.compat.v1.reset_default_graph()
with tf.compat.v1.Session() as sess:
x = tf.compat.v1.placeholder(dtype, x.shape, 'Input')
y = tf.constant(np.array(y).astype(dtype))
res = tf.raw_ops.FloorDiv(x=x, y=y)
tf.compat.v1.global_variables_initializer()
tf_net = sess.graph_def
ref_net = None
return tf_net, ref_net
def _prepare_input(self, inputs_dict):
for input in inputs_dict.keys():
inputs_dict[input] = np.arange(self.min, self.max, self.step, dtype=self.dtype)
return inputs_dict
test_inputs = [
dict(min=-20, max=20, step=1, y=[10]),
dict(min=-20, max=20, step=1, y=[5]),
dict(min=-20, max=20, step=1, y=[6]),
dict(min=-20, max=20, step=1, y=[-5]),
dict(min=-20, max=20, step=1, y=[-6]),
dict(min=-1e5, max=1e5, step=100, y=[1e5]),
]
@pytest.mark.parametrize("params", test_inputs)
@pytest.mark.parametrize("dtype", [np.int32, np.int64])
@pytest.mark.nightly
@pytest.mark.precommit
@pytest.mark.xfail(condition=platform.system() == 'Linux' and platform.machine() in list_arm_platforms(),
reason='Ticket CVS-132377 - Divide inconsistent behavior on different systems')
@pytest.mark.xfail(condition=platform.system() == 'Darwin' and platform.machine() in list_arm_platforms(),
reason='Ticket - 132699')
def test_floordiv(self, params, dtype, ie_device, precision, ir_version, temp_dir,
use_legacy_frontend):
self._test(*self.create_flordiv_tf_net(**params, dtype=dtype, ir_version=ir_version,
use_legacy_frontend=use_legacy_frontend),
ie_device, precision, ir_version, temp_dir=temp_dir,
use_legacy_frontend=use_legacy_frontend)