tatami_hdf5
tatami bindings for HDF5-backed matrices
Loading...
Searching...
No Matches
load_dense_matrix.hpp
Go to the documentation of this file.
1#ifndef TATAMI_HDF5_LOAD_DENSE_MATRIX_HPP
2#define TATAMI_HDF5_LOAD_DENSE_MATRIX_HPP
3
4#include "H5Cpp.h"
5
6#include <string>
7
8#include "tatami/tatami.hpp"
9#include "utils.hpp"
10
17namespace tatami_hdf5 {
18
37template<typename Value_, typename Index_, class ValueStorage_ = std::vector<Value_> >
38std::shared_ptr<tatami::Matrix<Value_, Index_> > load_dense_matrix(const std::string& file, const std::string& name, bool transpose) {
39 H5::H5File fhandle(file, H5F_ACC_RDONLY);
40 auto dhandle = open_and_check_dataset<false>(fhandle, name);
41
42 auto dims = get_array_dimensions<2>(dhandle, name);
43 ValueStorage_ values(static_cast<size_t>(dims[0]) * static_cast<size_t>(dims[1])); // cast just in case hsize_t is something silly...
44 dhandle.read(values.data(), define_mem_type<tatami::ElementType<ValueStorage_> >());
45
46 if (transpose) {
47 return std::make_shared<tatami::DenseMatrix<Value_, Index_, ValueStorage_> >(dims[1], dims[0], std::move(values), false);
48 } else {
49 return std::make_shared<tatami::DenseMatrix<Value_, Index_, ValueStorage_> >(dims[0], dims[1], std::move(values), true);
50 }
51}
52
53}
54
55#endif
Representations for matrix data in HDF5 files.
Definition CompressedSparseMatrix.hpp:23
std::shared_ptr< tatami::Matrix< Value_, Index_ > > load_dense_matrix(const std::string &file, const std::string &name, bool transpose)
Definition load_dense_matrix.hpp:38
typename std::remove_cv< typename std::remove_reference< decltype(std::declval< Array_ >()[0])>::type >::type ElementType
Utilities for HDF5 extraction.