-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcsr_test.cpp
More file actions
50 lines (38 loc) · 1.4 KB
/
csr_test.cpp
File metadata and controls
50 lines (38 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include "util.hpp"
#include <binsparse/binsparse.hpp>
#include <filesystem>
#include <fmt/core.h>
#include <gtest/gtest.h>
TEST(BinsparseReadWrite, CSRFormat) {
using T = float;
using I = std::size_t;
std::string binsparse_file = "out.bsp.hdf5";
auto base_path = find_prefix(files.front());
for (auto&& file : files) {
auto file_path = base_path + file;
auto x = binsparse::__detail::mmread<
T, I, binsparse::__detail::csr_matrix_owning<T, I>>(file_path);
auto&& [num_rows, num_columns] = x.shape();
binsparse::csr_matrix<T, I> matrix{x.values().data(), x.colind().data(),
x.rowptr().data(), num_rows,
num_columns, I(x.size())};
binsparse::write_csr_matrix(binsparse_file, matrix);
auto matrix_ = binsparse::read_csr_matrix<T, I>(binsparse_file);
EXPECT_EQ(matrix.nnz, matrix_.nnz);
EXPECT_EQ(matrix.m, matrix_.m);
EXPECT_EQ(matrix.n, matrix_.n);
for (I i = 0; i < matrix.nnz; i++) {
EXPECT_EQ(matrix.values[i], matrix_.values[i]);
}
for (I i = 0; i < matrix.nnz; i++) {
EXPECT_EQ(matrix.colind[i], matrix_.colind[i]);
}
for (I i = 0; i < matrix.m + 1; i++) {
EXPECT_EQ(matrix.row_ptr[i], matrix_.row_ptr[i]);
}
delete matrix_.values;
delete matrix_.row_ptr;
delete matrix_.colind;
}
std::filesystem::remove(binsparse_file);
}