23 std::vector<T> numbers;
24 std::ifstream inputFile(filename);
28 while (inputFile >> current_number)
29 numbers.push_back(current_number);
36 std::cout <<
"Error reading " << filename <<
"\n";
53 if (stat(filename.c_str(), &buf) != -1)
63 const std::string filename,
81 std::ifstream ifile(filename);
86 std::vector<std::vector<T>> Cij(row, std::vector<T>(col));
88 for (
int i = 0; i < row; i++)
90 for (
int j = 0; j < col; j++)
100 std::cerr <<
"\n file : " << filename <<
" not found \n";
106 template <
typename T>
108 const std::vector<std::vector<T>> &A,
109 const double threshold = 1e-8,
110 std::string in_degree =
"row")
124 int col = A[0].size();
125 std::vector<std::vector<int>> adjlist;
127 if (in_degree ==
"row")
131 for (
int i = 0; i < row; i++)
133 for (
int j = 0; j < col; j++)
135 if (std::abs(A[i][j]) > 1.e-8)
136 adjlist[i].push_back(j);
144 for (
int i = 0; i < col; i++)
146 for (
int j = 0; j < row; j++)
148 if (std::abs(A[i][j]) > 1.e-8)
149 adjlist[i].push_back(j);
158 template <
typename T>
160 const std::string filename)
170 int col = A[0].size();
173 ofile.open(filename);
176 for (
int i = 0; i < row; i++)
178 for (
int j = 0; j < col; j++)
180 ofile << A[i][j] <<
" ";
187 std::cout <<
"Error opening file to write data. \n";
191 template <
typename T>
193 const std::string filename)
206 ofile.open(filename);
209 for (
size_t i = 0; i < n; ++i)
210 ofile << v[i] <<
"\n";
215 std::cout <<
"Error opening file to write data. \n";
222 const std::vector<std::vector<double>> &spikes)
226 spkfile = fopen(filename.c_str(),
"w");
230 for (
size_t i = 0; i < spikes.size(); i++)
232 for (
size_t j = 0; j < spikes[i].size(); j++)
234 fprintf(spkfile,
"%18.6f", spikes[i][j]);
236 fprintf(spkfile,
"\n");
243 printf(
"Could not open file properly in spike_to_file!\n");
void write_matrix_to_file(const std::vector< std::vector< T >> &A, const std::string filename)
Definition: IO.hpp:159
void spikes_to_file(const std::string filename, const std::vector< std::vector< double >> &spikes)
Definition: IO.hpp:221
void write_vector_to_file(const std::vector< T > &v, const std::string filename)
Definition: IO.hpp:192
bool file_exists(const std::string &filename)
Definition: IO.hpp:43
std::vector< T > load_vector(std::string filename)
Definition: IO.hpp:10
std::vector< std::vector< T > > load_matrix(const std::string filename, const int row, const int col)
Definition: IO.hpp:62
std::vector< std::vector< T > > adjmat_to_adjlist(const std::vector< std::vector< T >> &A, const double threshold=1e-8, std::string in_degree="row")
Definition: IO.hpp:107