44template<
typename Value_,
typename Index_,
class ValueStorage_ = std::vector<Value_>,
class IndexStorage_ = std::vector<Index_>,
class Po
interStorage_ = std::vector<
size_t> >
48 const std::string& file,
49 const std::string& vals,
50 const std::string& idx,
51 const std::string& ptr,
54 H5::H5File file_handle(file, H5F_ACC_RDONLY);
56 auto dhandle = open_and_check_dataset<false>(file_handle, vals);
57 const size_t nonzeros = get_array_dimensions<1>(dhandle,
"vals")[0];
59 ValueStorage_ x(nonzeros);
62 auto ihandle = open_and_check_dataset<true>(file_handle, idx);
63 if (get_array_dimensions<1>(ihandle,
"idx")[0] != nonzeros) {
64 throw std::runtime_error(
"number of non-zero elements is not consistent between 'data' and 'idx'");
66 IndexStorage_ i(nonzeros);
69 auto phandle = open_and_check_dataset<true>(file_handle, ptr);
70 const size_t ptr_size = get_array_dimensions<1>(phandle,
"ptr")[0];
71 if (ptr_size != (row ? nr : nc) + 1) {
72 throw std::runtime_error(
"'ptr' dataset should have length equal to the number of " + (row ? std::string(
"rows") : std::string(
"columns")) +
" plus 1");
76 PointerStorage_ p(ptr_size);
77 if constexpr(std::is_same<size_t, tatami::ElementType<PointerStorage_> >::value) {
78 if constexpr(std::is_same<size_t, hsize_t>::value) {
79 phandle.read(p.data(), H5::PredType::NATIVE_HSIZE);
81 std::vector<hsize_t> p0(ptr_size);
82 phandle.read(p0.data(), H5::PredType::NATIVE_HSIZE);
83 std::copy(p0.begin(), p0.end(), p.begin());
89 return std::make_shared<tatami::CompressedSparseMatrix<Value_, Index_, ValueStorage_, IndexStorage_, PointerStorage_> >(nr, nc, std::move(x), std::move(i), std::move(p), row);
std::shared_ptr< tatami::Matrix< Value_, Index_ > > load_compressed_sparse_matrix(size_t nr, size_t nc, const std::string &file, const std::string &vals, const std::string &idx, const std::string &ptr, bool row)
Definition load_compressed_sparse_matrix.hpp:45