mirror of
https://github.com/TREX-CoE/Sherman-Morrison.git
synced 2025-01-13 06:28:35 +01:00
Re-applied code formatting on C++ code with clang-format --style=llvm.
This commit is contained in:
parent
0984682bdf
commit
5693e177ba
@ -237,7 +237,10 @@ void MaponiA3S(double *Slater_inv, unsigned int Dim, unsigned int N_updates,
|
||||
(i == j) - (j == component - 1) * ylk[l][p[l + 1]][i + 1] * ibeta;
|
||||
}
|
||||
}
|
||||
matMul(Al, last, next, Dim); tmp = next; next = last; last = tmp;
|
||||
matMul(Al, last, next, Dim);
|
||||
tmp = next;
|
||||
next = last;
|
||||
last = tmp;
|
||||
#ifdef DEBUG
|
||||
showMatrix(last, Dim, "last");
|
||||
#endif
|
||||
|
@ -173,7 +173,8 @@ void SM3(double *Slater_inv, unsigned int Dim, unsigned int N_updates,
|
||||
}
|
||||
|
||||
// Sherman Morrison, mix between SM3 + SM2
|
||||
// Leave zero denominators for later (SM3), and when none are left then split (SM2)
|
||||
// Leave zero denominators for later (SM3), and when none are left then split
|
||||
// (SM2)
|
||||
void SM4(double *Slater_inv, unsigned int Dim, unsigned int N_updates,
|
||||
double *Updates, unsigned int *Updates_index) {
|
||||
std::cerr << "Called SM4 with " << N_updates << " updates" << std::endl;
|
||||
@ -237,27 +238,23 @@ void SM4(double *Slater_inv, unsigned int Dim, unsigned int N_updates,
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
void SM1_f(double **linSlater_inv, unsigned int *Dim,
|
||||
unsigned int *N_updates, double **linUpdates,
|
||||
unsigned int **Updates_index) {
|
||||
void SM1_f(double **linSlater_inv, unsigned int *Dim, unsigned int *N_updates,
|
||||
double **linUpdates, unsigned int **Updates_index) {
|
||||
SM1(*linSlater_inv, *Dim, *N_updates, *linUpdates, *Updates_index);
|
||||
}
|
||||
|
||||
void SM2_f(double **linSlater_inv, unsigned int *Dim,
|
||||
unsigned int *N_updates, double **linUpdates,
|
||||
unsigned int **Updates_index) {
|
||||
void SM2_f(double **linSlater_inv, unsigned int *Dim, unsigned int *N_updates,
|
||||
double **linUpdates, unsigned int **Updates_index) {
|
||||
SM2(*linSlater_inv, *Dim, *N_updates, *linUpdates, *Updates_index);
|
||||
}
|
||||
|
||||
void SM3_f(double **linSlater_inv, unsigned int *Dim,
|
||||
unsigned int *N_updates, double **linUpdates,
|
||||
unsigned int **Updates_index) {
|
||||
void SM3_f(double **linSlater_inv, unsigned int *Dim, unsigned int *N_updates,
|
||||
double **linUpdates, unsigned int **Updates_index) {
|
||||
SM3(*linSlater_inv, *Dim, *N_updates, *linUpdates, *Updates_index);
|
||||
}
|
||||
|
||||
void SM4_f(double **linSlater_inv, unsigned int *Dim,
|
||||
unsigned int *N_updates, double **linUpdates,
|
||||
unsigned int **Updates_index) {
|
||||
void SM4_f(double **linSlater_inv, unsigned int *Dim, unsigned int *N_updates,
|
||||
double **linUpdates, unsigned int **Updates_index) {
|
||||
SM4(*linSlater_inv, *Dim, *N_updates, *linUpdates, *Updates_index);
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
// main.cpp
|
||||
#include "SM_Maponi.hpp"
|
||||
#include "SM_Helpers.hpp"
|
||||
#include "SM_Maponi.hpp"
|
||||
|
||||
int main() {
|
||||
|
||||
@ -10,7 +10,8 @@ int main() {
|
||||
// Declare, allocate all vectors and matrices and fill them with zeros
|
||||
unsigned int *Ar_index = new unsigned int[M];
|
||||
double *A = new double[M * M]; // The matrix to be inverted
|
||||
double *A0 = new double[M*M]; // A diagonal matrix with the digonal elements of A
|
||||
double *A0 =
|
||||
new double[M * M]; // A diagonal matrix with the digonal elements of A
|
||||
double *Ar = new double[M * M]; // The update matrix
|
||||
double *A0_inv = new double[M * M]; // The inverse
|
||||
|
||||
@ -24,9 +25,15 @@ int main() {
|
||||
}
|
||||
|
||||
// Initialize A with M=3 and fill acc. to Eq. (17) from paper
|
||||
A[0] = 1; A[3] = 1; A[6] = -1;
|
||||
A[1] = 1; A[4] = 1; A[7] = 0;
|
||||
A[2] = -1; A[5] = 0; A[8] = -1;
|
||||
A[0] = 1;
|
||||
A[3] = 1;
|
||||
A[6] = -1;
|
||||
A[1] = 1;
|
||||
A[4] = 1;
|
||||
A[7] = 0;
|
||||
A[2] = -1;
|
||||
A[5] = 0;
|
||||
A[8] = -1;
|
||||
|
||||
showMatrix(A, M, "A");
|
||||
|
||||
@ -42,7 +49,8 @@ int main() {
|
||||
}
|
||||
}
|
||||
|
||||
// Define pointers dim and n_updates to use in Sherman-Morrison(...) function call
|
||||
// Define pointers dim and n_updates to use in Sherman-Morrison(...) function
|
||||
// call
|
||||
MaponiA3(A0_inv, M, M, Ar, Ar_index);
|
||||
showMatrix(A0_inv, M, "A0_inv");
|
||||
|
||||
|
@ -1,9 +1,9 @@
|
||||
#include "hdf5/serial/hdf5.h"
|
||||
#include "hdf5/serial/H5Cpp.h"
|
||||
#include "hdf5/serial/hdf5.h"
|
||||
|
||||
#include "SM_Helpers.hpp"
|
||||
#include "SM_Maponi.hpp"
|
||||
#include "SM_Standard.hpp"
|
||||
#include "SM_Helpers.hpp"
|
||||
|
||||
using namespace H5;
|
||||
// #define DEBUG
|
||||
@ -55,7 +55,8 @@ int test_cycle(H5File file, int cycle, std::string version, double tolerance) {
|
||||
for (j = 0; j < nupdates; j++) {
|
||||
for (i = 0; i < dim; i++) {
|
||||
col = col_update_index[j];
|
||||
u[i + j*dim] = updates[i + j*dim] - slater_matrix[i*dim + (col - 1)];
|
||||
u[i + j * dim] =
|
||||
updates[i + j * dim] - slater_matrix[i * dim + (col - 1)];
|
||||
slater_matrix[i * dim + (col - 1)] = updates[i + j * dim];
|
||||
}
|
||||
}
|
||||
@ -99,14 +100,14 @@ int test_cycle(H5File file, int cycle, std::string version, double tolerance) {
|
||||
|
||||
double res_max = residual_max(res, dim);
|
||||
double res2 = residual_frobenius2(res, dim);
|
||||
std::cout << "Residual = " << version << " " << cycle << " " << res_max << " " << res2 << std::endl;
|
||||
std::cout << "Residual = " << version << " " << cycle << " " << res_max << " "
|
||||
<< res2 << std::endl;
|
||||
|
||||
#ifdef DEBUG
|
||||
showMatrix(res, dim, "Result");
|
||||
#endif
|
||||
|
||||
delete [] res, updates, u, col_update_index,
|
||||
slater_matrix, slater_inverse;
|
||||
delete[] res, updates, u, col_update_index, slater_matrix, slater_inverse;
|
||||
|
||||
return ok;
|
||||
}
|
||||
@ -114,7 +115,9 @@ int test_cycle(H5File file, int cycle, std::string version, double tolerance) {
|
||||
int main(int argc, char **argv) {
|
||||
if (argc != 5) {
|
||||
std::cerr << "Execute from within 'datasets/'" << std::endl;
|
||||
std::cerr << "usage: test_h5 <version> <start cycle> <stop cycle> <tolerance>" << std::endl;
|
||||
std::cerr
|
||||
<< "usage: test_h5 <version> <start cycle> <stop cycle> <tolerance>"
|
||||
<< std::endl;
|
||||
return 1;
|
||||
}
|
||||
std::string version(argv[1]);
|
||||
@ -127,12 +130,9 @@ int main(int argc, char **argv) {
|
||||
for (int cycle = start_cycle; cycle < stop_cycle + 1; cycle++) {
|
||||
ok = test_cycle(file, cycle, version, tolerance);
|
||||
if (ok) {
|
||||
std::cerr << "ok -- cycle " << std::to_string(cycle)
|
||||
<< std::endl;
|
||||
}
|
||||
else {
|
||||
std::cerr << "failed -- cycle " << std::to_string(cycle)
|
||||
<< std::endl;
|
||||
std::cerr << "ok -- cycle " << std::to_string(cycle) << std::endl;
|
||||
} else {
|
||||
std::cerr << "failed -- cycle " << std::to_string(cycle) << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -3,17 +3,16 @@
|
||||
// cycles in a CSV file, instead of accepting a start and an end cycle (which
|
||||
// makes it easier to select the exact cycles we are interested in with vfc_ci).
|
||||
|
||||
#include <hdf5/serial/hdf5.h>
|
||||
#include <hdf5/serial/H5Cpp.h>
|
||||
#include <hdf5/serial/hdf5.h>
|
||||
|
||||
#include <vector>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
|
||||
|
||||
#include "SM_Helpers.hpp"
|
||||
#include "SM_Maponi.hpp"
|
||||
#include "SM_Standard.hpp"
|
||||
#include "SM_Helpers.hpp"
|
||||
#include "vfc_probe.h"
|
||||
|
||||
using namespace H5;
|
||||
@ -49,7 +48,8 @@ std::vector<int> get_cycles_list(std::string path) {
|
||||
return cycles_list;
|
||||
}
|
||||
|
||||
int test_cycle(H5File file, int cycle, std::string version, vfc_probes * probes) {
|
||||
int test_cycle(H5File file, int cycle, std::string version,
|
||||
vfc_probes *probes) {
|
||||
|
||||
/* Read the data */
|
||||
|
||||
@ -59,7 +59,8 @@ int test_cycle(H5File file, int cycle, std::string version, vfc_probes * probes)
|
||||
// being zero-padded. This is used when calling vfc_put_probe later on.
|
||||
std::string zero_padded_group = std::to_string(cycle);
|
||||
zero_padded_group = "cycle_" +
|
||||
std::string(5 - zero_padded_group.length(), '0') + zero_padded_group;
|
||||
std::string(5 - zero_padded_group.length(), '0') +
|
||||
zero_padded_group;
|
||||
|
||||
try {
|
||||
file.openGroup(group);
|
||||
@ -72,7 +73,6 @@ int test_cycle(H5File file, int cycle, std::string version, vfc_probes * probes)
|
||||
read_int(file, group + "/slater_matrix_dim", &dim);
|
||||
read_int(file, group + "/nupdates", &nupdates);
|
||||
|
||||
|
||||
double *slater_matrix = new double[dim * dim];
|
||||
read_double(file, group + "/slater_matrix", slater_matrix);
|
||||
|
||||
@ -100,7 +100,8 @@ int test_cycle(H5File file, int cycle, std::string version, vfc_probes * probes)
|
||||
for (j = 0; j < nupdates; j++) {
|
||||
for (i = 0; i < dim; i++) {
|
||||
col = col_update_index[j];
|
||||
u[i + j*dim] = updates[i + j*dim] - slater_matrix[i*dim + (col - 1)];
|
||||
u[i + j * dim] =
|
||||
updates[i + j * dim] - slater_matrix[i * dim + (col - 1)];
|
||||
slater_matrix[i * dim + (col - 1)] = updates[i + j * dim];
|
||||
}
|
||||
}
|
||||
@ -139,11 +140,11 @@ int test_cycle(H5File file, int cycle, std::string version, vfc_probes * probes)
|
||||
showMatrix(res, dim, "Result");
|
||||
#endif
|
||||
|
||||
vfc_put_probe(probes, &(zero_padded_group)[0], &("res_max_" + version)[0], res_max);
|
||||
vfc_put_probe(probes, &(zero_padded_group)[0], &("res_max_" + version)[0],
|
||||
res_max);
|
||||
vfc_put_probe(probes, &(zero_padded_group)[0], &("res2_" + version)[0], res2);
|
||||
|
||||
delete [] res, updates, u, col_update_index,
|
||||
slater_matrix, slater_inverse;
|
||||
delete[] res, updates, u, col_update_index, slater_matrix, slater_inverse;
|
||||
|
||||
return ok;
|
||||
}
|
||||
@ -165,12 +166,9 @@ int main(int argc, char **argv) {
|
||||
for (int i = 0; i < cycles_list.size(); i++) {
|
||||
ok = test_cycle(file, cycles_list[i], version, &probes);
|
||||
if (ok) {
|
||||
std::cout << "ok -- cycle " << std::to_string(i)
|
||||
<< std::endl;
|
||||
}
|
||||
else {
|
||||
std::cerr << "failed -- cycle " << std::to_string(i)
|
||||
<< std::endl;
|
||||
std::cout << "ok -- cycle " << std::to_string(i) << std::endl;
|
||||
} else {
|
||||
std::cerr << "failed -- cycle " << std::to_string(i) << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user