Skip to content

Commit

Permalink
C++: automated code formatting
Browse files Browse the repository at this point in the history
Signed-off-by: Marcus Müller <[email protected]>
  • Loading branch information
marcusmueller committed Apr 22, 2023
1 parent fb55fb2 commit 62668df
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 32 deletions.
12 changes: 3 additions & 9 deletions fileReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
#include <random>
#include <sstream>



fileReader::fileReader(unsigned n, unsigned k, unsigned m, stabilizerCodesType codeType, bool trained) {
mycodetype = codeType;
N = n;
Expand All @@ -26,7 +24,6 @@ fileReader::fileReader(unsigned n, unsigned k, unsigned m, stabilizerCodesType c
}
}


void fileReader::read_H() {
std::string codeTypeString = code_type_string();
std::string filename = "./PCMs/" + codeTypeString + "_" + std::to_string(N) + "_" + std::to_string(K) + "/" +
Expand All @@ -36,7 +33,7 @@ void fileReader::read_H() {
// Mck same shape and Nv, but its value k means the i-th CN being the k-th neigbor of j-th VN
std::vector<std::vector<unsigned>> checkValues;
std::vector<std::vector<unsigned>> VariableValues;

std::string line;
std::ifstream matrix_file;
matrix_file.open(filename);
Expand Down Expand Up @@ -172,7 +169,7 @@ void fileReader::load_cn_weights() {
unsigned n = std::stoul(line);
getline(weights_file, line);
unsigned m = std::stoul(line);

if (n != N) {
throw std::runtime_error("load_cn_weights: file-specified N not as expected");
}
Expand Down Expand Up @@ -290,7 +287,6 @@ std::filesystem::path fileReader::construct_weights_path(std::string_view filena
return path;
}


std::string fileReader::code_type_string() const {
switch (mycodetype) {
case stabilizerCodesType::GeneralizedBicycle:
Expand Down Expand Up @@ -349,6 +345,4 @@ bool fileReader::check_symplectic() {
return true;
}

inline bool fileReader::trace_inner_product(unsigned int a, unsigned int b) {
return !(a == 0 || b == 0 || a == b);
}
inline bool fileReader::trace_inner_product(unsigned int a, unsigned int b) { return !(a == 0 || b == 0 || a == b); }
4 changes: 1 addition & 3 deletions fileReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@
#include <string_view>
#include <vector>
enum class stabilizerCodesType { GeneralizedBicycle = 0, HypergraphProduct = 1, toric = 3 };
class fileReader{
class fileReader {
public:
fileReader(unsigned n, unsigned k, unsigned m, stabilizerCodesType codeType, bool trained = false);
std::string code_type_string() const;
std::filesystem::path construct_weights_path(std::string_view filename) const;


void load_cn_weights();
void load_vn_weights();
void load_llr_weights();
Expand Down Expand Up @@ -51,4 +50,3 @@ class fileReader{
std::vector<std::vector<std::vector<double>>> weights_vn;
std::vector<std::vector<double>> weights_llr;
};

6 changes: 2 additions & 4 deletions simulateFER.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,8 @@ int main() {
std::cout << ",trained";
std::cout << std::endl;

std::cout << "% collect " << max_frame_errors << " frame errors or " << max_decoded_words << " decoded error patterns" << std::endl;


std::cout << "% collect " << max_frame_errors << " frame errors or " << max_decoded_words
<< " decoded error patterns" << std::endl;

// omp_set_num_threads(1);
for (double epsilon : ep_list) {
Expand All @@ -63,7 +62,6 @@ int main() {
}
std::cout << "% FE " << failure << ", total dec. " << total_decoding << "\\\\" << std::endl;
std::cout << epsilon << " " << (failure / total_decoding) << "\\\\" << std::endl;

}
return 0;
}
13 changes: 3 additions & 10 deletions stabilizerCodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
#include <random>
#include <sstream>


stabilizerCodes::stabilizerCodes(unsigned n, unsigned k, unsigned m, stabilizerCodesType codeType, const fileReader fr, bool trained) {
stabilizerCodes::stabilizerCodes(unsigned n, unsigned k, unsigned m, stabilizerCodesType codeType, const fileReader fr,
bool trained) {
mycodetype = codeType;
N = n;
K = k;
Expand All @@ -34,13 +34,11 @@ stabilizerCodes::stabilizerCodes(unsigned n, unsigned k, unsigned m, stabilizerC
Nvk = fr.Nvk;
Mck = fr.Mck;
G = fr.G;
if (trained){
if (trained) {
weights_cn = fr.weights_cn;
weights_vn = fr.weights_vn;
weights_llr = fr.weights_llr;
}


}

std::vector<bool> stabilizerCodes::decode(unsigned int L, double epsilon) {
Expand All @@ -52,8 +50,6 @@ std::vector<bool> stabilizerCodes::decode(unsigned int L, double epsilon) {
return flooding_decode(L, epsilon);
}



void stabilizerCodes::add_error_given_epsilon(double epsilon) {
error.clear();
errorString.clear();
Expand Down Expand Up @@ -83,7 +79,6 @@ void stabilizerCodes::add_error_given_epsilon(double epsilon) {

// void stabilizerCodes::add_error_given_positions(int *pos, int *error, int size) {}


double stabilizerCodes::quantize_belief(double Tau, double Tau1, double Tau2) {
double nom = log1p(exp(-1.0 * Tau));
double denom = std::max(-1.0 * Tau1, -1.0 * Tau2) + log1p(exp(-1.0 * fabs((Tau1 - Tau2))));
Expand Down Expand Up @@ -355,5 +350,3 @@ std::vector<bool> stabilizerCodes::check_success(const double *Taux, const doubl
success[1] = true;
return success;
}


9 changes: 3 additions & 6 deletions stabilizerCodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,16 @@
*/
#ifndef BPDECODING_STABILIZIERCODES_H
#define BPDECODING_STABILIZIERCODES_H
#include "fileReader.h"
#include <filesystem>
#include <string>
#include <string_view>
#include <vector>
#include "fileReader.h"



class stabilizerCodes {
public:
stabilizerCodes(unsigned n, unsigned k, unsigned m, stabilizerCodesType codeType, const fileReader fr, bool trained = false);
stabilizerCodes(unsigned n, unsigned k, unsigned m, stabilizerCodesType codeType, const fileReader fr,
bool trained = false);

std::vector<bool> decode(unsigned int L, double epsilon);

Expand All @@ -39,8 +38,6 @@ class stabilizerCodes {
static double quantize_belief(double Taux, double Tauy, double Tauz);

private:


bool print_msg = false;

stabilizerCodesType mycodetype;
Expand Down

0 comments on commit 62668df

Please sign in to comment.