11
11
#include < binsparse/c_bindings/allocator_wrapper.hpp>
12
12
#include < binsparse/matrix_market/matrix_market.hpp>
13
13
14
- #include < iostream>
15
-
16
14
namespace binsparse {
17
15
18
16
// CSR Format
@@ -46,7 +44,7 @@ void write_csr_matrix(std::string fname,
46
44
j[v.key ()] = v.value ();
47
45
}
48
46
49
- hdf5_tools::write_dataset (f, " metadata " , j.dump (2 ));
47
+ hdf5_tools::set_attribute (f, " binsparse " , j.dump (2 ));
50
48
51
49
f.close ();
52
50
}
@@ -60,10 +58,12 @@ csr_matrix<T, I> read_csr_matrix(std::string fname, Allocator&& alloc) {
60
58
using json = nlohmann::json;
61
59
auto data = json::parse (metadata);
62
60
63
- if (data[" binsparse" ][" format" ] == " CSR" ) {
64
- auto nrows = data[" binsparse" ][" shape" ][0 ];
65
- auto ncols = data[" binsparse" ][" shape" ][1 ];
66
- auto nnz = data[" binsparse" ][" nnz" ];
61
+ auto binsparse_metadata = data[" binsparse" ];
62
+
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" ];
67
67
68
68
typename std::allocator_traits<std::remove_cvref_t <Allocator>>
69
69
:: template rebind_alloc<I> i_alloc (alloc);
@@ -114,7 +114,7 @@ void write_coo_matrix(std::string fname,
114
114
j[v.key ()] = v.value ();
115
115
}
116
116
117
- hdf5_tools::write_dataset (f, " metadata " , j.dump (2 ));
117
+ hdf5_tools::set_attribute (f, " binsparse " , j.dump (2 ));
118
118
119
119
f.close ();
120
120
}
@@ -128,10 +128,12 @@ coo_matrix<T, I> read_coo_matrix(std::string fname, Allocator&& alloc) {
128
128
using json = nlohmann::json;
129
129
auto data = json::parse (metadata);
130
130
131
- if (data[" binsparse" ][" format" ] == " COO" ) {
132
- auto nrows = data[" binsparse" ][" shape" ][0 ];
133
- auto ncols = data[" binsparse" ][" shape" ][1 ];
134
- auto nnz = data[" binsparse" ][" nnz" ];
131
+ auto binsparse_metadata = data[" binsparse" ];
132
+
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" ];
135
137
136
138
typename std::allocator_traits<std::remove_cvref_t <Allocator>>
137
139
:: template rebind_alloc<I> i_alloc (alloc);
@@ -154,12 +156,14 @@ coo_matrix<T, I> read_coo_matrix(std::string fname) {
154
156
inline auto inspect (std::string fname) {
155
157
H5::H5File f (fname.c_str (), H5F_ACC_RDWR);
156
158
157
- auto metadata = hdf5_tools::read_dataset< char > (f, " metadata " );
159
+ auto metadata = hdf5_tools::get_attribute (f, " binsparse " );
158
160
159
161
using json = nlohmann::json;
160
162
auto data = json::parse (metadata);
161
163
162
- if (data[" binsparse" ][" version" ] >= 0.1 ) {
164
+ auto binsparse_metadata = data[" binsparse" ];
165
+
166
+ if (binsparse_metadata[" version" ] >= 0.1 ) {
163
167
return data;
164
168
} else {
165
169
assert (false );
0 commit comments