-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathconvert_matrixmarket.cpp
More file actions
62 lines (51 loc) · 2.18 KB
/
convert_matrixmarket.cpp
File metadata and controls
62 lines (51 loc) · 2.18 KB
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
#include <binsparse/binsparse.hpp>
#include <complex>
#include <concepts>
#include <iostream>
int main(int argc, char** argv) {
if (argc < 2) {
std::cout << "usage: ./convert_binsparse [matrix.bsp.h5]\n";
return 1;
}
std::string input_file(argv[1]);
auto json = binsparse::inspect(input_file);
auto metadata = json["binsparse"];
std::cout << "Inspecting Binsparse v" << metadata["version"] << " file...\n";
std::cout << metadata["format"] << " format matrix of dimension "
<< metadata["shape"] << " with "
<< metadata["number_of_stored_values"] << " nonzeros\n";
if (metadata["format"] == "COO") {
auto i0 = metadata["data_types"]["indices_0"];
auto i1 = metadata["data_types"]["indices_1"];
auto t = metadata["data_types"]["values"];
binsparse::visit_label(
{i0, i1, t},
[&]<typename I1, typename I2, typename T>(I1 i, I2 j, T v) {
using I = std::conditional_t<std::numeric_limits<I1>::max() <
std::numeric_limits<I2>::max(),
I2, I1>;
std::cout << "Reading binsparse with index and value types: "
<< binsparse::type_info<I>::label() << " "
<< binsparse::type_info<T>::label() << "\n";
auto m = binsparse::read_coo_matrix<T, I>(input_file);
});
} else if (metadata["format"] == "CSR") {
auto i0 = metadata["data_types"]["pointers_to_1"];
auto i1 = metadata["data_types"]["indices_1"];
auto t = metadata["data_types"]["values"];
binsparse::visit_label(
{i0, i1, t},
[&]<typename I1, typename I2, typename T>(I1 i, I2 j, T v) {
using I = std::conditional_t<std::numeric_limits<I1>::max() <
std::numeric_limits<I2>::max(),
I2, I1>;
std::cout << "Reading binsparse with index and value types: "
<< binsparse::type_info<I>::label() << " "
<< binsparse::type_info<T>::label() << "\n";
auto m = binsparse::read_csr_matrix<T, I>(input_file);
});
} else {
assert(false);
}
return 0;
}