@@ -60,22 +60,20 @@ csr_matrix<T, I> read_csr_matrix(std::string fname, Allocator&& alloc) {
6060
6161 auto binsparse_metadata = data[" binsparse" ];
6262
63- if (binsparse_metadata[" format" ] == " CSR" ) {
64- auto nrows = binsparse_metadata[" shape" ][0 ];
65- auto ncols = binsparse_metadata[" shape" ][1 ];
66- auto nnz = binsparse_metadata[" nnz" ];
63+ assert (binsparse_metadata[" format" ] == " CSR" );
6764
68- typename std::allocator_traits<std::remove_cvref_t <Allocator>>
69- :: template rebind_alloc<I> i_alloc (alloc);
65+ auto nrows = binsparse_metadata[" shape" ][0 ];
66+ auto ncols = binsparse_metadata[" shape" ][1 ];
67+ auto nnz = binsparse_metadata[" nnz" ];
7068
71- auto values = hdf5_tools::read_dataset<T>(f, " values" , alloc);
72- auto colind = hdf5_tools::read_dataset<I>(f, " indices_1" , i_alloc);
73- auto row_ptr = hdf5_tools::read_dataset<I>(f, " pointers_to_1" , i_alloc);
69+ typename std::allocator_traits<std::remove_cvref_t <Allocator>>
70+ :: template rebind_alloc<I> i_alloc (alloc);
7471
75- return csr_matrix<T, I>{values.data (), colind.data (), row_ptr.data (), nrows, ncols, nnz};
76- } else {
77- assert (false );
78- }
72+ auto values = hdf5_tools::read_dataset<T>(f, " values" , alloc);
73+ auto colind = hdf5_tools::read_dataset<I>(f, " indices_1" , i_alloc);
74+ auto row_ptr = hdf5_tools::read_dataset<I>(f, " pointers_to_1" , i_alloc);
75+
76+ return csr_matrix<T, I>{values.data (), colind.data (), row_ptr.data (), nrows, ncols, nnz};
7977}
8078
8179template <typename T, typename I>
@@ -130,22 +128,20 @@ coo_matrix<T, I> read_coo_matrix(std::string fname, Allocator&& alloc) {
130128
131129 auto binsparse_metadata = data[" binsparse" ];
132130
133- if (binsparse_metadata[" format" ] == " COO" ) {
134- auto nrows = binsparse_metadata[" shape" ][0 ];
135- auto ncols = binsparse_metadata[" shape" ][1 ];
136- auto nnz = binsparse_metadata[" nnz" ];
131+ assert (binsparse_metadata[" format" ] == " COO" );
137132
138- typename std::allocator_traits<std::remove_cvref_t <Allocator>>
139- :: template rebind_alloc<I> i_alloc (alloc);
133+ auto nrows = binsparse_metadata[" shape" ][0 ];
134+ auto ncols = binsparse_metadata[" shape" ][1 ];
135+ auto nnz = binsparse_metadata[" nnz" ];
140136
141- auto values = hdf5_tools::read_dataset<T>(f, " values" , alloc);
142- auto rows = hdf5_tools::read_dataset<I>(f, " indices_0" , i_alloc);
143- auto cols = hdf5_tools::read_dataset<I>(f, " indices_1" , i_alloc);
137+ typename std::allocator_traits<std::remove_cvref_t <Allocator>>
138+ :: template rebind_alloc<I> i_alloc (alloc);
144139
145- return coo_matrix<T, I>{values.data (), rows.data (), cols.data (), nrows, ncols, nnz};
146- } else {
147- assert (false );
148- }
140+ auto values = hdf5_tools::read_dataset<T>(f, " values" , alloc);
141+ auto rows = hdf5_tools::read_dataset<I>(f, " indices_0" , i_alloc);
142+ auto cols = hdf5_tools::read_dataset<I>(f, " indices_1" , i_alloc);
143+
144+ return coo_matrix<T, I>{values.data (), rows.data (), cols.data (), nrows, ncols, nnz};
149145}
150146
151147template <typename T, typename I>
@@ -163,11 +159,9 @@ inline auto inspect(std::string fname) {
163159
164160 auto binsparse_metadata = data[" binsparse" ];
165161
166- if (binsparse_metadata[" version" ] >= 0.1 ) {
167- return data;
168- } else {
169- assert (false );
170- }
162+ assert (binsparse_metadata[" version" ] >= 0.1 );
163+
164+ return data;
171165}
172166
173167} // end binsparse
0 commit comments