-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinspect_binsparse.cpp
More file actions
59 lines (47 loc) · 1.58 KB
/
inspect_binsparse.cpp
File metadata and controls
59 lines (47 loc) · 1.58 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
#include <binsparse/binsparse.hpp>
#include <complex>
#include <concepts>
#include <iostream>
#include <ranges>
class Foo {};
int main(int argc, char** argv) {
if (argc < 2) {
std::cout << "usage: ./inspect_binsparse [input_file.mtx]\n";
return 1;
}
std::string input_file(argv[1]);
auto j = binsparse::inspect(input_file);
auto metadata = j["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"];
std::cout << "Stored using index types: " << i0 << " " << i1 << std::endl;
std::cout << "Value type: " << t << std::endl;
} 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"];
std::cout << "Stored using index types: " << i0 << " " << i1 << " and "
<< "value type: " << t << std::endl;
} else {
assert(false);
}
nlohmann::json user;
std::cout << "User-provided keys:\n";
std::size_t n_keys = 0;
for (auto&& v : j.items()) {
if (v.key() != "binsparse") {
user[v.key()] = v.value();
n_keys++;
}
}
if (n_keys > 0) {
std::cout << user.dump(2) << std::endl;
}
return 0;
}