@@ -34,6 +34,11 @@ void write_dense_matrix(std::string fname, dense_matrix<T, I, Order> m,
3434 j[" binsparse" ][" nnz" ] = m.m * m.n ;
3535 j[" binsparse" ][" data_types" ][" values" ] = type_info<T>::label ();
3636
37+ if (m.structure != general) {
38+ j[" binsparse" ][" structure" ] =
39+ __detail::get_structure_name (m.structure ).value ();
40+ }
41+
3742 for (auto && v : user_keys.items ()) {
3843 j[v.key ()] = v.value ();
3944 }
@@ -67,7 +72,13 @@ auto read_dense_matrix(std::string fname, Allocator&& alloc = Allocator{}) {
6772
6873 auto values = hdf5_tools::read_dataset<T>(f, " values" , alloc);
6974
70- return dense_matrix<T, I, Order>{values.data (), nrows, ncols};
75+ structure_t structure = general;
76+
77+ if (binsparse_metadata.contains (" structure" )) {
78+ structure = __detail::parse_structure (binsparse_metadata[" structure" ]);
79+ }
80+
81+ return dense_matrix<T, I, Order>{values.data (), nrows, ncols, structure};
7182}
7283
7384// CSR Format
@@ -96,6 +107,11 @@ void write_csr_matrix(std::string fname, csr_matrix<T, I> m,
96107 j[" binsparse" ][" data_types" ][" indices_1" ] = type_info<I>::label ();
97108 j[" binsparse" ][" data_types" ][" values" ] = type_info<T>::label ();
98109
110+ if (m.structure != general) {
111+ j[" binsparse" ][" structure" ] =
112+ __detail::get_structure_name (m.structure ).value ();
113+ }
114+
99115 for (auto && v : user_keys.items ()) {
100116 j[v.key ()] = v.value ();
101117 }
@@ -130,8 +146,14 @@ csr_matrix<T, I> read_csr_matrix(std::string fname, Allocator&& alloc) {
130146 auto colind = hdf5_tools::read_dataset<I>(f, " indices_1" , i_alloc);
131147 auto row_ptr = hdf5_tools::read_dataset<I>(f, " pointers_to_1" , i_alloc);
132148
133- return csr_matrix<T, I>{values.data (), colind.data (), row_ptr.data (),
134- nrows, ncols, nnz};
149+ structure_t structure = general;
150+
151+ if (binsparse_metadata.contains (" structure" )) {
152+ structure = __detail::parse_structure (binsparse_metadata[" structure" ]);
153+ }
154+
155+ return csr_matrix<T, I>{values.data (), colind.data (), row_ptr.data (), nrows,
156+ ncols, nnz, structure};
135157}
136158
137159template <typename T, typename I>
@@ -165,6 +187,11 @@ void write_csc_matrix(std::string fname, csc_matrix<T, I> m,
165187 j[" binsparse" ][" data_types" ][" indices_1" ] = type_info<I>::label ();
166188 j[" binsparse" ][" data_types" ][" values" ] = type_info<T>::label ();
167189
190+ if (m.structure != general) {
191+ j[" binsparse" ][" structure" ] =
192+ __detail::get_structure_name (m.structure ).value ();
193+ }
194+
168195 for (auto && v : user_keys.items ()) {
169196 j[v.key ()] = v.value ();
170197 }
@@ -199,8 +226,14 @@ csc_matrix<T, I> read_csc_matrix(std::string fname, Allocator&& alloc) {
199226 auto rowind = hdf5_tools::read_dataset<I>(f, " indices_1" , i_alloc);
200227 auto col_ptr = hdf5_tools::read_dataset<I>(f, " pointers_to_1" , i_alloc);
201228
202- return csc_matrix<T, I>{values.data (), rowind.data (), col_ptr.data (),
203- nrows, ncols, nnz};
229+ structure_t structure = general;
230+
231+ if (binsparse_metadata.contains (" structure" )) {
232+ structure = __detail::parse_structure (binsparse_metadata[" structure" ]);
233+ }
234+
235+ return csc_matrix<T, I>{values.data (), rowind.data (), col_ptr.data (), nrows,
236+ ncols, nnz, structure};
204237}
205238
206239template <typename T, typename I>
@@ -234,6 +267,11 @@ void write_coo_matrix(std::string fname, coo_matrix<T, I> m,
234267 j[" binsparse" ][" data_types" ][" indices_1" ] = type_info<I>::label ();
235268 j[" binsparse" ][" data_types" ][" values" ] = type_info<T>::label ();
236269
270+ if (m.structure != general) {
271+ j[" binsparse" ][" structure" ] =
272+ __detail::get_structure_name (m.structure ).value ();
273+ }
274+
237275 for (auto && v : user_keys.items ()) {
238276 j[v.key ()] = v.value ();
239277 }
@@ -270,8 +308,14 @@ coo_matrix<T, I> read_coo_matrix(std::string fname, Allocator&& alloc) {
270308 auto rows = hdf5_tools::read_dataset<I>(f, " indices_0" , i_alloc);
271309 auto cols = hdf5_tools::read_dataset<I>(f, " indices_1" , i_alloc);
272310
273- return coo_matrix<T, I>{values.data (), rows.data (), cols.data (),
274- nrows, ncols, nnz};
311+ structure_t structure = general;
312+
313+ if (binsparse_metadata.contains (" structure" )) {
314+ structure = __detail::parse_structure (binsparse_metadata[" structure" ]);
315+ }
316+
317+ return coo_matrix<T, I>{values.data (), rows.data (), cols.data (), nrows,
318+ ncols, nnz, structure};
275319}
276320
277321template <typename T, typename I>
0 commit comments