11#include < binsparse/binsparse.hpp>
2- #include < iostream>
3- #include < concepts>
42#include < complex>
3+ #include < concepts>
4+ #include < iostream>
55
66template <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) {
89 nlohmann::json user_keys;
910 user_keys[" comment" ] = comment;
1011 if (format == " CSR" ) {
1112 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 ())};
1418 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 " ;
1621 } 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 ())};
1927 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 " ;
2130 }
2231}
2332
2433template <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) {
2737 if (type == " real" ) {
2838 convert_to_binsparse<float , I>(input_file, output_file, format, comment);
2939 } else if (type == " complex" ) {
3040 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);
3243 } else if (type == " integer" ) {
3344 convert_to_binsparse<int64_t , I>(input_file, output_file, format, comment);
3445 } else if (type == " pattern" ) {
3546 convert_to_binsparse<uint8_t , I>(input_file, output_file, format, comment);
3647 }
3748}
3849
39-
4050int main (int argc, char ** argv) {
4151
4252 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 " ;
4455 return 1 ;
4556 }
4657
@@ -61,7 +72,8 @@ int main(int argc, char** argv) {
6172
6273 auto [m, n, nnz, type, comment] = binsparse::mmread_metadata (input_file);
6374
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 " ;
6577 std::cout << " Type: " << type << std::endl;
6678 std::cout << " Comment:\n " ;
6779 std::cout << comment;
@@ -71,15 +83,20 @@ int main(int argc, char** argv) {
7183 auto max_size = std::max ({m, n, nnz});
7284
7385 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);
7588 } 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);
7791 } 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);
7994 } 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);
8197 } 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." );
83100 }
84101
85102 return 0 ;
0 commit comments