Skip to content
This repository was archived by the owner on Oct 11, 2025. It is now read-only.

Commit 29cd84a

Browse files
authored
[MLIR][Python] enhance python api for tensor.empty (#103087)
Since we have extended `EmptyOp`, maybe we should also provide a corresponding `tensor.empty` method. In the downstream usage, I tend to use APIs with all lowercase letters to create ops, so having a `tensor.empty` to replace the extended `tensor.EmptyOp` would keep my code style consistent.
1 parent 86347f6 commit 29cd84a

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

mlir/python/mlir/dialects/tensor.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
from typing import Sequence, Union
1515
from ._ods_common import _cext as _ods_cext
16+
from ._ods_common import get_op_result_or_op_results as _get_op_result_or_op_results
1617

1718

1819
@_ods_cext.register_operation(_Dialect, replace=True)
@@ -43,6 +44,18 @@ def __init__(
4344
super().__init__(result_type, dynamic_sizes, loc=loc, ip=ip)
4445

4546

47+
def empty(
48+
sizes: Sequence[Union[int, Value]],
49+
element_type: Type,
50+
*,
51+
loc=None,
52+
ip=None,
53+
) -> _ods_cext.ir.Value:
54+
return _get_op_result_or_op_results(
55+
EmptyOp(sizes=sizes, element_type=element_type, loc=loc, ip=ip)
56+
)
57+
58+
4659
generate = region_op(
4760
lambda result, dynamic_extents: GenerateOp(result, dynamic_extents),
4861
terminator=lambda args: YieldOp(args[0]),

0 commit comments

Comments
 (0)