forked from openvinotoolkit/openvino
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdimension.cpp
122 lines (101 loc) · 3.83 KB
/
dimension.cpp
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
// Copyright (C) 2018-2023 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include "ngraph/dimension.hpp"
#include "gtest/gtest.h"
using namespace std;
using namespace ngraph;
TEST(dimension, broadcast_merge_static_1_and_10) {
Dimension result;
Dimension one(1), ten(10);
bool success = Dimension::broadcast_merge(result, one, ten);
EXPECT_TRUE(success);
EXPECT_EQ(result, ten);
}
TEST(dimension, broadcast_merge_static_1_5_and_10_15) {
Dimension result;
Dimension one(1, 5), ten(10, 15);
bool success = Dimension::broadcast_merge(result, one, ten);
EXPECT_TRUE(success);
EXPECT_EQ(result, ten);
}
TEST(dimension, broadcast_merge_static_1_12_and_10_15) {
Dimension result;
Dimension one(1, 12), ten(10, 15);
bool success = Dimension::broadcast_merge(result, one, ten);
EXPECT_TRUE(success);
EXPECT_EQ(result, ten);
}
TEST(dimension, broadcast_merge_static_7_12_and_10_15) {
Dimension result;
Dimension one(7, 12), ten(10, 15);
bool success = Dimension::broadcast_merge(result, one, ten);
EXPECT_TRUE(success);
EXPECT_EQ(result, Dimension(10, 12));
}
TEST(dimension, broadcast_merge_static_0_12_and_1_15) {
Dimension result;
Dimension one(0, 12), ten(1, 15);
bool success = Dimension::broadcast_merge(result, one, ten);
EXPECT_TRUE(success);
EXPECT_EQ(result, Dimension(0, 15));
}
TEST(dimension, dimension_mul_operator_ordinary_intervals) {
Dimension interval_1(0, 10);
Dimension interval_2(2, 100);
Dimension ref_value(0, 1000);
EXPECT_EQ(ref_value, interval_1 * interval_2);
}
TEST(dimension, dimension_mul_operator_1) {
Dimension fully_dynamic_dim(-1);
Dimension two(2);
Dimension ref_value(-1);
EXPECT_EQ(ref_value, fully_dynamic_dim * two);
}
TEST(dimension, dimension_mul_operator_2) {
// overflow happens and clip_times keeps result within in64 limits
// (Interval::s_max - 1) * 2 = 9223372036854775806 * 2 = 18446744073709551612
// arithmetical result does not fit into int64, is clipped into int64_max
Dimension large_interval(2, Interval::s_max - 1);
Dimension two(2);
Dimension ref_value(4, Interval::s_max);
EXPECT_EQ(ref_value, large_interval * two);
}
TEST(dimension, dimension_mul_operator_3) {
// no overflow
// (int64_max / 2) * 2= 4611686018427387903 * 2 = 9223372036854775806 = int64_max - 1
Dimension large_interval(2, ov::Interval::s_max / 2);
Dimension two(2);
Dimension ref_value(4, ov::Interval::s_max - 1);
EXPECT_EQ(ref_value, large_interval * two);
}
TEST(dimension, dimension_mul_operator_4) {
// overflow happens and clip_times keeps result within in64 limits
// (int64_max / 2 + 1) * 2 = 4611686018427387904 * 2 = 9223372036854775808 = int64_max + 1
// 9223372036854775808 does not fit into int64, is clipped into int64_max
Dimension large_interval(2, ov::Interval::s_max / 2 + 1);
Dimension two(2);
Dimension ref_value(4, ov::Interval::s_max);
EXPECT_EQ(ref_value, large_interval * two);
}
TEST(dimension, dimension_mul_operator_5) {
// (int64_max / 3 + 2) = 3074457345618258604 * 3 = 9223372036854775812 = int64_max + 5
// overflow happens and clip_times keeps result within in64 limits
// 9223372036854775812 does not fit into int64, is clipped into int64_max
Dimension large_interval(2, ov::Interval::s_max / 3 + 2);
Dimension three(3);
Dimension ref_value(6, ov::Interval::s_max);
EXPECT_EQ(ref_value, large_interval * three);
}
TEST(dimension, division_of_static_dims_twenty_three_div_three_eq_seven) {
Dimension twenty_three(23);
Dimension::value_type three(3);
Dimension empty(8, 7);
EXPECT_EQ(empty, twenty_three / three);
}
TEST(dimension, division_of_static_dims) {
Dimension seven(7);
Dimension::value_type four(4);
Dimension empty(2, 1);
EXPECT_EQ(seven / four, empty);
}