Skip to content

Commit 4d9f1a4

Browse files
committed
[fixup] Clarify some early-return cases
Signed-off-by: Artem Gindinson <[email protected]>
1 parent 31ea4ea commit 4d9f1a4

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

mlir/lib/Dialect/Utils/ReshapeOpsUtils.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,10 @@ mlir::getReassociationIndicesForCollapse(ArrayRef<int64_t> sourceShape,
293293
ArrayRef<int64_t> targetShape) {
294294
unsigned numSourceDims = sourceShape.size(),
295295
numTargetDims = targetShape.size();
296+
// We're supposed to search for a collapsing reassociation. If the sizes
297+
// match, there's no actual collapsing taking place - it's either a no-op or a
298+
// `tensor.reshape`-style reassociation (that would be beyond the scope of
299+
// this utility).
296300
if (numSourceDims <= numTargetDims)
297301
return std::nullopt;
298302
// Early handling for scalar target types.

mlir/unittests/Dialect/Utils/ReshapeOpsUtilsTest.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,14 @@ TEST(ReassociationIndicesForCollapse, StaticTest) {
5454
}
5555

5656
TEST(ReassociationIndicesForCollapse, StaticTestFailure) {
57-
EXPECT_EQ(getReassociationIndicesForCollapse({10, 20}, {10}), std::nullopt);
57+
// No-op reassociation
5858
EXPECT_EQ(getReassociationIndicesForCollapse({10, 20}, {10, 20}),
5959
std::nullopt);
60+
// Invalid static reassociations
61+
EXPECT_EQ(getReassociationIndicesForCollapse({10, 20}, {10}), std::nullopt);
6062
EXPECT_EQ(getReassociationIndicesForCollapse({10, 20, 30}, {200, 300}),
6163
std::nullopt);
64+
// Non-collapsing (expanding) reassociation
6265
EXPECT_EQ(getReassociationIndicesForCollapse({10, 20, 30}, {1, 10, 20, 30}),
6366
std::nullopt);
6467
}

0 commit comments

Comments
 (0)