Commit 0fe5e345 authored by Alois SCHLOEGL's avatar Alois SCHLOEGL

convert matrix from double to float in order to save 50% memory

parent 6e71e8d2
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
int calc_phat_alphahat_1p(gsl_matrix *W, int N_nodes, int calc_phat_alphahat_1p(gsl_matrix_float *W, int N_nodes,
double &phat, double &phat,
double &alphahat_recip, double &alphahat_recip,
double &alphahat_conv, double &alphahat_conv,
...@@ -43,12 +43,12 @@ int calc_phat_alphahat_1p(gsl_matrix *W, int N_nodes, ...@@ -43,12 +43,12 @@ int calc_phat_alphahat_1p(gsl_matrix *W, int N_nodes,
// network adjacency matrix W with N_node nodes // network adjacency matrix W with N_node nodes
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
int calc_N_motifs(gsl_matrix *W, int N_nodes, int calc_N_motifs(gsl_matrix_float *W, int N_nodes,
double &N_edge, double &N_recip, double &N_edge, double &N_recip,
double &N_conv, double &N_div, double &N_chain, double &N_conv, double &N_div, double &N_chain,
double &N_other) { double &N_other) {
double *thedata = W->data; float *thedata = W->data;
size_t tda = W->tda; size_t tda = W->tda;
double row_sums[N_nodes]; double row_sums[N_nodes];
......
#include <gsl/gsl_matrix.h> #include <gsl/gsl_matrix_float.h>
int calc_phat_alphahat_1p(gsl_matrix *W, int N_nodes, int calc_phat_alphahat_1p(gsl_matrix_float *W, int N_nodes,
double &phat, double &phat,
double &alphahat_recip, double &alphahat_recip,
double &alphahat_conv, double &alphahat_conv,
double &alphahat_div, double &alphahat_div,
double &alphahat_chain, double &alphahat_chain,
double &alphahat_other); double &alphahat_other);
int calc_N_motifs(gsl_matrix *W, int N_nodes, int calc_N_motifs(gsl_matrix_float *W, int N_nodes,
double &N_edge, double &N_recip, double &N_edge, double &N_recip,
double &N_conv, double &N_div, double &N_chain, double &N_conv, double &N_div, double &N_chain,
double &N_other); double &N_other);
...@@ -55,7 +55,7 @@ int main(int argc, char *argv[]) { ...@@ -55,7 +55,7 @@ int main(int argc, char *argv[]) {
else else
gsl_rng_set(rng, time(NULL)); gsl_rng_set(rng, time(NULL));
gsl_matrix *W; gsl_matrix_float *W;
W=secorder_rec_1p(N_nodes,p, alpha_recip, alpha_conv, alpha_div, alpha_chain, W=secorder_rec_1p(N_nodes,p, alpha_recip, alpha_conv, alpha_div, alpha_chain,
rng); rng);
...@@ -87,7 +87,7 @@ int main(int argc, char *argv[]) { ...@@ -87,7 +87,7 @@ int main(int argc, char *argv[]) {
for(int i=0; i<N_nodes;i++) { for(int i=0; i<N_nodes;i++) {
for(int j=0; j<N_nodes; j++) { for(int j=0; j<N_nodes; j++) {
fprintf(fhnd, "%i ", gsl_matrix_get(W,i,j)>1.0); fprintf(fhnd, "%i ", gsl_matrix_float_get(W,i,j)>1.0);
} }
fprintf(fhnd,"\n"); fprintf(fhnd,"\n");
} }
...@@ -99,7 +99,7 @@ int main(int argc, char *argv[]) { ...@@ -99,7 +99,7 @@ int main(int argc, char *argv[]) {
size_t nnz=0; size_t nnz=0;
for(int i=0; i<N_nodes; i++) { for(int i=0; i<N_nodes; i++) {
for(int j=0; j<N_nodes; j++) { for(int j=0; j<N_nodes; j++) {
nnz += gsl_matrix_get(W,i,j)>1.0; nnz += gsl_matrix_float_get(W,i,j)>1.0;
} }
} }
strcat(FN,".sparse"); strcat(FN,".sparse");
...@@ -112,7 +112,7 @@ int main(int argc, char *argv[]) { ...@@ -112,7 +112,7 @@ int main(int argc, char *argv[]) {
fwrite(&nnz,8,1,fhnd); fwrite(&nnz,8,1,fhnd);
for (int32_t i=0; i<N_nodes; i++) { for (int32_t i=0; i<N_nodes; i++) {
for (int32_t j=0; j<N_nodes; j++) { for (int32_t j=0; j<N_nodes; j++) {
if (gsl_matrix_get(W,i,j) > 1.0) { if (gsl_matrix_float_get(W,i,j) > 1.0) {
fwrite(&i, 4, 1, fhnd); fwrite(&i, 4, 1, fhnd);
fwrite(&j, 4, 1, fhnd); fwrite(&j, 4, 1, fhnd);
} }
......
...@@ -13,9 +13,9 @@ using namespace std; ...@@ -13,9 +13,9 @@ using namespace std;
// declare auxiliary functions // declare auxiliary functions
int gen_corr_gaussian(const int N_nodes, double sqrt_diag, double sqrt_recip, int gen_corr_gaussian(const int N_nodes, double sqrt_diag, double sqrt_recip,
double sqrt_conv, double sqrt_div, double sqrt_chain, double sqrt_conv, double sqrt_div, double sqrt_chain,
double sqrt_noshare, gsl_matrix *thevars, gsl_rng *rng); double sqrt_noshare, gsl_matrix_float *thevars, gsl_rng *rng);
int calc_gaus_covs(gsl_matrix *W_gaus, int N_nodes, int calc_gaus_covs(gsl_matrix_float *W_gaus, int N_nodes,
double &sigma, double &cov_recip, double &sigma, double &cov_recip,
double &cov_conv, double &cov_div, double &cov_conv, double &cov_div,
double &cov_chain, double &cov_other); double &cov_chain, double &cov_other);
...@@ -49,8 +49,8 @@ int calc_gaus_covs(gsl_matrix *W_gaus, int N_nodes, ...@@ -49,8 +49,8 @@ int calc_gaus_covs(gsl_matrix *W_gaus, int N_nodes,
// connection from node j onto node i // connection from node j onto node i
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
gsl_matrix* secorder_rec_1p(int N_nodes, double p, gsl_matrix_float* secorder_rec_1p(int N_nodes, double p,
double alpha_recip, double alpha_conv, double alpha_recip, double alpha_conv,
double alpha_div, double alpha_chain, double alpha_div, double alpha_chain,
gsl_rng *rng) { gsl_rng *rng) {
...@@ -164,7 +164,7 @@ gsl_matrix* secorder_rec_1p(int N_nodes, double p, ...@@ -164,7 +164,7 @@ gsl_matrix* secorder_rec_1p(int N_nodes, double p,
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
gsl_matrix *W_gaus = gsl_matrix_alloc(N_nodes, N_nodes); gsl_matrix_float *W_gaus = gsl_matrix_float_alloc(N_nodes, N_nodes);
cout << "Generating gaussian matrix..."; cout << "Generating gaussian matrix...";
cout.flush(); cout.flush();
...@@ -224,10 +224,10 @@ gsl_matrix* secorder_rec_1p(int N_nodes, double p, ...@@ -224,10 +224,10 @@ gsl_matrix* secorder_rec_1p(int N_nodes, double p,
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
int gen_corr_gaussian(const int N_nodes, double sqrt_diag, double sqrt_recip, int gen_corr_gaussian(const int N_nodes, double sqrt_diag, double sqrt_recip,
double sqrt_conv, double sqrt_div, double sqrt_chain, double sqrt_conv, double sqrt_div, double sqrt_chain,
double sqrt_noshare, gsl_matrix *thevars, gsl_rng *rng) { double sqrt_noshare, gsl_matrix_float *thevars, gsl_rng *rng) {
gsl_matrix_set_zero(thevars); gsl_matrix_float_set_zero(thevars);
double *thedata = thevars->data; float *thedata = thevars->data;
size_t tda=thevars->tda; size_t tda=thevars->tda;
// for speed we'll access the gsl_matrix entries directly // for speed we'll access the gsl_matrix entries directly
......
#include <gsl/gsl_rng.h> #include <gsl/gsl_rng.h>
#include <gsl/gsl_matrix.h> #include <gsl/gsl_matrix_float.h>
gsl_matrix* secorder_rec_1p(int N_nodes, double p, gsl_matrix_float* secorder_rec_1p(int N_nodes, double p,
double alpha_recip, double alpha_conv, double alpha_recip, double alpha_conv,
double alpha_div, double alpha_chain, double alpha_div, double alpha_chain,
gsl_rng *rng); gsl_rng *rng);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment