Skip to content

Commit d67cfa6

Browse files
committed
Updates to conform with current version of Binsparse
1 parent 02b85c2 commit d67cfa6

File tree

4 files changed

+66
-14
lines changed

4 files changed

+66
-14
lines changed

examples/convert_matrixmarket.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#include <iostream>
55

66
int main(int argc, char** argv) {
7-
87
if (argc < 2) {
98
std::cout << "usage: ./convert_binsparse [matrix.bsp.h5]\n";
109
return 1;
@@ -18,8 +17,8 @@ int main(int argc, char** argv) {
1817

1918
std::cout << "Inspecting Binsparse v" << metadata["version"] << " file...\n";
2019
std::cout << metadata["format"] << " format matrix of dimension "
21-
<< metadata["shape"] << " with " << metadata["nnz"]
22-
<< " nonzeros\n";
20+
<< metadata["shape"] << " with "
21+
<< metadata["number_of_stored_values"] << " nonzeros\n";
2322

2423
if (metadata["format"] == "COO") {
2524
auto i0 = metadata["data_types"]["indices_0"];

examples/inspect_binsparse.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ int main(int argc, char** argv) {
2121

2222
std::cout << "Inspecting Binsparse v" << metadata["version"] << " file...\n";
2323
std::cout << metadata["format"] << " format matrix of dimension "
24-
<< metadata["shape"] << " with " << metadata["nnz"]
25-
<< " nonzeros\n";
24+
<< metadata["shape"] << " with "
25+
<< metadata["number_of_stored_values"] << " nonzeros\n";
2626

2727
if (metadata["format"] == "COO") {
2828
auto i0 = metadata["data_types"]["indices_0"];

include/binsparse/binsparse.hpp

Lines changed: 58 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
namespace binsparse {
1515

16-
inline constexpr double version = 0.1;
16+
inline constexpr std::string version = "0.1";
1717

1818
template <typename T>
1919
void write_dense_vector(H5::Group& f, std::span<T> v,
@@ -77,7 +77,13 @@ void write_dense_matrix(H5::Group& f, dense_matrix<T, I, Order> m,
7777
j["binsparse"]["format"] = __detail::get_matrix_format_string(m);
7878
j["binsparse"]["shape"] = {m.m, m.n};
7979
j["binsparse"]["number_of_stored_values"] = m.m * m.n;
80-
j["binsparse"]["data_types"]["values"] = type_info<T>::label();
80+
81+
if (!m.is_iso) {
82+
j["binsparse"]["data_types"]["values"] =
83+
std::string("iso[") + type_info<T>::label() + "]";
84+
} else {
85+
j["binsparse"]["data_types"]["values"] = type_info<T>::label();
86+
}
8187

8288
if (m.structure != general) {
8389
j["binsparse"]["structure"] =
@@ -120,6 +126,12 @@ auto read_dense_matrix(std::string fname, Allocator&& alloc = Allocator{}) {
120126
auto ncols = binsparse_metadata["shape"][1];
121127
auto nnz = binsparse_metadata["number_of_stored_values"];
122128

129+
bool is_iso = false;
130+
if (std::string(binsparse_metadata["data_types"]["values"])
131+
.starts_with("iso")) {
132+
is_iso = true;
133+
}
134+
123135
auto values = hdf5_tools::read_dataset<T>(f, "values", alloc);
124136

125137
structure_t structure = general;
@@ -128,7 +140,8 @@ auto read_dense_matrix(std::string fname, Allocator&& alloc = Allocator{}) {
128140
structure = __detail::parse_structure(binsparse_metadata["structure"]);
129141
}
130142

131-
return dense_matrix<T, I, Order>{values.data(), nrows, ncols, structure};
143+
return dense_matrix<T, I, Order>{values.data(), nrows, ncols, structure,
144+
is_iso};
132145
}
133146

134147
// CSR Format
@@ -152,7 +165,13 @@ void write_csr_matrix(H5::Group& f, csr_matrix<T, I> m,
152165
j["binsparse"]["number_of_stored_values"] = m.nnz;
153166
j["binsparse"]["data_types"]["pointers_to_1"] = type_info<I>::label();
154167
j["binsparse"]["data_types"]["indices_1"] = type_info<I>::label();
155-
j["binsparse"]["data_types"]["values"] = type_info<T>::label();
168+
169+
if (!m.is_iso) {
170+
j["binsparse"]["data_types"]["values"] =
171+
std::string("iso[") + type_info<T>::label() + "]";
172+
} else {
173+
j["binsparse"]["data_types"]["values"] = type_info<T>::label();
174+
}
156175

157176
if (m.structure != general) {
158177
j["binsparse"]["structure"] =
@@ -191,6 +210,12 @@ csr_matrix<T, I> read_csr_matrix(std::string fname, Allocator&& alloc) {
191210
auto ncols = binsparse_metadata["shape"][1];
192211
auto nnz = binsparse_metadata["number_of_stored_values"];
193212

213+
bool is_iso = false;
214+
if (std::string(binsparse_metadata["data_types"]["values"])
215+
.starts_with("iso")) {
216+
is_iso = true;
217+
}
218+
194219
typename std::allocator_traits<
195220
std::remove_cvref_t<Allocator>>::template rebind_alloc<I>
196221
i_alloc(alloc);
@@ -206,7 +231,7 @@ csr_matrix<T, I> read_csr_matrix(std::string fname, Allocator&& alloc) {
206231
}
207232

208233
return csr_matrix<T, I>{values.data(), colind.data(), row_ptr.data(), nrows,
209-
ncols, nnz, structure};
234+
ncols, nnz, structure, is_iso};
210235
}
211236

212237
template <typename T, typename I>
@@ -235,7 +260,13 @@ void write_csc_matrix(H5::Group& f, csc_matrix<T, I> m,
235260
j["binsparse"]["number_of_stored_values"] = m.nnz;
236261
j["binsparse"]["data_types"]["pointers_to_1"] = type_info<I>::label();
237262
j["binsparse"]["data_types"]["indices_1"] = type_info<I>::label();
238-
j["binsparse"]["data_types"]["values"] = type_info<T>::label();
263+
264+
if (!m.is_iso) {
265+
j["binsparse"]["data_types"]["values"] =
266+
std::string("iso[") + type_info<T>::label() + "]";
267+
} else {
268+
j["binsparse"]["data_types"]["values"] = type_info<T>::label();
269+
}
239270

240271
if (m.structure != general) {
241272
j["binsparse"]["structure"] =
@@ -274,6 +305,12 @@ csc_matrix<T, I> read_csc_matrix(std::string fname, Allocator&& alloc) {
274305
auto ncols = binsparse_metadata["shape"][1];
275306
auto nnz = binsparse_metadata["number_of_stored_values"];
276307

308+
bool is_iso = false;
309+
if (std::string(binsparse_metadata["data_types"]["values"])
310+
.starts_with("iso")) {
311+
is_iso = true;
312+
}
313+
277314
typename std::allocator_traits<
278315
std::remove_cvref_t<Allocator>>::template rebind_alloc<I>
279316
i_alloc(alloc);
@@ -289,7 +326,7 @@ csc_matrix<T, I> read_csc_matrix(std::string fname, Allocator&& alloc) {
289326
}
290327

291328
return csc_matrix<T, I>{values.data(), rowind.data(), col_ptr.data(), nrows,
292-
ncols, nnz, structure};
329+
ncols, nnz, structure, is_iso};
293330
}
294331

295332
template <typename T, typename I>
@@ -318,7 +355,13 @@ void write_coo_matrix(H5::Group& f, coo_matrix<T, I> m,
318355
j["binsparse"]["number_of_stored_values"] = m.nnz;
319356
j["binsparse"]["data_types"]["indices_0"] = type_info<I>::label();
320357
j["binsparse"]["data_types"]["indices_1"] = type_info<I>::label();
321-
j["binsparse"]["data_types"]["values"] = type_info<T>::label();
358+
359+
if (!m.is_iso) {
360+
j["binsparse"]["data_types"]["values"] =
361+
std::string("iso[") + type_info<T>::label() + "]";
362+
} else {
363+
j["binsparse"]["data_types"]["values"] = type_info<T>::label();
364+
}
322365

323366
if (m.structure != general) {
324367
j["binsparse"]["structure"] =
@@ -359,6 +402,12 @@ coo_matrix<T, I> read_coo_matrix(std::string fname, Allocator&& alloc) {
359402
auto ncols = binsparse_metadata["shape"][1];
360403
auto nnz = binsparse_metadata["number_of_stored_values"];
361404

405+
bool is_iso = false;
406+
if (std::string(binsparse_metadata["data_types"]["values"])
407+
.starts_with("iso")) {
408+
is_iso = true;
409+
}
410+
362411
typename std::allocator_traits<
363412
std::remove_cvref_t<Allocator>>::template rebind_alloc<I>
364413
i_alloc(alloc);
@@ -374,7 +423,7 @@ coo_matrix<T, I> read_coo_matrix(std::string fname, Allocator&& alloc) {
374423
}
375424

376425
return coo_matrix<T, I>{values.data(), rows.data(), cols.data(), nrows,
377-
ncols, nnz, structure};
426+
ncols, nnz, structure, is_iso};
378427
}
379428

380429
template <typename T, typename I>

include/binsparse/containers/matrices.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ struct csr_matrix {
3434

3535
I m, n, nnz;
3636
structure_t structure = general;
37+
bool is_iso = false;
3738
};
3839

3940
template <typename T, typename I>
@@ -44,6 +45,7 @@ struct csc_matrix {
4445

4546
I m, n, nnz;
4647
structure_t structure = general;
48+
bool is_iso = false;
4749
};
4850

4951
template <typename T, typename I>
@@ -54,6 +56,7 @@ struct coo_matrix {
5456

5557
I m, n, nnz;
5658
structure_t structure = general;
59+
bool is_iso = false;
5760
};
5861

5962
template <typename T, typename I = std::size_t, typename Order = row_major>
@@ -64,6 +67,7 @@ struct dense_matrix {
6467
structure_t structure = general;
6568

6669
using order = Order;
70+
bool is_iso = false;
6771
};
6872

6973
} // namespace binsparse

0 commit comments

Comments
 (0)