diff --git a/examples/convert_matrixmarket.cpp b/examples/convert_matrixmarket.cpp index bba0b81..43d9a1e 100644 --- a/examples/convert_matrixmarket.cpp +++ b/examples/convert_matrixmarket.cpp @@ -4,9 +4,8 @@ #include int main(int argc, char** argv) { - if (argc < 2) { - std::cout << "usage: ./inspect_binsparse [matrix.bsp.h5]\n"; + std::cout << "usage: ./convert_binsparse [matrix.bsp.h5]\n"; return 1; } @@ -18,8 +17,8 @@ int main(int argc, char** argv) { std::cout << "Inspecting Binsparse v" << metadata["version"] << " file...\n"; std::cout << metadata["format"] << " format matrix of dimension " - << metadata["shape"] << " with " << metadata["nnz"] - << " nonzeros\n"; + << metadata["shape"] << " with " + << metadata["number_of_stored_values"] << " nonzeros\n"; if (metadata["format"] == "COO") { auto i0 = metadata["data_types"]["indices_0"]; diff --git a/examples/inspect_binsparse.cpp b/examples/inspect_binsparse.cpp index 0fb390e..5524308 100644 --- a/examples/inspect_binsparse.cpp +++ b/examples/inspect_binsparse.cpp @@ -21,8 +21,8 @@ int main(int argc, char** argv) { std::cout << "Inspecting Binsparse v" << metadata["version"] << " file...\n"; std::cout << metadata["format"] << " format matrix of dimension " - << metadata["shape"] << " with " << metadata["nnz"] - << " nonzeros\n"; + << metadata["shape"] << " with " + << metadata["number_of_stored_values"] << " nonzeros\n"; if (metadata["format"] == "COO") { auto i0 = metadata["data_types"]["indices_0"]; diff --git a/include/binsparse/binsparse.hpp b/include/binsparse/binsparse.hpp index 4fa04d2..2138645 100644 --- a/include/binsparse/binsparse.hpp +++ b/include/binsparse/binsparse.hpp @@ -13,7 +13,7 @@ namespace binsparse { -inline constexpr double version = 0.1; +inline const std::string version = "0.1"; template void write_dense_vector(H5::Group& f, std::span v, @@ -25,7 +25,7 @@ void write_dense_vector(H5::Group& f, std::span v, j["binsparse"]["version"] = version; j["binsparse"]["format"] = "DVEC"; j["binsparse"]["shape"] = {v.size()}; - j["binsparse"]["nnz"] = v.size(); + j["binsparse"]["number_of_stored_values"] = v.size(); j["binsparse"]["data_types"]["values"] = type_info::label(); for (auto&& v : user_keys.items()) { @@ -51,7 +51,7 @@ auto read_dense_vector(std::string fname, Allocator&& alloc = Allocator{}) { assert(format == "DVEC"); auto nvalues = binsparse_metadata["shape"][0]; - auto nnz = binsparse_metadata["nnz"]; + auto nnz = binsparse_metadata["number_of_stored_values"]; assert(nvalues == nnz); @@ -76,8 +76,14 @@ void write_dense_matrix(H5::Group& f, dense_matrix m, j["binsparse"]["version"] = version; j["binsparse"]["format"] = __detail::get_matrix_format_string(m); j["binsparse"]["shape"] = {m.m, m.n}; - j["binsparse"]["nnz"] = m.m * m.n; - j["binsparse"]["data_types"]["values"] = type_info::label(); + j["binsparse"]["number_of_stored_values"] = m.m * m.n; + + if (!m.is_iso) { + j["binsparse"]["data_types"]["values"] = + std::string("iso[") + type_info::label() + "]"; + } else { + j["binsparse"]["data_types"]["values"] = type_info::label(); + } if (m.structure != general) { j["binsparse"]["structure"] = @@ -118,7 +124,13 @@ auto read_dense_matrix(std::string fname, Allocator&& alloc = Allocator{}) { auto nrows = binsparse_metadata["shape"][0]; auto ncols = binsparse_metadata["shape"][1]; - auto nnz = binsparse_metadata["nnz"]; + auto nnz = binsparse_metadata["number_of_stored_values"]; + + bool is_iso = false; + if (std::string(binsparse_metadata["data_types"]["values"]) + .starts_with("iso")) { + is_iso = true; + } auto values = hdf5_tools::read_dataset(f, "values", alloc); @@ -128,7 +140,8 @@ auto read_dense_matrix(std::string fname, Allocator&& alloc = Allocator{}) { structure = __detail::parse_structure(binsparse_metadata["structure"]); } - return dense_matrix{values.data(), nrows, ncols, structure}; + return dense_matrix{values.data(), nrows, ncols, structure, + is_iso}; } // CSR Format @@ -149,10 +162,16 @@ void write_csr_matrix(H5::Group& f, csr_matrix m, j["binsparse"]["version"] = version; j["binsparse"]["format"] = "CSR"; j["binsparse"]["shape"] = {m.m, m.n}; - j["binsparse"]["nnz"] = m.nnz; + j["binsparse"]["number_of_stored_values"] = m.nnz; j["binsparse"]["data_types"]["pointers_to_1"] = type_info::label(); j["binsparse"]["data_types"]["indices_1"] = type_info::label(); - j["binsparse"]["data_types"]["values"] = type_info::label(); + + if (!m.is_iso) { + j["binsparse"]["data_types"]["values"] = + std::string("iso[") + type_info::label() + "]"; + } else { + j["binsparse"]["data_types"]["values"] = type_info::label(); + } if (m.structure != general) { j["binsparse"]["structure"] = @@ -189,7 +208,13 @@ csr_matrix read_csr_matrix(std::string fname, Allocator&& alloc) { auto nrows = binsparse_metadata["shape"][0]; auto ncols = binsparse_metadata["shape"][1]; - auto nnz = binsparse_metadata["nnz"]; + auto nnz = binsparse_metadata["number_of_stored_values"]; + + bool is_iso = false; + if (std::string(binsparse_metadata["data_types"]["values"]) + .starts_with("iso")) { + is_iso = true; + } typename std::allocator_traits< std::remove_cvref_t>::template rebind_alloc @@ -206,7 +231,7 @@ csr_matrix read_csr_matrix(std::string fname, Allocator&& alloc) { } return csr_matrix{values.data(), colind.data(), row_ptr.data(), nrows, - ncols, nnz, structure}; + ncols, nnz, structure, is_iso}; } template @@ -232,10 +257,16 @@ void write_csc_matrix(H5::Group& f, csc_matrix m, j["binsparse"]["version"] = version; j["binsparse"]["format"] = "CSR"; j["binsparse"]["shape"] = {m.m, m.n}; - j["binsparse"]["nnz"] = m.nnz; + j["binsparse"]["number_of_stored_values"] = m.nnz; j["binsparse"]["data_types"]["pointers_to_1"] = type_info::label(); j["binsparse"]["data_types"]["indices_1"] = type_info::label(); - j["binsparse"]["data_types"]["values"] = type_info::label(); + + if (!m.is_iso) { + j["binsparse"]["data_types"]["values"] = + std::string("iso[") + type_info::label() + "]"; + } else { + j["binsparse"]["data_types"]["values"] = type_info::label(); + } if (m.structure != general) { j["binsparse"]["structure"] = @@ -272,7 +303,13 @@ csc_matrix read_csc_matrix(std::string fname, Allocator&& alloc) { auto nrows = binsparse_metadata["shape"][0]; auto ncols = binsparse_metadata["shape"][1]; - auto nnz = binsparse_metadata["nnz"]; + auto nnz = binsparse_metadata["number_of_stored_values"]; + + bool is_iso = false; + if (std::string(binsparse_metadata["data_types"]["values"]) + .starts_with("iso")) { + is_iso = true; + } typename std::allocator_traits< std::remove_cvref_t>::template rebind_alloc @@ -289,7 +326,7 @@ csc_matrix read_csc_matrix(std::string fname, Allocator&& alloc) { } return csc_matrix{values.data(), rowind.data(), col_ptr.data(), nrows, - ncols, nnz, structure}; + ncols, nnz, structure, is_iso}; } template @@ -315,10 +352,16 @@ void write_coo_matrix(H5::Group& f, coo_matrix m, j["binsparse"]["version"] = version; j["binsparse"]["format"] = "COO"; j["binsparse"]["shape"] = {m.m, m.n}; - j["binsparse"]["nnz"] = m.nnz; + j["binsparse"]["number_of_stored_values"] = m.nnz; j["binsparse"]["data_types"]["indices_0"] = type_info::label(); j["binsparse"]["data_types"]["indices_1"] = type_info::label(); - j["binsparse"]["data_types"]["values"] = type_info::label(); + + if (!m.is_iso) { + j["binsparse"]["data_types"]["values"] = + std::string("iso[") + type_info::label() + "]"; + } else { + j["binsparse"]["data_types"]["values"] = type_info::label(); + } if (m.structure != general) { j["binsparse"]["structure"] = @@ -357,7 +400,13 @@ coo_matrix read_coo_matrix(std::string fname, Allocator&& alloc) { auto nrows = binsparse_metadata["shape"][0]; auto ncols = binsparse_metadata["shape"][1]; - auto nnz = binsparse_metadata["nnz"]; + auto nnz = binsparse_metadata["number_of_stored_values"]; + + bool is_iso = false; + if (std::string(binsparse_metadata["data_types"]["values"]) + .starts_with("iso")) { + is_iso = true; + } typename std::allocator_traits< std::remove_cvref_t>::template rebind_alloc @@ -374,7 +423,7 @@ coo_matrix read_coo_matrix(std::string fname, Allocator&& alloc) { } return coo_matrix{values.data(), rows.data(), cols.data(), nrows, - ncols, nnz, structure}; + ncols, nnz, structure, is_iso}; } template diff --git a/include/binsparse/containers/matrices.hpp b/include/binsparse/containers/matrices.hpp index dd7f38c..0b9c1d6 100644 --- a/include/binsparse/containers/matrices.hpp +++ b/include/binsparse/containers/matrices.hpp @@ -34,6 +34,7 @@ struct csr_matrix { I m, n, nnz; structure_t structure = general; + bool is_iso = false; }; template @@ -44,6 +45,7 @@ struct csc_matrix { I m, n, nnz; structure_t structure = general; + bool is_iso = false; }; template @@ -54,6 +56,7 @@ struct coo_matrix { I m, n, nnz; structure_t structure = general; + bool is_iso = false; }; template @@ -64,6 +67,7 @@ struct dense_matrix { structure_t structure = general; using order = Order; + bool is_iso = false; }; } // namespace binsparse