[Mlir-commits] [mlir] [MLIR][Presburger] Add Gram-Schmidt (PR #70843)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Tue Oct 31 10:59:42 PDT 2023
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff a9b3f200159595ed8f13cc891ae34291020ba111 060e3c8f7f76e083723e4c303ec396447e6a1df3 -- mlir/include/mlir/Analysis/Presburger/Matrix.h mlir/include/mlir/Analysis/Presburger/Utils.h mlir/lib/Analysis/Presburger/Matrix.cpp mlir/lib/Analysis/Presburger/Utils.cpp mlir/unittests/Analysis/Presburger/MatrixTest.cpp
``````````
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/mlir/include/mlir/Analysis/Presburger/Matrix.h b/mlir/include/mlir/Analysis/Presburger/Matrix.h
index b591b0b4f..de3909fd8 100644
--- a/mlir/include/mlir/Analysis/Presburger/Matrix.h
+++ b/mlir/include/mlir/Analysis/Presburger/Matrix.h
@@ -269,7 +269,6 @@ public:
// Computes the Gram-Schmidt orthogonalisation
// of the matrix (cubic time).
FracMatrix gramSchmidt() const;
-
};
} // namespace presburger
diff --git a/mlir/lib/Analysis/Presburger/Matrix.cpp b/mlir/lib/Analysis/Presburger/Matrix.cpp
index 7669e461f..44a5c4580 100644
--- a/mlir/lib/Analysis/Presburger/Matrix.cpp
+++ b/mlir/lib/Analysis/Presburger/Matrix.cpp
@@ -552,23 +552,23 @@ Fraction FracMatrix::determinant(FracMatrix *inverse) const {
FracMatrix FracMatrix::gramSchmidt() const {
- // Create a copy of the argument to store
- // the orthogonalised version.
- FracMatrix orth(*this);
- Fraction projectionScale;
-
- // For each vector (row) in the matrix,
- // subtract its unit projection along
- // each of the previous vectors.
- // This ensures that it has no component
- // in the direction of any of the
- // previous vectors.
- for (unsigned i = 1; i < getNumRows(); i++) {
- for (unsigned j = 0; j < i; j++) {
- projectionScale = dotProduct(orth.getRow(i), orth.getRow(j)) /
- dotProduct(orth.getRow(j), orth.getRow(j));
- orth.addToRow(j, i, -projectionScale);
- }
+ // Create a copy of the argument to store
+ // the orthogonalised version.
+ FracMatrix orth(*this);
+ Fraction projectionScale;
+
+ // For each vector (row) in the matrix,
+ // subtract its unit projection along
+ // each of the previous vectors.
+ // This ensures that it has no component
+ // in the direction of any of the
+ // previous vectors.
+ for (unsigned i = 1; i < getNumRows(); i++) {
+ for (unsigned j = 0; j < i; j++) {
+ projectionScale = dotProduct(orth.getRow(i), orth.getRow(j)) /
+ dotProduct(orth.getRow(j), orth.getRow(j));
+ orth.addToRow(j, i, -projectionScale);
}
- return orth;
+ }
+ return orth;
}
\ No newline at end of file
diff --git a/mlir/lib/Analysis/Presburger/Utils.cpp b/mlir/lib/Analysis/Presburger/Utils.cpp
index 30f01f545..a11bd9db0 100644
--- a/mlir/lib/Analysis/Presburger/Utils.cpp
+++ b/mlir/lib/Analysis/Presburger/Utils.cpp
@@ -521,7 +521,8 @@ SmallVector<int64_t, 8> presburger::getInt64Vec(ArrayRef<MPInt> range) {
return result;
}
-Fraction presburger::dotProduct(MutableArrayRef<Fraction> a, MutableArrayRef<Fraction> b) {
+Fraction presburger::dotProduct(MutableArrayRef<Fraction> a,
+ MutableArrayRef<Fraction> b) {
assert(a.size() == b.size() && "Dot product of two unequal vectors!");
Fraction sum = 0;
for (unsigned i = 0; i < a.size(); i++)
diff --git a/mlir/unittests/Analysis/Presburger/MatrixTest.cpp b/mlir/unittests/Analysis/Presburger/MatrixTest.cpp
index b7cc8e07a..79906cddd 100644
--- a/mlir/unittests/Analysis/Presburger/MatrixTest.cpp
+++ b/mlir/unittests/Analysis/Presburger/MatrixTest.cpp
@@ -312,14 +312,23 @@ TEST(MatrixTest, intInverse) {
}
TEST(MatrixTest, gramSchmidt) {
- FracMatrix mat = makeFracMatrix(3, 5, {{Fraction(3, 1), Fraction(4, 1), Fraction(5, 1), Fraction(12, 1), Fraction(19, 1)},
- {Fraction(4, 1), Fraction(5, 1), Fraction(6, 1), Fraction(13, 1), Fraction(20, 1)},
- {Fraction(7, 1), Fraction(8, 1), Fraction(9, 1), Fraction(16, 1), Fraction(24, 1)}});
-
- FracMatrix gramSchmidt = makeFracMatrix(3, 5,
- {{Fraction(3, 1), Fraction(4, 1), Fraction(5, 1), Fraction(12, 1), Fraction(19, 1)},
- {Fraction(142, 185), Fraction(383, 555), Fraction(68, 111), Fraction(13, 185), Fraction(-262, 555)},
- {Fraction(53, 463), Fraction(27, 463), Fraction(1, 463), Fraction(-181, 463), Fraction(100, 463)}});
+ FracMatrix mat =
+ makeFracMatrix(3, 5,
+ {{Fraction(3, 1), Fraction(4, 1), Fraction(5, 1),
+ Fraction(12, 1), Fraction(19, 1)},
+ {Fraction(4, 1), Fraction(5, 1), Fraction(6, 1),
+ Fraction(13, 1), Fraction(20, 1)},
+ {Fraction(7, 1), Fraction(8, 1), Fraction(9, 1),
+ Fraction(16, 1), Fraction(24, 1)}});
+
+ FracMatrix gramSchmidt = makeFracMatrix(
+ 3, 5,
+ {{Fraction(3, 1), Fraction(4, 1), Fraction(5, 1), Fraction(12, 1),
+ Fraction(19, 1)},
+ {Fraction(142, 185), Fraction(383, 555), Fraction(68, 111),
+ Fraction(13, 185), Fraction(-262, 555)},
+ {Fraction(53, 463), Fraction(27, 463), Fraction(1, 463),
+ Fraction(-181, 463), Fraction(100, 463)}});
FracMatrix gs = mat.gramSchmidt();
``````````
</details>
https://github.com/llvm/llvm-project/pull/70843
More information about the Mlir-commits
mailing list