forked from iree-org/iree-comparative-benchmark
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils_test.py
53 lines (42 loc) · 1.46 KB
/
utils_test.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
# Copyright 2023 The OpenXLA Authors
#
# Licensed under the Apache License v2.0 with LLVM Exceptions.
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
import numpy as np
import unittest
import utils
class UtilsTest(unittest.TestCase):
def test_compare_tensors(self):
verdicts = utils.compare_tensors(
outputs=(np.array([0]), np.array([0.1, 0.1]), np.array([10])),
expects=(np.array([-1]), np.array([0.1, 0.2]), np.array([11])),
absolute_tolerance=0.2,
relative_tolerance=0.1,
)
self.assertEqual(
verdicts,
[
(False, 1),
(True, 0.1),
# It's equal because abs(10 - 11) <= 0.2 + 0.1 * 11
(True, 1),
])
def test_compare_tensors_mismatch_outputs(self):
self.assertRaises(
ValueError, lambda: utils.compare_tensors(
outputs=(np.array([0]),),
expects=(np.array([0]), np.array([1])),
))
def test_check_tensor_outputs(self):
utils.check_tensor_outputs(outputs=(np.array([0]),),
expects=(np.array([-1]),),
absolute_tolerance=10)
def test_check_tensor_outputs_raise_error(self):
self.assertRaises(
ValueError, lambda: utils.check_tensor_outputs(
outputs=(np.array([0]),),
expects=(np.array([-1]),),
))
if __name__ == "__main__":
unittest.main()