Skip to content

Commit 59c8d8b

Browse files
authored
reexport math constant to dialect (#448)
1 parent f7474f2 commit 59c8d8b

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

src/kirin/dialects/math/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
"math dialect, modeling functions in python's `math` stdlib" # This file is generated by gen.py
22

3+
import math as pymath
4+
35
from kirin import lowering
46
from kirin.dialects.math.dialect import dialect as dialect
57

68
from . import stmts as stmts, interp as interp
79

10+
pi = pymath.pi
11+
e = pymath.e
12+
tau = pymath.tau
13+
814

915
@lowering.wraps(stmts.acos)
1016
def acos(x: float) -> float: ...

src/kirin/dialects/math/_gen.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,12 @@ class MathMethodTable(MethodTable):
109109
f.write("# This file is generated by gen.py\n")
110110
f.write("from kirin.dialects.math.dialect import dialect as dialect\n")
111111
f.write("from . import stmts as stmts, interp as interp\n")
112-
112+
f.write("import math as pymath\n")
113+
f.write("pi = pymath.pi\n")
114+
f.write("e = pymath.e\n")
115+
f.write("tau = pymath.tau\n")
113116
f.write("from kirin import lowering2\n")
117+
114118
for name, obj, sig in builtin_math_functions():
115119
f.write(
116120
textwrap.dedent(

test/dialects/math/test_const.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import math as pymath
2+
3+
from kirin.dialects import math
4+
5+
6+
def test_const():
7+
assert math.pi == pymath.pi
8+
assert math.e == pymath.e
9+
assert math.tau == pymath.tau

0 commit comments

Comments
 (0)