[Mlir-commits] [mlir] [mlir][presburger] Implement moveColumns using std::rotate (PR #168243)
lonely eagle
llvmlistbot at llvm.org
Fri Nov 21 21:07:56 PST 2025
================
@@ -276,23 +270,25 @@ void Matrix<T>::moveColumns(unsigned srcPos, unsigned num, unsigned dstPos) {
assert(dstPos + num <= getNumColumns() &&
"move destination range exceeds matrix columns");
- unsigned insertCount = offset > 0 ? offset : -offset;
- unsigned finalAdjStart = offset > 0 ? srcPos : srcPos + num;
- unsigned curAdjStart = offset > 0 ? srcPos + num : dstPos;
- // TODO: This can be done using std::rotate.
- // Insert new zero columns in the positions where the adjacent columns are to
- // be moved.
- insertColumns(finalAdjStart, insertCount);
- // Update curAdjStart if insertion of new columns invalidates it.
- if (finalAdjStart < curAdjStart)
- curAdjStart += insertCount;
-
- // Swap the adjacent columns with inserted zero columns.
- for (unsigned i = 0; i < insertCount; ++i)
- swapColumns(finalAdjStart + i, curAdjStart + i);
-
- // Delete the now redundant zero columns.
- removeColumns(curAdjStart, insertCount);
+ unsigned numRows = getNumRows();
+ unsigned numCols = getNumReservedColumns();
+
+ if (offset > 0) {
+ // shift the matrix left, see
+ // https://en.cppreference.com/w/cpp/algorithm/rotate.html.
+ for (unsigned i = 0; i < numRows; ++i) {
+ auto begin = data.begin() + i * numCols + srcPos;
+ auto end = data.begin() + i * numCols + dstPos + num;
+ std::rotate(begin, begin + num, end);
+ }
+ } else {
+ // shift the matrix right.
+ for (unsigned i = 0; i < numRows; ++i) {
+ auto begin = data.begin() + i * numCols + srcPos + num;
+ auto end = data.begin() + i * numCols + dstPos;
----------------
linuxlonelyeagle wrote:
I also find the naming conventions for "start" and "end" here quite confusing. However, I don't have any better suggestions, so thank you for your advice.
https://github.com/llvm/llvm-project/pull/168243
More information about the Mlir-commits
mailing list