mirror of
https://github.com/TREX-CoE/Sherman-Morrison.git
synced 2024-12-27 06:43:55 +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;
|
(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
|
#ifdef DEBUG
|
||||||
showMatrix(last, Dim, "last");
|
showMatrix(last, Dim, "last");
|
||||||
#endif
|
#endif
|
||||||
|
@ -173,7 +173,8 @@ void SM3(double *Slater_inv, unsigned int Dim, unsigned int N_updates,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Sherman Morrison, mix between SM3 + SM2
|
// 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,
|
void SM4(double *Slater_inv, unsigned int Dim, unsigned int N_updates,
|
||||||
double *Updates, unsigned int *Updates_index) {
|
double *Updates, unsigned int *Updates_index) {
|
||||||
std::cerr << "Called SM4 with " << N_updates << " updates" << std::endl;
|
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" {
|
extern "C" {
|
||||||
void SM1_f(double **linSlater_inv, unsigned int *Dim,
|
void SM1_f(double **linSlater_inv, unsigned int *Dim, unsigned int *N_updates,
|
||||||
unsigned int *N_updates, double **linUpdates,
|
double **linUpdates, unsigned int **Updates_index) {
|
||||||
unsigned int **Updates_index) {
|
|
||||||
SM1(*linSlater_inv, *Dim, *N_updates, *linUpdates, *Updates_index);
|
SM1(*linSlater_inv, *Dim, *N_updates, *linUpdates, *Updates_index);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SM2_f(double **linSlater_inv, unsigned int *Dim,
|
void SM2_f(double **linSlater_inv, unsigned int *Dim, unsigned int *N_updates,
|
||||||
unsigned int *N_updates, double **linUpdates,
|
double **linUpdates, unsigned int **Updates_index) {
|
||||||
unsigned int **Updates_index) {
|
|
||||||
SM2(*linSlater_inv, *Dim, *N_updates, *linUpdates, *Updates_index);
|
SM2(*linSlater_inv, *Dim, *N_updates, *linUpdates, *Updates_index);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SM3_f(double **linSlater_inv, unsigned int *Dim,
|
void SM3_f(double **linSlater_inv, unsigned int *Dim, unsigned int *N_updates,
|
||||||
unsigned int *N_updates, double **linUpdates,
|
double **linUpdates, unsigned int **Updates_index) {
|
||||||
unsigned int **Updates_index) {
|
|
||||||
SM3(*linSlater_inv, *Dim, *N_updates, *linUpdates, *Updates_index);
|
SM3(*linSlater_inv, *Dim, *N_updates, *linUpdates, *Updates_index);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SM4_f(double **linSlater_inv, unsigned int *Dim,
|
void SM4_f(double **linSlater_inv, unsigned int *Dim, unsigned int *N_updates,
|
||||||
unsigned int *N_updates, double **linUpdates,
|
double **linUpdates, unsigned int **Updates_index) {
|
||||||
unsigned int **Updates_index) {
|
|
||||||
SM4(*linSlater_inv, *Dim, *N_updates, *linUpdates, *Updates_index);
|
SM4(*linSlater_inv, *Dim, *N_updates, *linUpdates, *Updates_index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
// main.cpp
|
// main.cpp
|
||||||
#include "SM_Maponi.hpp"
|
|
||||||
#include "SM_Helpers.hpp"
|
#include "SM_Helpers.hpp"
|
||||||
|
#include "SM_Maponi.hpp"
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
|
|
||||||
@ -10,7 +10,8 @@ int main() {
|
|||||||
// Declare, allocate all vectors and matrices and fill them with zeros
|
// Declare, allocate all vectors and matrices and fill them with zeros
|
||||||
unsigned int *Ar_index = new unsigned int[M];
|
unsigned int *Ar_index = new unsigned int[M];
|
||||||
double *A = new double[M * M]; // The matrix to be inverted
|
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 *Ar = new double[M * M]; // The update matrix
|
||||||
double *A0_inv = new double[M * M]; // The inverse
|
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
|
// Initialize A with M=3 and fill acc. to Eq. (17) from paper
|
||||||
A[0] = 1; A[3] = 1; A[6] = -1;
|
A[0] = 1;
|
||||||
A[1] = 1; A[4] = 1; A[7] = 0;
|
A[3] = 1;
|
||||||
A[2] = -1; A[5] = 0; A[8] = -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");
|
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);
|
MaponiA3(A0_inv, M, M, Ar, Ar_index);
|
||||||
showMatrix(A0_inv, M, "A0_inv");
|
showMatrix(A0_inv, M, "A0_inv");
|
||||||
|
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
#include "hdf5/serial/hdf5.h"
|
|
||||||
#include "hdf5/serial/H5Cpp.h"
|
#include "hdf5/serial/H5Cpp.h"
|
||||||
|
#include "hdf5/serial/hdf5.h"
|
||||||
|
|
||||||
|
#include "SM_Helpers.hpp"
|
||||||
#include "SM_Maponi.hpp"
|
#include "SM_Maponi.hpp"
|
||||||
#include "SM_Standard.hpp"
|
#include "SM_Standard.hpp"
|
||||||
#include "SM_Helpers.hpp"
|
|
||||||
|
|
||||||
using namespace H5;
|
using namespace H5;
|
||||||
// #define DEBUG
|
// #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 (j = 0; j < nupdates; j++) {
|
||||||
for (i = 0; i < dim; i++) {
|
for (i = 0; i < dim; i++) {
|
||||||
col = col_update_index[j];
|
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];
|
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 res_max = residual_max(res, dim);
|
||||||
double res2 = residual_frobenius2(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
|
#ifdef DEBUG
|
||||||
showMatrix(res, dim, "Result");
|
showMatrix(res, dim, "Result");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
delete [] res, updates, u, col_update_index,
|
delete[] res, updates, u, col_update_index, slater_matrix, slater_inverse;
|
||||||
slater_matrix, slater_inverse;
|
|
||||||
|
|
||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
@ -114,7 +115,9 @@ int test_cycle(H5File file, int cycle, std::string version, double tolerance) {
|
|||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
if (argc != 5) {
|
if (argc != 5) {
|
||||||
std::cerr << "Execute from within 'datasets/'" << std::endl;
|
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;
|
return 1;
|
||||||
}
|
}
|
||||||
std::string version(argv[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++) {
|
for (int cycle = start_cycle; cycle < stop_cycle + 1; cycle++) {
|
||||||
ok = test_cycle(file, cycle, version, tolerance);
|
ok = test_cycle(file, cycle, version, tolerance);
|
||||||
if (ok) {
|
if (ok) {
|
||||||
std::cerr << "ok -- cycle " << std::to_string(cycle)
|
std::cerr << "ok -- cycle " << std::to_string(cycle) << std::endl;
|
||||||
<< std::endl;
|
} else {
|
||||||
}
|
std::cerr << "failed -- 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
|
// 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).
|
// 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/H5Cpp.h>
|
||||||
|
#include <hdf5/serial/hdf5.h>
|
||||||
|
|
||||||
#include <vector>
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include "SM_Helpers.hpp"
|
||||||
#include "SM_Maponi.hpp"
|
#include "SM_Maponi.hpp"
|
||||||
#include "SM_Standard.hpp"
|
#include "SM_Standard.hpp"
|
||||||
#include "SM_Helpers.hpp"
|
|
||||||
#include "vfc_probe.h"
|
#include "vfc_probe.h"
|
||||||
|
|
||||||
using namespace H5;
|
using namespace H5;
|
||||||
@ -49,7 +48,8 @@ std::vector<int> get_cycles_list(std::string path) {
|
|||||||
return cycles_list;
|
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 */
|
/* 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.
|
// being zero-padded. This is used when calling vfc_put_probe later on.
|
||||||
std::string zero_padded_group = std::to_string(cycle);
|
std::string zero_padded_group = std::to_string(cycle);
|
||||||
zero_padded_group = "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 {
|
try {
|
||||||
file.openGroup(group);
|
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 + "/slater_matrix_dim", &dim);
|
||||||
read_int(file, group + "/nupdates", &nupdates);
|
read_int(file, group + "/nupdates", &nupdates);
|
||||||
|
|
||||||
|
|
||||||
double *slater_matrix = new double[dim * dim];
|
double *slater_matrix = new double[dim * dim];
|
||||||
read_double(file, group + "/slater_matrix", slater_matrix);
|
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 (j = 0; j < nupdates; j++) {
|
||||||
for (i = 0; i < dim; i++) {
|
for (i = 0; i < dim; i++) {
|
||||||
col = col_update_index[j];
|
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];
|
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");
|
showMatrix(res, dim, "Result");
|
||||||
#endif
|
#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);
|
vfc_put_probe(probes, &(zero_padded_group)[0], &("res2_" + version)[0], res2);
|
||||||
|
|
||||||
delete [] res, updates, u, col_update_index,
|
delete[] res, updates, u, col_update_index, slater_matrix, slater_inverse;
|
||||||
slater_matrix, slater_inverse;
|
|
||||||
|
|
||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
@ -165,12 +166,9 @@ int main(int argc, char **argv) {
|
|||||||
for (int i = 0; i < cycles_list.size(); i++) {
|
for (int i = 0; i < cycles_list.size(); i++) {
|
||||||
ok = test_cycle(file, cycles_list[i], version, &probes);
|
ok = test_cycle(file, cycles_list[i], version, &probes);
|
||||||
if (ok) {
|
if (ok) {
|
||||||
std::cout << "ok -- cycle " << std::to_string(i)
|
std::cout << "ok -- cycle " << std::to_string(i) << std::endl;
|
||||||
<< std::endl;
|
} else {
|
||||||
}
|
std::cerr << "failed -- 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