-
Notifications
You must be signed in to change notification settings - Fork 131
Expand file tree
/
Copy pathlcm.py
More file actions
102 lines (80 loc) · 2.62 KB
/
Copy pathlcm.py
File metadata and controls
102 lines (80 loc) · 2.62 KB
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
import os
import sys
sys.path.insert(0, os.path.join(os.path.dirname(__file__), ".."))
import infinicore
import torch
from framework import (
BaseOperatorTest,
GenericTestRunner,
TensorSpec,
TestCase,
is_broadcast,
)
_TEST_CASES_DATA = [
((13, 4), None, None, None),
((13, 4), (10, 1), (10, 1), None),
((13, 4, 4), None, None, None),
((13, 4, 4), (20, 4, 1), (20, 4, 1), None),
((16, 5632), None, None, None),
]
_TOLERANCE_MAP = {
infinicore.int8: {"atol": 0, "rtol": 0},
infinicore.int16: {"atol": 0, "rtol": 0},
infinicore.int32: {"atol": 0, "rtol": 0},
infinicore.int64: {"atol": 0, "rtol": 0},
}
_TENSOR_DTYPES = [
infinicore.int8,
infinicore.int16,
infinicore.int32,
infinicore.int64,
]
def parse_test_cases():
test_cases = []
for data in _TEST_CASES_DATA:
shape = data[0]
a_strides = data[1] if len(data) > 1 else None
b_strides = data[2] if len(data) > 2 else None
c_strides = data[3] if len(data) > 3 else None
c_supports_inplace = not is_broadcast(c_strides)
for dtype in _TENSOR_DTYPES:
tol = _TOLERANCE_MAP.get(dtype, {"atol": 0, "rtol": 0})
a_spec = TensorSpec.from_tensor(shape, a_strides, dtype, name="a")
b_spec = TensorSpec.from_tensor(shape, b_strides, dtype, name="b")
c_spec = TensorSpec.from_tensor(shape, c_strides, dtype, name="c")
test_cases.append(
TestCase(
inputs=[a_spec, b_spec],
kwargs={},
output_spec=None,
comparison_target=None,
tolerance=tol,
description="lcm - OUT_OF_PLACE",
)
)
if c_supports_inplace:
test_cases.append(
TestCase(
inputs=[a_spec, b_spec],
kwargs=None,
output_spec=c_spec,
comparison_target="out",
tolerance=tol,
description="lcm - INPLACE(out)",
)
)
return test_cases
class OpTest(BaseOperatorTest):
def __init__(self):
super().__init__("Lcm")
def get_test_cases(self):
return parse_test_cases()
def torch_operator(self, *args, **kwargs):
return torch.lcm(*args, **kwargs)
def infinicore_operator(self, *args, **kwargs):
return infinicore.lcm(*args, **kwargs)
def main():
runner = GenericTestRunner(OpTest)
runner.run_and_exit()
if __name__ == "__main__":
main()