47template<
typename Value_,
typename Index_,
class ValueStorage_ = std::vector<Value_>,
class IndexStorage_ = std::vector<Index_>,
class Po
interStorage_ = std::vector<std::
size_t> >
51 const std::string& file,
52 const std::string& vals,
53 const std::string& idx,
54 const std::string& ptr,
57 H5::H5File file_handle(file, H5F_ACC_RDONLY);
59 auto dhandle = open_and_check_dataset<false>(file_handle, vals);
60 auto nonzeros = get_array_dimensions<1>(dhandle,
"vals")[0];
62 auto x = sanisizer::create<ValueStorage_>(nonzeros);
65 auto ihandle = open_and_check_dataset<true>(file_handle, idx);
66 if (get_array_dimensions<1>(ihandle,
"idx")[0] != nonzeros) {
67 throw std::runtime_error(
"number of non-zero elements is not consistent between 'data' and 'idx'");
69 auto i = sanisizer::create<IndexStorage_>(nonzeros);
72 auto phandle = open_and_check_dataset<true>(file_handle, ptr);
73 auto ptr_size = get_array_dimensions<1>(phandle,
"ptr")[0];
74 if (ptr_size == 0 || !sanisizer::is_equal(ptr_size - 1, row ? nr : nc)) {
75 throw std::runtime_error(
"'ptr' dataset should have length equal to the number of " + (row ? std::string(
"rows") : std::string(
"columns")) +
" plus 1");
79 auto p = sanisizer::create<PointerStorage_>(ptr_size);
80 if constexpr(std::is_same<std::size_t, tatami::ElementType<PointerStorage_> >::value) {
81 if constexpr(std::is_same<std::size_t, hsize_t>::value) {
82 phandle.read(p.data(), H5::PredType::NATIVE_HSIZE);
84 std::vector<hsize_t> p0(ptr_size);
85 phandle.read(p0.data(), H5::PredType::NATIVE_HSIZE);
86 std::copy(p0.begin(), p0.end(), p.begin());
92 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(Index_ nr, Index_ 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:48