Skip to content

Commit 0dd4db0

Browse files
committed
fix id init
1 parent 282901b commit 0dd4db0

File tree

3 files changed

+16
-14
lines changed

3 files changed

+16
-14
lines changed

caten/isl/specs/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from .aff import Aff
33
from .aff_list import AffList
44
from .ast_build import ASTBuild
5-
from .ast_expr import ASTExpr
5+
from .ast_expr import expr, ASTExpr
66
from .ast_node import ASTNode, ASTUserNode
77
from .ast_node_list import AstNodeList
88
from .ast_print_options import ASTPrintOptions
@@ -99,6 +99,7 @@
9999
"ScheduleConstraints",
100100
"ScheduleNode",
101101
"ASTBuild",
102+
"expr",
102103
"ASTExpr",
103104
"ASTNode",
104105
"StrideInfo",
@@ -132,4 +133,4 @@
132133
"ASTPrintOptions",
133134
"AstNodeList",
134135
"ASTUserNode",
135-
]
136+
]

caten/isl/specs/ast_expr.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,22 @@
2020

2121
_lib = load_libisl()
2222

23+
# handle is an integer, to prevent the confusion vs val, use I.expr instead of I.ASTExpr
24+
def expr(id_or_val: Any) -> "ASTExpr":
25+
if isinstance(id_or_val, int):
26+
from .val import Val
27+
return ASTExpr.from_val(Val.int_from_si(id_or_val))
28+
elif isinstance(id_or_val, str):
29+
from .id import Id
30+
return ASTExpr.from_id(Id(id_or_val))
31+
else:
32+
raise TypeError("I.expr can only accept int or str")
33+
2334
class ASTExpr(ISLObject, ISLObjectMixin):
2435
__slots__ = ()
2536

2637
def __init__(self, handle_or_spec: Any) -> None:
27-
if isinstance(handle_or_spec, str):
28-
handle = _isl_ast_expr_read_from_str(handle_or_spec, return_raw_pointer=True)
29-
super().__init__(handle)
30-
else:
31-
super().__init__(handle_or_spec)
38+
super().__init__(handle_or_spec)
3239

3340
def get_type_name(self) -> str:
3441
"""Helper to get the string name of the expr type."""

caten/isl/specs/val.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,7 @@ class Val(ISLObject, ISLObjectMixin):
2020
__slots__ = ()
2121

2222
def __init__(self, handle_or_spec: Any) -> None:
23-
if isinstance(handle_or_spec, str):
24-
handle = _isl_val_read_from_str(handle_or_spec, return_raw_pointer=True)
25-
super().__init__(handle)
26-
if isinstance(handle_or_spec, int):
27-
handle = _isl_val_int_from_si(handle_or_spec, return_raw_pointer=True)
28-
else:
29-
super().__init__(handle_or_spec)
23+
super().__init__(handle_or_spec)
3024

3125
@classmethod
3226
def from_str(cls, spec: str) -> Any:

0 commit comments

Comments
 (0)