Caffe2 - C++ API
A deep learning, cross platform ML framework
mmio.h
1 #pragma once
2 
3 #include <cstdio>
4 #include <set>
5 #include <string>
6 #include <type_traits>
7 
8 namespace caffe2 {
9 
10 template <typename T>
11 void StoreMatrixInMatrixMarketFormat(
12  int m,
13  int n,
14  const T* a,
15  const std::string& matrix_name) {
16  using namespace std;
17  static_assert(
18  is_integral<T>::value,
19  "StoreMatrixInMatrixMarket only works with integer types");
20 
21  static set<string> dumped_matrix_names;
22 
23  string name(matrix_name);
24  string::size_type pos = name.rfind('/');
25  if (pos != string::npos) {
26  name = name.substr(pos + 1);
27  }
28  if (dumped_matrix_names.find(name) == dumped_matrix_names.end()) {
29  dumped_matrix_names.insert(name);
30 
31  FILE* fp = fopen((name + ".mtx").c_str(), "w");
32  if (!fp) {
33  return;
34  }
35 
36  fprintf(fp, "%%%%MatrixMarket matrix array integer general\n");
37  fprintf(fp, "%d %d\n", m, n);
38  // matrix market array format uses column-major order
39  for (int j = 0; j < n; ++j) {
40  for (int i = 0; i < m; ++i) {
41  fprintf(fp, "%d\n", a[j * m + i]);
42  }
43  }
44 
45  fclose(fp);
46  }
47 }
48 
49 } // namespace caffe2
A global dictionary that holds information about what Caffe2 modules have been loaded in the current ...
Definition: blob.h:13