forked from pybind/python_example
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_foo.py
More file actions
78 lines (65 loc) · 2.38 KB
/
Copy pathtest_foo.py
File metadata and controls
78 lines (65 loc) · 2.38 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
# Copyright 2020 Yong Tang. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
"""test_foo"""
import foo
def test_simple():
"""test_simple"""
@foo.jit
def simple_fn():
"""simple_doc"""
mlir_exp = r"""
CHECK-LABEL: func @simple_fn() {
CHECK-NEXT: "std.return"() : () -> ()
CHECK-NEXT: }
"""
assert simple_fn.__doc__ == "simple_doc"
assert simple_fn.__name__ == "simple_fn"
assert simple_fn.signature is None
assert simple_fn.check(mlir_exp)
def test_function():
"""test_function"""
@foo.jit
def fn_const():
return 5
exp_const = r"""
CHECK-LABEL: func @fn_const() -> !foo.int {
CHECK-NEXT: %0 = "foo.const"() {value = "5" : !foo.int} : () -> !foo.int
CHECK-NEXT: "std.return"(%0) : (!foo.int) -> ()
CHECK-NEXT: }
"""
assert fn_const.check(exp_const)
@foo.jit
def fn_unary():
return -5
exp_unary = r"""
CHECK-LABEL: func @fn_unary() -> !foo.opaque {
CHECK-NEXT: %0 = "foo.const"() {value = "5" : !foo.int} : () -> !foo.int
CHECK-NEXT: %1 = "foo.unary"(%0) {kind = "usub" : !foo.op} : (!foo.int) -> !foo.opaque
CHECK-NEXT: "std.return"(%1) : (!foo.opaque) -> ()
CHECK-NEXT: }
"""
assert fn_unary.check(exp_unary)
@foo.jit
def fn_binary():
return 3 + 5
exp_binary = r"""
CHECK-LABEL: func @fn_binary() -> !foo.opaque {
CHECK-NEXT: %0 = "foo.const"() {value = "3" : !foo.int} : () -> !foo.int
CHECK-NEXT: %1 = "foo.const"() {value = "5" : !foo.int} : () -> !foo.int
CHECK-NEXT: %2 = "foo.binary"(%0, %1) {kind = "add" : !foo.op} : (!foo.int, !foo.int) -> !foo.opaque
CHECK-NEXT: "std.return"(%2) : (!foo.opaque) -> ()
CHECK-NEXT: }
"""
assert fn_binary.check(exp_binary)