Skip to content

Commit c3160f8

Browse files
[mlir][sparse] Fix bug in new syntax parser (#66024)
Currently, dimlvlmap with identity affine map will be treated as empty affine map. But the new syntax would treat it as an actual identity affine map such as {d0} -> {d0}. This mismatch could raise an error when we are comparing sparse encodings.
1 parent 7b75094 commit c3160f8

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

mlir/lib/Dialect/SparseTensor/IR/Detail/DimLvlMap.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,15 +348,19 @@ AffineMap DimLvlMap::getDimToLvlMap(MLIRContext *context) const {
348348
lvlAffines.reserve(getLvlRank());
349349
for (const auto &lvlSpec : lvlSpecs)
350350
lvlAffines.push_back(lvlSpec.getExpr().getAffineExpr());
351-
return AffineMap::get(getDimRank(), getSymRank(), lvlAffines, context);
351+
auto map = AffineMap::get(getDimRank(), getSymRank(), lvlAffines, context);
352+
if (map.isIdentity()) return AffineMap();
353+
return map;
352354
}
353355

354356
AffineMap DimLvlMap::getLvlToDimMap(MLIRContext *context) const {
355357
SmallVector<AffineExpr> dimAffines;
356358
dimAffines.reserve(getDimRank());
357359
for (const auto &dimSpec : dimSpecs)
358360
dimAffines.push_back(dimSpec.getExpr().getAffineExpr());
359-
return AffineMap::get(getLvlRank(), getSymRank(), dimAffines, context);
361+
auto map = AffineMap::get(getLvlRank(), getSymRank(), dimAffines, context);
362+
if (map.isIdentity()) return AffineMap();
363+
return map;
360364
}
361365

362366
void DimLvlMap::dump() const {

0 commit comments

Comments
 (0)