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 "utils.hpp"
5
6#include <string>
7#include <vector>
8#include <memory>
9
10#include "H5Cpp.h"
11#include "tatami/tatami.hpp"
12#include "sanisizer/sanisizer.hpp"
13
20namespace tatami_hdf5 {
21
40template<typename Value_, typename Index_, class ValueStorage_ = std::vector<Value_> >
41std::shared_ptr<tatami::Matrix<Value_, Index_> > load_dense_matrix(const std::string& file, const std::string& name, bool transpose) {
42 H5::H5File fhandle(file, H5F_ACC_RDONLY);
43 auto dhandle = open_and_check_dataset<false>(fhandle, name);
44
45 auto dims = get_array_dimensions<2>(dhandle, name);
46 ValueStorage_ values(sanisizer::product<decltype(std::declval<ValueStorage_>().size())>(dims[0], dims[1]));
47 dhandle.read(values.data(), define_mem_type<tatami::ElementType<ValueStorage_> >());
48
49 if (transpose) {
50 return std::make_shared<tatami::DenseMatrix<Value_, Index_, ValueStorage_> >(dims[1], dims[0], std::move(values), false);
51 } else {
52 return std::make_shared<tatami::DenseMatrix<Value_, Index_, ValueStorage_> >(dims[0], dims[1], std::move(values), true);
53 }
54}
55
56}
57
58#endif
Representations for matrix data in HDF5 files.
Definition CompressedSparseMatrix.hpp:24
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:41
typename std::remove_cv< typename std::remove_reference< decltype(std::declval< Array_ >()[0])>::type >::type ElementType
Utilities for HDF5 extraction.