-
Notifications
You must be signed in to change notification settings - Fork 1
/
lib.h
108 lines (83 loc) · 3.37 KB
/
lib.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/**\file lib.h
*\brief lib for general functions, defined within namespace common
*/
#ifndef LIB_H
#define LIB_H
#include <string> //string is already included in itpp
//#include <iostream>
//#include<fstream>
//#include <stdio.h>
#include <itpp/itbase.h>
//#include "weilei_lib.h"
/**\namespace common
*\brief common function shared by many program
*/
namespace common{
//general cpp util functions
/** return text in red color for printing */
std::string color_text(std::string str);
std::string red_text(std::string str); /**< return red std::string */
std::string blue_text(std::string str);/**< return blue std::string */
int get_time(int mode = 1); /**< return time in secs, milliseconds, or ... */
//itpp based functions
/** check if it is a quantum CSS code
*@param G_x X type parity check matrix
*@param G_z Z type parity check matrix
*/
bool is_quantum_code(itpp::GF2mat & G_x, itpp::GF2mat & G_z);
//check if the code is quantum or not
//this function is also defined elsewhere
//moved from product.h
/** check if it is a quantum CSS code
*@param G_x X type parity check matrix
*@param G_z Z type parity check matrix
*@param C_x X type codeword generating matrix
*@param C_z Z type codeword generating matrix
*/
bool is_quantum_code(itpp::GF2mat &Gx,itpp::GF2mat &Gz, itpp::GF2mat &Cx,itpp::GF2mat &Cz);
/** reduce a fat matrix with degenerate rows to a thin matrix with full rank; remove the dependent rows
*@param fat a GF2mat not necessary full rank
*@return thin: a full rank GF2mat matrix
*/
itpp::GF2mat make_it_full_rank(itpp::GF2mat fat);
//int itpp::GF2matPrint(itpp::GF2mat &G, char * name = (char *) " ");
/**print brief information of G: name, size, density
*@param G
*@param name name of the matrix
*/
int GF2matPrint(itpp::GF2mat &G, std::string name);
/**print brief information of G: name, size, density
*@param G
*@param name name of the matrix
*/
int matPrint(itpp::mat G, char * name = (char *) " ");//print brief infomation of G
/**
*Kronecker product of A and B
*@param A the outer matrix
*@param B the inner matrix
*/
itpp::GF2mat kron(itpp::GF2mat A, itpp::GF2mat B);//not sure how this kron is defined, maybe inversed
/** convert int to string
*\warning not used anywhere, should be replaced by build-in function to_string()
*/
std::string NumberToString(int pNumber);//Convert number to std::string. //because the build in function is not supported in C++ 11
/**< append row vectors to an itpp::GF2mat
*\warning This is super ineffcient, and should not be used this way
*/
itpp::GF2mat append_vector(itpp::GF2mat G, itpp::bvec b);
/** getitpp::GF2mat from filename with given pattern
*full name = filename_prefix+filename_suffix
*/
itpp::GF2mat get_GF2mat(char * filename_prefix, char * filename_suffix);
/** getitpp::GF2mat from filename with given pattern
*full name = parent_folder/folder/filename
*/
itpp::GF2mat get_GF2mat(char * parent_folder, char * folder, char * filename);
/** return density of a matrix whose first row is zero
*remove first row and return density of the remained submatrix
*/
double get_error_density(itpp::GF2mat E);
/** save mat into gnuplot data file, with a custom comment as header*/
int mat2gnudata(itpp::mat data, std::string filename, std::string header);
}
#endif