Skip to content

Commit 04c94ba

Browse files
authored
[mlir][py] NFC: remove exception-based isa from linalg module (#92556)
When this code was written, we didn't have proper isinstance support for operation classes in Python. Now we do, so there is no reason to keep the expensive exception-based flow.
1 parent d6541fc commit 04c94ba

File tree

2 files changed

+3
-12
lines changed

2 files changed

+3
-12
lines changed

mlir/python/mlir/dialects/linalg/__init__.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@
5555
# TODO: guard against surprises and fail create Runtime Custom Ops with
5656
# the same name as existing Core Named Ops.
5757
from .opdsl.ops.core_named_ops import *
58-
from .opdsl.lang.emitter import isa
5958

6059
from ...ir import *
6160
from .._ods_common import get_op_result_or_value as _get_op_result_or_value
@@ -71,7 +70,7 @@ def transpose(
7170
if len(outs) > 1:
7271
raise ValueError(f"{outs=} must have length 1.")
7372
init = _get_op_result_or_value(outs[0])
74-
result_types = [init.type] if isa(RankedTensorType, init.type) else []
73+
result_types = [init.type] if isinstance(init.type, RankedTensorType) else []
7574

7675
op = TransposeOp(
7776
result=result_types,
@@ -93,7 +92,7 @@ def broadcast(
9392
if len(outs) > 1:
9493
raise ValueError(f"{outs=} must have length 1.")
9594
init = _get_op_result_or_value(outs[0])
96-
result_types = [init.type] if isa(RankedTensorType, init.type) else []
95+
result_types = [init.type] if isinstance(init.type, RankedTensorType) else []
9796

9897
op = BroadcastOp(
9998
result=result_types,

mlir/python/mlir/dialects/linalg/opdsl/lang/emitter.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,6 @@
3131
ValueList = Union[Sequence[Value], OpResultList]
3232

3333

34-
def isa(cls: Type, ty: Type):
35-
try:
36-
cls(ty)
37-
return True
38-
except ValueError:
39-
return False
40-
41-
4234
def prepare_common_structured_op(
4335
op_config: LinalgStructuredOpConfig,
4436
*ins: Value,
@@ -127,7 +119,7 @@ def prepare_common_structured_op(
127119
op_config, in_arg_defs, ins, out_arg_defs, outs
128120
)
129121

130-
result_types = [t for t in out_types if isa(RankedTensorType, t)]
122+
result_types = [t for t in out_types if isinstance(t, RankedTensorType)]
131123

132124
# Initialize the type dictionary with the predefined types.
133125
type_mapping = dict() # type: Dict[str, Type]

0 commit comments

Comments
 (0)