generated from Tiphereth-A/TINplate
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
588b43d
commit 595e0a7
Showing
9 changed files
with
40 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#ifndef TIFALIBS_LALG_SHERMAN_MORRISON | ||
#define TIFALIBS_LALG_SHERMAN_MORRISON | ||
|
||
#include "../util/util.hpp" | ||
|
||
namespace tifa_libs::math { | ||
|
||
template <class Mat, class T = typename Mat::value_type> | ||
requires std::same_as<T, typename Mat::value_type> | ||
constexpr void sherman_morrison(Mat &inv_A, vec<T> const &u, vec<T> const &v) { | ||
u32 n = inv_A.row(); | ||
assert(n == inv_A.col()); | ||
vec<T> x(n), y(n); | ||
for (u32 i = 0; i < n; ++i) | ||
for (u32 j = 0; j < n; ++j) | ||
x[i] += inv_A[i][j] * u[j], y[j] += v[i] * inv_A[i][j]; | ||
T sum = 1; | ||
for (u32 i = 0; i < n; ++i) | ||
for (u32 j = 0; j < n; ++j) sum += v[i] * inv_A[i][j] * u[j]; | ||
for (u32 i = 0; i < n; ++i) | ||
for (u32 j = 0; j < n; ++j) inv_A[i][j] -= x[i] * y[j] / sum; | ||
} | ||
|
||
} // namespace tifa_libs::math | ||
|
||
#endif |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
根据方阵 \(A^{-1}\) 和列向量 \(u,v\) 计算 \((A+uv^T)^{-1}\) | ||
|
||
\[ | ||
\left(A+uv^T\right)^{-1}=A^{-1}-\frac{A^{-1}uv^TA^{-1}}{1+v^TA^{-1}u} | ||
\] | ||
|
||
\paragraph{复杂度} \(O(n^2)\) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.