forked from llvm/torch-mlir
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconstants.py
88 lines (68 loc) · 2.06 KB
/
constants.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
# RUN: %PYTHON %s | npcomp-opt -split-input-file | FileCheck %s --dump-input=fail
from npcomp.compiler.numpy import test_config
import_global = test_config.create_import_dump_decorator()
# CHECK-LABEL: func @integer_constants
@import_global
def integer_constants():
# CHECK: %[[A:.*]] = constant 100 : i64
a = 100
# CHECK: %[[A_CAST:.*]] = basicpy.unknown_cast %[[A]] : i64 -> !basicpy.UnknownType
# CHECK: return %[[A_CAST]]
return a
# CHECK-LABEL: func @float_constants
@import_global
def float_constants():
# CHECK: %[[A:.*]] = constant 2.200000e+00 : f64
a = 2.2
# CHECK: %[[A_CAST:.*]] = basicpy.unknown_cast %[[A]] : f64 -> !basicpy.UnknownType
# CHECK: return %[[A_CAST]]
return a
# CHECK-LABEL: func @bool_true_constant
@import_global
def bool_true_constant():
# CHECK: %[[A:.*]] = basicpy.bool_constant true
# CHECK: basicpy.unknown_cast %[[A]]
a = True
return a
# CHECK-LABEL: func @bool_false_constant
@import_global
def bool_false_constant():
# CHECK: %[[A:.*]] = basicpy.bool_constant false
# CHECK: basicpy.unknown_cast %[[A]]
a = False
return a
# CHECK-LABEL: func @string_constant
@import_global
def string_constant():
# CHECK: %[[A:.*]] = basicpy.str_constant "foobar"
# CHECK: basicpy.unknown_cast %[[A]]
a = "foobar"
return a
# CHECK-LABEL: func @joined_string_constant
@import_global
def joined_string_constant():
# CHECK: %[[A:.*]] = basicpy.str_constant "I am still here"
# CHECK: basicpy.unknown_cast %[[A]]
a = "I am" " still here"
return a
# CHECK-LABEL: func @bytes_constant
@import_global
def bytes_constant():
# CHECK: %[[A:.*]] = basicpy.bytes_constant "foobar"
# CHECK: basicpy.unknown_cast %[[A]]
a = b"foobar"
return a
# CHECK-LABEL: func @ellipsis
@import_global
def ellipsis():
# CHECK: %[[A:.*]] = basicpy.singleton : !basicpy.EllipsisType
# CHECK: basicpy.unknown_cast %[[A]]
a = ...
return a
# CHECK-LABEL: func @none_constant
@import_global
def none_constant():
# CHECK: %[[A:.*]] = basicpy.singleton : !basicpy.NoneType
# CHECK: basicpy.unknown_cast %[[A]]
a = None
return a