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

Commit 66a465b

Browse files
authored
[mlir][python] Fix how the mlir variadic Python accessor _ods_equally_sized_accessor is used (#101132) (#106003)
As reported in llvm/llvm-project#101132, this fixes two bugs: 1. When accessing variadic operands inside an operation, it must be accessed as `self.operation.operands` instead of `operation.operands` 2. The implementation of the `equally_sized_accessor` function is doing wrong arithmetics when calculating the resulting index and group sizes. I have added a test for the `equally_sized_accessor` function, which did not have a test previously.
1 parent bd8016a commit 66a465b

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

mlir/python/mlir/dialects/_ods_common.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,21 +51,22 @@ def segmented_accessor(elements, raw_segments, idx):
5151

5252

5353
def equally_sized_accessor(
54-
elements, n_variadic, n_preceding_simple, n_preceding_variadic
54+
elements, n_simple, n_variadic, n_preceding_simple, n_preceding_variadic
5555
):
5656
"""
5757
Returns a starting position and a number of elements per variadic group
5858
assuming equally-sized groups and the given numbers of preceding groups.
5959
6060
elements: a sequential container.
61+
n_simple: the number of non-variadic groups in the container.
6162
n_variadic: the number of variadic groups in the container.
6263
n_preceding_simple: the number of non-variadic groups preceding the current
6364
group.
6465
n_preceding_variadic: the number of variadic groups preceding the current
6566
group.
6667
"""
6768

68-
total_variadic_length = len(elements) - n_variadic + 1
69+
total_variadic_length = len(elements) - n_simple
6970
# This should be enforced by the C++-side trait verifier.
7071
assert total_variadic_length % n_variadic == 0
7172

0 commit comments

Comments
 (0)