1
1
#include < binsparse/binsparse.hpp>
2
- #include < iostream>
3
- #include < concepts>
4
2
#include < complex>
3
+ #include < concepts>
4
+ #include < iostream>
5
5
6
6
template <typename T, typename I>
7
- void convert_to_binsparse (std::string input_file, std::string output_file, std::string format, std::string comment) {
7
+ void convert_to_binsparse (std::string input_file, std::string output_file,
8
+ std::string format, std::string comment) {
8
9
nlohmann::json user_keys;
9
10
user_keys[" comment" ] = comment;
10
11
if (format == " CSR" ) {
11
12
std::cout << " Reading in " << input_file << " ...\n " ;
12
- auto x = binsparse::__detail::mmread<T, I, binsparse::__detail::csr_matrix_owning<T, I>>(input_file);
13
- binsparse::csr_matrix<T, I> matrix{x.values ().data (), x.colind ().data (), x.rowptr ().data (), std::get<0 >(x.shape ()), std::get<1 >(x.shape ()), I (x.size ())};
13
+ auto x = binsparse::__detail::mmread<
14
+ T, I, binsparse::__detail::csr_matrix_owning<T, I>>(input_file);
15
+ binsparse::csr_matrix<T, I> matrix{
16
+ x.values ().data (), x.colind ().data (), x.rowptr ().data (),
17
+ std::get<0 >(x.shape ()), std::get<1 >(x.shape ()), I (x.size ())};
14
18
binsparse::write_csr_matrix (output_file, matrix, user_keys);
15
- std::cout << " Writing to binsparse file " << output_file << " using " << format << " format...\n " ;
19
+ std::cout << " Writing to binsparse file " << output_file << " using "
20
+ << format << " format...\n " ;
16
21
} else {
17
- auto x = binsparse::__detail::mmread<T, I, binsparse::__detail::coo_matrix_owning<T, I>>(input_file);
18
- binsparse::coo_matrix<T, I> matrix{x.values ().data (), x.rowind ().data (), x.colind ().data (), std::get<0 >(x.shape ()), std::get<1 >(x.shape ()), I (x.size ())};
22
+ auto x = binsparse::__detail::mmread<
23
+ T, I, binsparse::__detail::coo_matrix_owning<T, I>>(input_file);
24
+ binsparse::coo_matrix<T, I> matrix{
25
+ x.values ().data (), x.rowind ().data (), x.colind ().data (),
26
+ std::get<0 >(x.shape ()), std::get<1 >(x.shape ()), I (x.size ())};
19
27
binsparse::write_coo_matrix (output_file, matrix, user_keys);
20
- std::cout << " Writing to binsparse file " << output_file << " using " << format << " format...\n " ;
28
+ std::cout << " Writing to binsparse file " << output_file << " using "
29
+ << format << " format...\n " ;
21
30
}
22
31
}
23
32
24
33
template <typename I>
25
- void convert_to_binsparse (std::string input_file, std::string output_file, std::string type,
26
- std::string format, std::string comment) {
34
+ void convert_to_binsparse (std::string input_file, std::string output_file,
35
+ std::string type, std::string format,
36
+ std::string comment) {
27
37
if (type == " real" ) {
28
38
convert_to_binsparse<float , I>(input_file, output_file, format, comment);
29
39
} else if (type == " complex" ) {
30
40
assert (false );
31
- // convert_to_binsparse<std::complex<float>, I>(input_file, output_file, format, comment);
41
+ // convert_to_binsparse<std::complex<float>, I>(input_file, output_file,
42
+ // format, comment);
32
43
} else if (type == " integer" ) {
33
44
convert_to_binsparse<int64_t , I>(input_file, output_file, format, comment);
34
45
} else if (type == " pattern" ) {
35
46
convert_to_binsparse<uint8_t , I>(input_file, output_file, format, comment);
36
47
}
37
48
}
38
49
39
-
40
50
int main (int argc, char ** argv) {
41
51
42
52
if (argc < 3 ) {
43
- std::cout << " usage: ./convert_binsparse [input_file.mtx] [output_file.hdf5] [optional: format {CSR, COO}]\n " ;
53
+ std::cout << " usage: ./convert_binsparse [input_file.mtx] "
54
+ " [output_file.hdf5] [optional: format {CSR, COO}]\n " ;
44
55
return 1 ;
45
56
}
46
57
@@ -61,7 +72,8 @@ int main(int argc, char** argv) {
61
72
62
73
auto [m, n, nnz, type, comment] = binsparse::mmread_metadata (input_file);
63
74
64
- std::cout << " Matrix is " << m << " x " << n << " with " << nnz << " values.\n " ;
75
+ std::cout << " Matrix is " << m << " x " << n << " with " << nnz
76
+ << " values.\n " ;
65
77
std::cout << " Type: " << type << std::endl;
66
78
std::cout << " Comment:\n " ;
67
79
std::cout << comment;
@@ -71,15 +83,20 @@ int main(int argc, char** argv) {
71
83
auto max_size = std::max ({m, n, nnz});
72
84
73
85
if (max_size + 1 <= std::numeric_limits<uint8_t >::max ()) {
74
- convert_to_binsparse<uint8_t >(input_file, output_file, type, format, comment);
86
+ convert_to_binsparse<uint8_t >(input_file, output_file, type, format,
87
+ comment);
75
88
} else if (max_size + 1 <= std::numeric_limits<uint16_t >::max ()) {
76
- convert_to_binsparse<uint16_t >(input_file, output_file, type, format, comment);
89
+ convert_to_binsparse<uint16_t >(input_file, output_file, type, format,
90
+ comment);
77
91
} else if (max_size + 1 <= std::numeric_limits<uint32_t >::max ()) {
78
- convert_to_binsparse<uint32_t >(input_file, output_file, type, format, comment);
92
+ convert_to_binsparse<uint32_t >(input_file, output_file, type, format,
93
+ comment);
79
94
} else if (max_size + 1 <= std::numeric_limits<uint64_t >::max ()) {
80
- convert_to_binsparse<uint64_t >(input_file, output_file, type, format, comment);
95
+ convert_to_binsparse<uint64_t >(input_file, output_file, type, format,
96
+ comment);
81
97
} else {
82
- throw std::runtime_error (" Error! Matrix dimensions or NNZ too large to handle." );
98
+ throw std::runtime_error (
99
+ " Error! Matrix dimensions or NNZ too large to handle." );
83
100
}
84
101
85
102
return 0 ;
0 commit comments