Skip to content

Commit

Permalink
Remove unnecessary/unused members, simplify logic and general clean u…
Browse files Browse the repository at this point in the history
…p in det_manip

- remove change_col_row operation
- remove old working data
- do not keep track of the size and capacity explicitly
- remove short cut functions
- remove/update old tests
  • Loading branch information
Thoemi09 committed Dec 10, 2024
1 parent 5da019f commit a330ec7
Show file tree
Hide file tree
Showing 15 changed files with 422 additions and 1,571 deletions.
493 changes: 181 additions & 312 deletions c++/triqs/det_manip/det_manip.hpp

Large diffs are not rendered by default.

113 changes: 10 additions & 103 deletions c++/triqs/det_manip/work_data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,78 +26,6 @@

namespace triqs::det_manip::detail {

// ================ Work Data Types =====================

// For single-row/column operations
template <typename x_type, typename y_type, typename value_type> struct work_data_type1 {
x_type x;
y_type y;
long i, j, ireal, jreal;
// MB = A^(-1)*B,
// MC = C*A^(-1)
nda::vector<value_type> MB, MC, B, C;
// ksi = newdet/det
value_type ksi;
void resize(long N) {
MB.resize(N);
MC.resize(N);
B.resize(N);
C.resize(N);
}
};

// For multiple-row/column operations
template <typename x_type, typename y_type, typename value_type> struct work_data_typek {
std::vector<x_type> x;
std::vector<y_type> y;
std::vector<long> i, j, ireal, jreal;
// MB = A^(-1)*B,
// MC = C*A^(-1)
nda::matrix<value_type> MB, MC, B, C, ksi;
void resize(long N, long k) {
if (k < 2) return;
x.resize(k);
y.resize(k);
i.resize(k);
j.resize(k);
ireal.resize(k);
jreal.resize(k);
MB.resize(N, k);
MC.resize(k, N);
B.resize(N, k);
C.resize(k, N);
ksi.resize(k, k);
}
value_type det_ksi(long k) const {
if (k == 2) {
return ksi(0, 0) * ksi(1, 1) - ksi(1, 0) * ksi(0, 1);
} else if (k == 3) {
return // Rule of Sarrus
ksi(0, 0) * ksi(1, 1) * ksi(2, 2) + //
ksi(0, 1) * ksi(1, 2) * ksi(2, 0) + //
ksi(0, 2) * ksi(1, 0) * ksi(2, 1) - //
ksi(2, 0) * ksi(1, 1) * ksi(0, 2) - //
ksi(2, 1) * ksi(1, 2) * ksi(0, 0) - //
ksi(2, 2) * ksi(1, 0) * ksi(0, 1); //
} else {
auto Rk = nda::range(k);
return nda::determinant(ksi(Rk, Rk));
};
}
};

// For refill operations
template <typename x_type, typename y_type, typename value_type> struct work_data_type_refill {
std::vector<x_type> x_values;
std::vector<y_type> y_values;
nda::matrix<value_type> M;
void reserve(long N) {
x_values.reserve(N);
y_values.reserve(N);
M.resize(N, N);
}
};

// Data storage for temporary data used in the det_manip class when inserting a new row and column.
//
// - x and y: MatrixBuilder arguments for the new row and column.
Expand All @@ -108,13 +36,9 @@ namespace triqs::det_manip::detail {
template <typename X, typename Y, typename T> struct work_data_insert {
X x;
Y y;
long i;
long j;
long i, j;
T S_inv;
nda::vector<T> B;
nda::vector<T> C;
nda::vector<T> MB;
nda::vector<T> CM;
nda::vector<T> B, C, MB, CM;

// Get current capacity of the data storages.
auto capacity() const { return B.size(); }
Expand Down Expand Up @@ -143,13 +67,8 @@ namespace triqs::det_manip::detail {
template <typename X, typename Y, typename T> struct work_data_insert_k {
std::vector<X> x;
std::vector<Y> y;
std::vector<long> i;
std::vector<long> j;
nda::matrix<T> S_inv;
nda::matrix<T> B;
nda::matrix<T> C;
nda::matrix<T> MB;
nda::matrix<T> CM;
std::vector<long> i, j;
nda::matrix<T> S_inv, B, C, MB, CM;

// Get current capacity of the data storages.
auto capacity() const { return std::make_pair(B.shape()[0], B.shape()[1]); }
Expand All @@ -173,10 +92,7 @@ namespace triqs::det_manip::detail {
// - ip and jp: Positions of the row and column in the matrix G.
// - S: Diagonal element of \widetilde{M}^{(n)}.
template <typename T> struct work_data_remove {
long i;
long j;
long ip;
long jp;
long i, j, ip, jp;
T S;
};

Expand All @@ -186,10 +102,7 @@ namespace triqs::det_manip::detail {
// - ip and jp: Positions of the rows and columns in the matrix G.
// - S: Block matrix of \widetilde{M}^{(n)}.
template <typename T> struct work_data_remove_k {
std::vector<long> i;
std::vector<long> j;
std::vector<long> ip;
std::vector<long> jp;
std::vector<long> i, j, ip, jp;
nda::matrix<T> S;

// Get current capacity of the data storages.
Expand All @@ -216,11 +129,8 @@ namespace triqs::det_manip::detail {
// - xi: Factor appearing in the matrix determinant lemma, i.e. xi = (1 + v^T M u).
template <typename Y, typename T> struct work_data_change_col {
Y y;
long j;
long jp;
nda::vector<T> u;
nda::vector<T> Mu;
nda::vector<T> vTM;
long j, jp;
nda::vector<T> u, Mu, vTM;
T xi;

// Get current capacity of the data storages.
Expand All @@ -247,11 +157,8 @@ namespace triqs::det_manip::detail {
// - xi: Factor appearing in the matrix determinant lemma, i.e. xi = (1 + v^T M u).
template <typename X, typename T> struct work_data_change_row {
X x;
long i;
long ip;
nda::vector<T> vT;
nda::vector<T> vTM;
nda::vector<T> Mu;
long i, ip;
nda::vector<T> vT, vTM, Mu;
T xi;

// Get current capacity of the data storages.
Expand Down
190 changes: 0 additions & 190 deletions test/c++/det_manip/det_manip1.cpp

This file was deleted.

Loading

0 comments on commit a330ec7

Please sign in to comment.