Skip to content

Commit 5eda04e

Browse files
committed
Implement test for COO
1 parent 865a8cd commit 5eda04e

File tree

4 files changed

+48
-3
lines changed

4 files changed

+48
-3
lines changed

include/binsparse/binsparse.hpp

-2
Original file line numberDiff line numberDiff line change
@@ -294,5 +294,3 @@ inline auto inspect(std::string fname) {
294294
}
295295

296296
} // end binsparse
297-
298-
#include <binsparse/c_bindings/bc_read_matrix.hpp>

include/binsparse/matrix_market/matrix_market_inspector.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace binsparse {
1414
// 2 - number of values in matrix
1515
// 3 - type of the matrix (real / integer / complex / pattern)
1616
// 4 - comments
17-
auto mmread_metadata(std::string file_path) {
17+
inline auto mmread_metadata(std::string file_path) {
1818
std::string type;
1919

2020
std::ifstream f;

test/gtest/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ enable_testing()
2020
add_executable(
2121
binsparse-tests
2222
csr_test.cpp
23+
coo_test.cpp
2324
)
2425

2526
target_link_libraries(binsparse-tests binsparse fmt GTest::gtest_main)

test/gtest/coo_test.cpp

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#include <gtest/gtest.h>
2+
3+
#include <fmt/core.h>
4+
5+
#include <binsparse/binsparse.hpp>
6+
7+
inline std::vector file_paths({"1138_bus/1138_bus.mtx",
8+
"chesapeake/chesapeake.mtx",
9+
"mouse_gene/mouse_gene.mtx"});
10+
11+
TEST(BinsparseReadWrite, COOFormat) {
12+
using T = float;
13+
using I = std::size_t;
14+
15+
std::string binsparse_file = "out.bsp.hdf5";
16+
17+
for (auto&& file_path : file_paths) {
18+
auto x = binsparse::__detail::mmread<T, I, binsparse::__detail::coo_matrix_owning<T, I>>(file_path);
19+
20+
auto&& [num_rows, num_columns] = x.shape();
21+
binsparse::coo_matrix<T, I> matrix{x.values().data(), x.rowind().data(), x.colind().data(), num_rows, num_columns, I(x.size())};
22+
binsparse::write_coo_matrix(binsparse_file, matrix);
23+
24+
auto matrix_ = binsparse::read_coo_matrix<T, I>(binsparse_file);
25+
26+
EXPECT_EQ(matrix.nnz, matrix_.nnz);
27+
EXPECT_EQ(matrix.m, matrix_.m);
28+
EXPECT_EQ(matrix.n, matrix_.n);
29+
30+
for (I i = 0; i < matrix.nnz; i++) {
31+
EXPECT_EQ(matrix.values[i], matrix_.values[i]);
32+
}
33+
34+
for (I i = 0; i < matrix.nnz; i++) {
35+
EXPECT_EQ(matrix.rowind[i], matrix_.rowind[i]);
36+
}
37+
38+
for (I i = 0; i < matrix.nnz; i++) {
39+
EXPECT_EQ(matrix.colind[i], matrix_.colind[i]);
40+
}
41+
42+
delete matrix_.values;
43+
delete matrix_.rowind;
44+
delete matrix_.colind;
45+
}
46+
}

0 commit comments

Comments
 (0)