From 8ee376b43de3bf9bccc0be1a9a63aed397c7c5f6 Mon Sep 17 00:00:00 2001 From: Aaron Lun Date: Tue, 14 May 2024 22:42:56 -0700 Subject: [PATCH] Renamed classes and functions for more consistency, less redundancy. (#21) This removes the "hdf5" component in the class and function names. It should be obvious that we're dealing with HDF5 given that we're in the tatami_hdf5 namespace, so I don't see the need to repeat it. Also clarified that the sparse readers/writers are operating on compressed sparse matrices. The various *Options and *Parameters classes now follow the format of "Options". We use different Options classes for dense and sparse matrix constructors to future-proof for class-specific parameters. The nested enums have been moved out of the WriteSparseMatrixParameters class, mostly for easier writing by callers (the fully namespaced name is pretty long) but also to potentially allow re-use in a future dense matrix writer. Also removed the Stored class in favor of tatami::ElementType. --- docs/Doxyfile | 3 +- ...eMatrix.hpp => CompressedSparseMatrix.hpp} | 64 ++++--- .../{Hdf5DenseMatrix.hpp => DenseMatrix.hpp} | 56 ++++-- .../load_compressed_sparse_matrix.hpp | 94 ++++++++++ include/tatami_hdf5/load_dense_matrix.hpp | 55 ++++++ include/tatami_hdf5/load_hdf5_matrix.hpp | 152 ---------------- include/tatami_hdf5/sparse_primary.hpp | 5 +- include/tatami_hdf5/sparse_secondary.hpp | 7 +- include/tatami_hdf5/tatami_hdf5.hpp | 9 +- include/tatami_hdf5/utils.hpp | 33 +--- ...hpp => write_compressed_sparse_matrix.hpp} | 84 ++++----- tests/CMakeLists.txt | 9 +- ...eMatrix.cpp => CompressedSparseMatrix.cpp} | 123 +++++++------ .../{Hdf5DenseMatrix.cpp => DenseMatrix.cpp} | 76 ++++---- ....cpp => load_compressed_sparse_matrix.cpp} | 65 +------ tests/src/load_dense_matrix.cpp | 57 ++++++ ...cpp => write_compressed_sparse_matrix.cpp} | 162 +++++++++--------- 17 files changed, 538 insertions(+), 516 deletions(-) rename include/tatami_hdf5/{Hdf5CompressedSparseMatrix.hpp => CompressedSparseMatrix.hpp} (82%) rename include/tatami_hdf5/{Hdf5DenseMatrix.hpp => DenseMatrix.hpp} (92%) create mode 100644 include/tatami_hdf5/load_compressed_sparse_matrix.hpp create mode 100644 include/tatami_hdf5/load_dense_matrix.hpp delete mode 100644 include/tatami_hdf5/load_hdf5_matrix.hpp rename include/tatami_hdf5/{write_sparse_matrix_to_hdf5.hpp => write_compressed_sparse_matrix.hpp} (83%) rename tests/src/{Hdf5CompressedSparseMatrix.cpp => CompressedSparseMatrix.cpp} (85%) rename tests/src/{Hdf5DenseMatrix.cpp => DenseMatrix.cpp} (81%) rename tests/src/{load_hdf5_matrix.cpp => load_compressed_sparse_matrix.cpp} (55%) create mode 100644 tests/src/load_dense_matrix.cpp rename tests/src/{write_sparse_matrix_to_hdf5.cpp => write_compressed_sparse_matrix.cpp} (57%) diff --git a/docs/Doxyfile b/docs/Doxyfile index 84587ea..0a31cf3 100644 --- a/docs/Doxyfile +++ b/docs/Doxyfile @@ -873,7 +873,8 @@ RECURSIVE = YES # Note that relative paths are relative to the directory from which doxygen is # run. -EXCLUDE = +EXCLUDE = ../include/tatami_hdf5/sparse_primary.hpp \ + ../include/tatami_hdf5/sparse_secondary.hpp # The EXCLUDE_SYMLINKS tag can be used to select whether or not files or # directories that are symbolic links (a Unix file system feature) are excluded diff --git a/include/tatami_hdf5/Hdf5CompressedSparseMatrix.hpp b/include/tatami_hdf5/CompressedSparseMatrix.hpp similarity index 82% rename from include/tatami_hdf5/Hdf5CompressedSparseMatrix.hpp rename to include/tatami_hdf5/CompressedSparseMatrix.hpp index 6995d6d..e2852f9 100644 --- a/include/tatami_hdf5/Hdf5CompressedSparseMatrix.hpp +++ b/include/tatami_hdf5/CompressedSparseMatrix.hpp @@ -5,9 +5,7 @@ #include #include -#include #include -#include #include "tatami/tatami.hpp" @@ -17,13 +15,29 @@ #include "utils.hpp" /** - * @file Hdf5CompressedSparseMatrix.hpp + * @file CompressedSparseMatrix.hpp * * @brief Defines a class for a HDF5-backed compressed sparse matrix. */ namespace tatami_hdf5 { +/** + * @brief Options for HDF5 extraction. + */ +struct CompressedSparseMatrixOptions { + /** + * Size of the in-memory cache in bytes. + * + * We cache all chunks required to read a row/column in `tatami::MyopicDenseExtractor::fetch()` and related methods. + * This allows us to re-use the cached chunks when adjacent rows/columns are requested, rather than re-reading them from disk. + * + * Larger caches improve access speed at the cost of memory usage. + * Small values may be ignored as `CompressedSparseMatrix` will always allocate enough to cache a single element of the target dimension. + */ + size_t maximum_cache_size = 100000000; +}; + /** * @brief Compressed sparse matrix in a HDF5 file. * @@ -31,7 +45,8 @@ namespace tatami_hdf5 { * This allows us to handle very large datasets in limited memory at the cost of speed. * * We manually handle the chunk caching to speed up access for consecutive rows or columns (for compressed sparse row and column matrices, respectively). - * The policy is to minimize the number of calls to the HDF5 library - and thus expensive file reads - by requesting large contiguous slices where possible, i.e., multiple columns or rows for CSC and CSR matrices, respectively. + * The policy is to minimize the number of calls to the HDF5 library - and thus expensive file reads - by requesting large contiguous slices where possible, + * i.e., multiple columns or rows for CSC and CSR matrices, respectively. * These are held in memory in the `Extractor` while the relevant column/row is returned to the user by `row()` or `column()`. * The size of the slice is determined by the `options` in the constructor. * @@ -53,7 +68,7 @@ namespace tatami_hdf5 { * if a smaller type is known to be able to store all indices (based on their HDF5 type or other knowledge). */ template -class Hdf5CompressedSparseMatrix : public tatami::Matrix { +class CompressedSparseMatrix : public tatami::Matrix { Index_ nrows, ncols; std::string file_name; std::string data_name, index_name; @@ -76,10 +91,11 @@ class Hdf5CompressedSparseMatrix : public tatami::Matrix { * If `row = true`, this should contain column indices sorted within each row, otherwise it should contain row indices sorted within each column. * @param ptr Name of the 1D dataset inside `file` containing the index pointers for the start and end of each row (if `row = true`) or column (otherwise). * This should have length equal to the number of rows (if `row = true`) or columns (otherwise). - * @param row Whether the matrix is stored in compressed sparse row format. + * @param row Whether the matrix is stored on disk in compressed sparse row format. + * If false, the matrix is assumed to be stored in compressed sparse column format. * @param options Further options. */ - Hdf5CompressedSparseMatrix(Index_ nr, Index_ nc, std::string file, std::string vals, std::string idx, std::string ptr, bool row, const Hdf5Options& options) : + CompressedSparseMatrix(Index_ nr, Index_ nc, std::string file, std::string vals, std::string idx, std::string ptr, bool row, const CompressedSparseMatrixOptions& options) : nrows(nr), ncols(nc), file_name(std::move(file)), @@ -164,7 +180,7 @@ class Hdf5CompressedSparseMatrix : public tatami::Matrix { } /** - * Overload that uses the defaults for `Hdf5Options`. + * Overload that uses the default `CompressedSparseMatrixOptions`. * @param nr Number of rows in the matrix. * @param nc Number of columns in the matrix. * @param file Path to the file. @@ -175,8 +191,8 @@ class Hdf5CompressedSparseMatrix : public tatami::Matrix { * This should have length equal to the number of rows (if `row = true`) or columns (otherwise). * @param row Whether the matrix is stored in compressed sparse row format. */ - Hdf5CompressedSparseMatrix(Index_ nr, Index_ nc, std::string file, std::string vals, std::string idx, std::string ptr, bool row) : - Hdf5CompressedSparseMatrix(nr, nc, std::move(file), std::move(vals), std::move(idx), std::move(ptr), row, Hdf5Options()) {} + CompressedSparseMatrix(Index_ nr, Index_ nc, std::string file, std::string vals, std::string idx, std::string ptr, bool row) : + CompressedSparseMatrix(nr, nc, std::move(file), std::move(vals), std::move(idx), std::move(ptr), row, CompressedSparseMatrixOptions()) {} public: Index_ nrow() const { @@ -219,8 +235,8 @@ class Hdf5CompressedSparseMatrix : public tatami::Matrix { ************ Myopic dense ************ **************************************/ private: - Hdf5CompressedSparseMatrix_internal::MatrixDetails details() const { - return Hdf5CompressedSparseMatrix_internal::MatrixDetails( + CompressedSparseMatrix_internal::MatrixDetails details() const { + return CompressedSparseMatrix_internal::MatrixDetails( file_name, data_name, index_name, @@ -236,11 +252,11 @@ class Hdf5CompressedSparseMatrix : public tatami::Matrix { template std::unique_ptr > populate_dense(bool row, tatami::MaybeOracle oracle, const tatami::Options&) const { if (row == csr) { - return std::make_unique >( + return std::make_unique >( details(), std::move(oracle) ); } else { - return std::make_unique >( + return std::make_unique >( details(), std::move(oracle) ); } @@ -249,11 +265,11 @@ class Hdf5CompressedSparseMatrix : public tatami::Matrix { template std::unique_ptr > populate_dense(bool row, tatami::MaybeOracle oracle, Index_ block_start, Index_ block_length, const tatami::Options&) const { if (row == csr) { - return std::make_unique >( + return std::make_unique >( details(), std::move(oracle), block_start, block_length ); } else { - return std::make_unique >( + return std::make_unique >( details(), std::move(oracle), block_start, block_length ); } @@ -262,11 +278,11 @@ class Hdf5CompressedSparseMatrix : public tatami::Matrix { template std::unique_ptr > populate_dense(bool row, tatami::MaybeOracle oracle, tatami::VectorPtr indices_ptr, const tatami::Options&) const { if (row == csr) { - return std::make_unique >( + return std::make_unique >( details(), std::move(oracle), std::move(indices_ptr) ); } else { - return std::make_unique >( + return std::make_unique >( details(), std::move(oracle), std::move(indices_ptr) ); } @@ -292,11 +308,11 @@ class Hdf5CompressedSparseMatrix : public tatami::Matrix { template std::unique_ptr > populate_sparse(bool row, tatami::MaybeOracle oracle, const tatami::Options& opt) const { if (row == csr) { - return std::make_unique >( + return std::make_unique >( details(), std::move(oracle), opt.sparse_extract_value, opt.sparse_extract_index ); } else { - return std::make_unique >( + return std::make_unique >( details(), std::move(oracle), opt.sparse_extract_value, opt.sparse_extract_index ); } @@ -305,11 +321,11 @@ class Hdf5CompressedSparseMatrix : public tatami::Matrix { template std::unique_ptr > populate_sparse(bool row, tatami::MaybeOracle oracle, Index_ block_start, Index_ block_length, const tatami::Options& opt) const { if (row == csr) { - return std::make_unique >( + return std::make_unique >( details(), std::move(oracle), block_start, block_length, opt.sparse_extract_value, opt.sparse_extract_index ); } else { - return std::make_unique >( + return std::make_unique >( details(), std::move(oracle), block_start, block_length, opt.sparse_extract_value, opt.sparse_extract_index ); } @@ -318,11 +334,11 @@ class Hdf5CompressedSparseMatrix : public tatami::Matrix { template std::unique_ptr > populate_sparse(bool row, tatami::MaybeOracle oracle, tatami::VectorPtr indices_ptr, const tatami::Options& opt) const { if (row == csr) { - return std::make_unique >( + return std::make_unique >( details(), std::move(oracle), std::move(indices_ptr), opt.sparse_extract_value, opt.sparse_extract_index ); } else { - return std::make_unique >( + return std::make_unique >( details(), std::move(oracle), std::move(indices_ptr), opt.sparse_extract_value, opt.sparse_extract_index ); } diff --git a/include/tatami_hdf5/Hdf5DenseMatrix.hpp b/include/tatami_hdf5/DenseMatrix.hpp similarity index 92% rename from include/tatami_hdf5/Hdf5DenseMatrix.hpp rename to include/tatami_hdf5/DenseMatrix.hpp index ac28e61..dd1a113 100644 --- a/include/tatami_hdf5/Hdf5DenseMatrix.hpp +++ b/include/tatami_hdf5/DenseMatrix.hpp @@ -4,10 +4,8 @@ #include "H5Cpp.h" #include -#include #include #include -#include #include #include "serialize.hpp" @@ -15,17 +13,40 @@ #include "tatami_chunked/tatami_chunked.hpp" /** - * @file Hdf5DenseMatrix.hpp + * @file DenseMatrix.hpp * * @brief Defines a class for a HDF5-backed dense matrix. */ namespace tatami_hdf5 { +/** + * @brief Options for `DenseMatrix` extraction. + */ +struct DenseMatrixOptions { + /** + * Size of the in-memory cache in bytes. + * + * We cache all chunks required to read a row/column in `tatami::MyopicDenseExtractor::fetch()` and related methods. + * This allows us to re-use the cached chunks when adjacent rows/columns are requested, rather than re-reading them from disk. + * + * Larger caches improve access speed at the cost of memory usage. + * Small values may be ignored if `require_minimum_cache` is `true`. + */ + size_t maximum_cache_size = 100000000; + + /** + * Whether to automatically enforce a minimum size for the cache, regardless of `maximum_cache_size`. + * This minimum is chosen to ensure that all chunks overlapping one row (or a slice/subset thereof) can be retained in memory, + * so that the same chunks are not repeatedly re-read from disk when iterating over consecutive rows/columns of the matrix. + */ + bool require_minimum_cache = true; +}; + /** * @cond */ -namespace Hdf5DenseMatrix_internal { +namespace DenseMatrix_internal { // All HDF5-related members. struct Components { @@ -509,7 +530,7 @@ struct Index : public DenseBase -class Hdf5DenseMatrix : public tatami::Matrix { +class DenseMatrix : public tatami::Matrix { std::string file_name, dataset_name; bool transpose; @@ -524,9 +545,11 @@ class Hdf5DenseMatrix : public tatami::Matrix { * @param file Path to the file. * @param name Path to the dataset inside the file. * @param transpose Whether the dataset is transposed in its storage order, i.e., rows in the HDF5 dataset correspond to columns of this matrix. - * @param options Further options. + * This may be true for HDF5 files generated by frameworks that use column-major matrices, + * where preserving the data layout between memory and disk is more efficient (see, e.g., the **rhdf5** Bioconductor package). + * @param options Further options for data extraction. */ - Hdf5DenseMatrix(std::string file, std::string name, bool transpose, const Hdf5Options& options) : + DenseMatrix(std::string file, std::string name, bool transpose, const DenseMatrixOptions& options) : file_name(std::move(file)), dataset_name(std::move(name)), transpose(transpose), @@ -561,12 +584,13 @@ class Hdf5DenseMatrix : public tatami::Matrix { } /** - * Overload that uses the defaults for `Hdf5Options`. + * Overload that uses the default `DenseMatrixOptions`. * @param file Path to the file. * @param name Path to the dataset inside the file. - * @param transpose Whether the dataset is transposed in its storage order, i.e., rows in the HDF5 dataset correspond to columns of this matrix. + * @param transpose Whether the dataset is transposed in its storage order. */ - Hdf5DenseMatrix(std::string file, std::string name, bool transpose) : Hdf5DenseMatrix(std::move(file), std::move(name), transpose, Hdf5Options()) {} + DenseMatrix(std::string file, std::string name, bool transpose) : + DenseMatrix(std::move(file), std::move(name), transpose, DenseMatrixOptions()) {} private: bool prefer_rows_internal() const { @@ -677,16 +701,16 @@ class Hdf5DenseMatrix : public tatami::Matrix { public: std::unique_ptr > dense(bool row, const tatami::Options&) const { Index_ full_non_target = (row ? ncol_internal() : nrow_internal()); - return populate(row, full_non_target, false, full_non_target); + return populate(row, full_non_target, false, full_non_target); } std::unique_ptr > dense(bool row, Index_ block_start, Index_ block_length, const tatami::Options&) const { - return populate(row, block_length, false, block_start, block_length); + return populate(row, block_length, false, block_start, block_length); } std::unique_ptr > dense(bool row, tatami::VectorPtr indices_ptr, const tatami::Options&) const { auto nidx = indices_ptr->size(); - return populate(row, nidx, false, std::move(indices_ptr)); + return populate(row, nidx, false, std::move(indices_ptr)); } /********************* @@ -717,7 +741,7 @@ class Hdf5DenseMatrix : public tatami::Matrix { const tatami::Options&) const { Index_ full_non_target = (row ? ncol_internal() : nrow_internal()); - return populate(row, full_non_target, std::move(oracle), full_non_target); + return populate(row, full_non_target, std::move(oracle), full_non_target); } std::unique_ptr > dense( @@ -727,7 +751,7 @@ class Hdf5DenseMatrix : public tatami::Matrix { Index_ block_length, const tatami::Options&) const { - return populate(row, block_length, std::move(oracle), block_start, block_length); + return populate(row, block_length, std::move(oracle), block_start, block_length); } std::unique_ptr > dense( @@ -737,7 +761,7 @@ class Hdf5DenseMatrix : public tatami::Matrix { const tatami::Options&) const { auto nidx = indices_ptr->size(); - return populate(row, nidx, std::move(oracle), std::move(indices_ptr)); + return populate(row, nidx, std::move(oracle), std::move(indices_ptr)); } /*********************** diff --git a/include/tatami_hdf5/load_compressed_sparse_matrix.hpp b/include/tatami_hdf5/load_compressed_sparse_matrix.hpp new file mode 100644 index 0000000..66689cd --- /dev/null +++ b/include/tatami_hdf5/load_compressed_sparse_matrix.hpp @@ -0,0 +1,94 @@ +#ifndef TATAMI_HDF5_LOAD_SPARSE_MATRIX_HPP +#define TATAMI_HDF5_LOAD_SPARSE_MATRIX_HPP + +#include "H5Cpp.h" + +#include + +#include "tatami/tatami.hpp" +#include "utils.hpp" + +/** + * @file load_compressed_sparse_matrix.hpp + * + * @brief Load a HDF5 group into a sparse in-memory matrix. + */ + +namespace tatami_hdf5 { + +/** + * Create a `tatami::CompressedSparseMatrix` from a HDF5 group containing compressed sparse data. + * + * @tparam Value_ Type of the matrix values in the `Matrix` interface. + * @tparam Index_ Type of the row/column indices. + * @tparam ValueStorage_ Vector type for storing the values of the non-zero elements. + * Elements of this vector may be of a different type than `Value_` for more efficient storage. + * @tparam IndexStorage_ Vector type for storing the indices. + * Elements of this vector may be of a different type than `Index_` for more efficient storage. + * @tparam PointerStorage_ Vector type for storing the index pointers. + * + * @param nr Number of rows in the matrix. + * @param nc Number of columns in the matrix. + * @param file Path to the file. + * @param vals Name of the 1D dataset inside `file` containing the non-zero elements. + * @param idx Name of the 1D dataset inside `file` containing the indices of the non-zero elements. + * If `row = true`, this should contain column indices sorted within each row, otherwise it should contain row indices sorted within each column. + * @param ptr Name of the 1D dataset inside `file` containing the index pointers for the start and end of each row (if `row = true`) or column (otherwise). + * This should have length equal to the number of rows (if `row = true`) or columns (otherwise) plus 1. + * @param row Whether the matrix is stored on disk in compressed sparse row format. + * If false, the matrix is assumed to be stored in compressed sparse column format. + * + * @return Pointer to a `tatami::CompressedSparseMatrix` containing all values and indices in memory. + * This differs from a `tatami_hdf5::CompressedSparseMatrix`, where the loading of data is deferred until requested. + */ +template, class IndexStorage_ = std::vector, class PointerStorage_ = std::vector > +std::shared_ptr > 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) +{ + H5::H5File file_handle(file, H5F_ACC_RDONLY); + + auto dhandle = open_and_check_dataset(file_handle, vals); + const size_t nonzeros = get_array_dimensions<1>(dhandle, "vals")[0]; + + ValueStorage_ x(nonzeros); + dhandle.read(x.data(), define_mem_type >()); + + auto ihandle = open_and_check_dataset(file_handle, idx); + if (get_array_dimensions<1>(ihandle, "idx")[0] != nonzeros) { + throw std::runtime_error("number of non-zero elements is not consistent between 'data' and 'idx'"); + } + IndexStorage_ i(nonzeros); + ihandle.read(i.data(), define_mem_type >()); + + auto phandle = open_and_check_dataset(file_handle, ptr); + const size_t ptr_size = get_array_dimensions<1>(phandle, "ptr")[0]; + if (ptr_size != (row ? nr : nc) + 1) { + throw std::runtime_error("'ptr' dataset should have length equal to the number of " + (row ? std::string("rows") : std::string("columns")) + " plus 1"); + } + + // Because HDF5 doesn't have a native type for size_t. + PointerStorage_ p(ptr_size); + if constexpr(std::is_same >::value) { + if constexpr(std::is_same::value) { + phandle.read(p.data(), H5::PredType::NATIVE_HSIZE); + } else { + std::vector p0(ptr_size); + phandle.read(p0.data(), H5::PredType::NATIVE_HSIZE); + std::copy(p0.begin(), p0.end(), p.begin()); + } + } else { + phandle.read(p.data(), define_mem_type >()); + } + + return std::make_shared >(nr, nc, std::move(x), std::move(i), std::move(p), row); +} + +} + +#endif diff --git a/include/tatami_hdf5/load_dense_matrix.hpp b/include/tatami_hdf5/load_dense_matrix.hpp new file mode 100644 index 0000000..74c2410 --- /dev/null +++ b/include/tatami_hdf5/load_dense_matrix.hpp @@ -0,0 +1,55 @@ +#ifndef TATAMI_HDF5_LOAD_DENSE_MATRIX_HPP +#define TATAMI_HDF5_LOAD_DENSE_MATRIX_HPP + +#include "H5Cpp.h" + +#include + +#include "tatami/tatami.hpp" +#include "utils.hpp" + +/** + * @file load_dense_matrix.hpp + * + * @brief Load a HDF5 dataset into a dense in-memory matrix. + */ + +namespace tatami_hdf5 { + +/** + * Create a `tatami::DenseMatrix` from a HDF5 DataSet. + * + * @tparam Value_ Type of the matrix values in the `tatami::Matrix` interface. + * @tparam Index_Type of the row/column indices. + * @tparam ValueStorage_ Vector type for storing the matrix values. + * This may be different from `Value_` for more efficient storage. + * + * @param file Path to the HDF5 file. + * @param name Name of the dataset inside the file. + * This should refer to a 2-dimensional dataset of integer or floating-point type. + * @param transpose Whether the dataset is transposed in its storage order, i.e., rows in HDF5 are columns in the matrix. + * This may be true for HDF5 files generated by frameworks that use column-major matrices, + * where preserving the data layout between memory and disk is more efficient (see, e.g., the **rhdf5** Bioconductor package). + * + * @return Pointer to a `tatami::DenseMatrix` where all values are in memory. + * This differs from a `tatami_hdf5::DenseMatrix`, where the loading of data is deferred until requested. + */ +template > +std::shared_ptr > load_dense_matrix(const std::string& file, const std::string& name, bool transpose) { + H5::H5File fhandle(file, H5F_ACC_RDONLY); + auto dhandle = open_and_check_dataset(fhandle, name); + + auto dims = get_array_dimensions<2>(dhandle, name); + ValueStorage_ values(static_cast(dims[0]) * static_cast(dims[1])); // cast just in case hsize_t is something silly... + dhandle.read(values.data(), define_mem_type >()); + + if (transpose) { + return std::make_shared >(dims[1], dims[0], std::move(values), false); + } else { + return std::make_shared >(dims[0], dims[1], std::move(values), true); + } +} + +} + +#endif diff --git a/include/tatami_hdf5/load_hdf5_matrix.hpp b/include/tatami_hdf5/load_hdf5_matrix.hpp deleted file mode 100644 index af1adf9..0000000 --- a/include/tatami_hdf5/load_hdf5_matrix.hpp +++ /dev/null @@ -1,152 +0,0 @@ -#ifndef TATAMI_LOAD_HDF5_MATRIX_HPP -#define TATAMI_LOAD_HDF5_MATRIX_HPP - -#include "H5Cpp.h" - -#include -#include -#include -#include - -#include "tatami/tatami.hpp" -#include "utils.hpp" - -/** - * @file load_hdf5_matrix.hpp - * - * @brief Load HDF5 data into `Matrix` objects. - */ - -namespace tatami_hdf5 { - -/** - * Load a `tatami::CompressedSparseMatrix` from a HDF5 file. - * - * @tparam Value_ Type of the matrix values in the `Matrix` interface. - * @tparam Index_ Type of the row/column indices. - * @tparam ValueStorage_ Vector type for storing the values of the non-zero elements. - * Elements of this vector may be of a different type than `T` for more efficient storage. - * @tparam IndexStorage_ Vector type for storing the indices. - * Elements of this vector may be of a different type than `IDX` for more efficient storage. - * @tparam PointerStorage_ Vector type for storing the index pointers. - * - * @param nr Number of rows in the matrix. - * @param nc Number of columns in the matrix. - * @param file Path to the file. - * @param vals Name of the 1D dataset inside `file` containing the non-zero elements. - * @param idx Name of the 1D dataset inside `file` containing the indices of the non-zero elements. - * If `row = true`, this should contain column indices sorted within each row, otherwise it should contain row indices sorted within each column. - * @param ptr Name of the 1D dataset inside `file` containing the index pointers for the start and end of each row (if `row = true`) or column (otherwise). - * This should have length equal to the number of rows (if `row = true`) or columns (otherwise) plus 1. - * @param row Whether the matrix is stored in compressed sparse row format. - * - * @return A `tatami::CompressedSparseMatrix` containing all values and indices in memory. - * This differs from a `Hdf5CompressedSparseMatrix`, where the loading of data is deferred until requested. - */ -template, class IndexStorage_ = std::vector, class PointerStorage_ = std::vector > -tatami::CompressedSparseMatrix load_hdf5_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) -{ - H5::H5File file_handle(file, H5F_ACC_RDONLY); - - auto dhandle = open_and_check_dataset(file_handle, vals); - const size_t nonzeros = get_array_dimensions<1>(dhandle, "vals")[0]; - - ValueStorage_ x(nonzeros); - dhandle.read(x.data(), define_mem_type >()); - - auto ihandle = open_and_check_dataset(file_handle, idx); - if (get_array_dimensions<1>(ihandle, "idx")[0] != nonzeros) { - throw std::runtime_error("number of non-zero elements is not consistent between 'data' and 'idx'"); - } - IndexStorage_ i(nonzeros); - ihandle.read(i.data(), define_mem_type >()); - - auto phandle = open_and_check_dataset(file_handle, ptr); - const size_t ptr_size = get_array_dimensions<1>(phandle, "ptr")[0]; - if (ptr_size != (row ? nr : nc) + 1) { - throw std::runtime_error("'ptr' dataset should have length equal to the number of " + (row ? std::string("rows") : std::string("columns")) + " plus 1"); - } - - // Because HDF5 doesn't have a native type for size_t. - PointerStorage_ p(ptr_size); - if constexpr(std::is_same >::value) { - if constexpr(std::is_same::value) { - phandle.read(p.data(), H5::PredType::NATIVE_HSIZE); - } else { - std::vector p0(ptr_size); - phandle.read(p0.data(), H5::PredType::NATIVE_HSIZE); - std::copy(p0.begin(), p0.end(), p.begin()); - } - } else { - phandle.read(p.data(), define_mem_type >()); - } - - return tatami::CompressedSparseMatrix(nr, nc, std::move(x), std::move(i), std::move(p), row); -} - -/** - * Load a `tatami::DenseMatrix` from a HDF5 DataSet. - * - * @tparam Value_ Type of the matrix values in the `Matrix` interface. - * @tparam Index_Type of the row/column indices. - * @tparam ValueStorage_ Vector type for storing the matrix values. - * This may be different from `T` for more efficient storage. - * - * @param file Path to the HDF5 file. - * @param name Name of the dataset inside the file. - * This should refer to a 2-dimensional dataset of integer or floating-point type. - * @param transpose Whether the dataset is transposed in its storage order, i.e., rows in HDF5 are columns in the matrix. - * - * @return A `tatami::DenseMatrix` where all values are in memory. - * This differs from a `Hdf5DenseMatrix`, where the loading of data is deferred until requested. - */ -template > -tatami::DenseMatrix load_hdf5_dense_matrix(const std::string& file, const std::string& name, bool transpose) { - H5::H5File fhandle(file, H5F_ACC_RDONLY); - auto dhandle = open_and_check_dataset(fhandle, name); - - auto dims = get_array_dimensions<2>(dhandle, name); - ValueStorage_ values(static_cast(dims[0]) * static_cast(dims[1])); // cast just in case hsize_t is something silly... - dhandle.read(values.data(), define_mem_type >()); - - if (transpose) { - return tatami::DenseMatrix(dims[1], dims[0], std::move(values), false); - } else { - return tatami::DenseMatrix(dims[0], dims[1], std::move(values), true); - } -} - -/** - * @cond - */ -// Back-compatibility. -template, class IndexStorage_ = std::vector, class PointerStorage_ = std::vector > -tatami::CompressedSparseMatrix load_hdf5_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) -{ - return load_hdf5_compressed_sparse_matrix(nr, nc, file, vals, idx, ptr, row_); -} - -template, bool transpose_ = false> -tatami::DenseMatrix load_hdf5_dense_matrix(const std::string& file, const std::string& name) { - return load_hdf5_dense_matrix(file, name, transpose_); -} -/** - * @endcond - */ - -} - -#endif diff --git a/include/tatami_hdf5/sparse_primary.hpp b/include/tatami_hdf5/sparse_primary.hpp index 546ab57..e550dc2 100644 --- a/include/tatami_hdf5/sparse_primary.hpp +++ b/include/tatami_hdf5/sparse_primary.hpp @@ -4,6 +4,7 @@ #include #include #include +#include #include "tatami/tatami.hpp" #include "tatami_chunked/tatami_chunked.hpp" @@ -13,7 +14,7 @@ namespace tatami_hdf5 { -namespace Hdf5CompressedSparseMatrix_internal { +namespace CompressedSparseMatrix_internal { /*************************** **** General utitities **** @@ -206,7 +207,7 @@ class PrimaryBase { // Using some kinda-big prime number as the number of slots. This // doesn't really matter too much as we only intend to store two - // chunks at most - see Hdf5CompressedSparseMatrix.hpp for the rationale. + // chunks at most - see CompressedSparseMatrix.hpp for the rationale. H5::FileAccPropList fapl(H5::FileAccPropList::DEFAULT.getId()); fapl.setCache(0, 511, details.h5_chunk_cache_size, 0); diff --git a/include/tatami_hdf5/sparse_secondary.hpp b/include/tatami_hdf5/sparse_secondary.hpp index 4dbcc77..6654fba 100644 --- a/include/tatami_hdf5/sparse_secondary.hpp +++ b/include/tatami_hdf5/sparse_secondary.hpp @@ -3,6 +3,7 @@ #include #include +#include #include "tatami/tatami.hpp" #include "tatami_chunked/tatami_chunked.hpp" @@ -13,7 +14,7 @@ namespace tatami_hdf5 { -namespace Hdf5CompressedSparseMatrix_internal { +namespace CompressedSparseMatrix_internal { template tatami::SparseRange slab_to_sparse(const tatami::SparseRange& slab, Value_* vbuffer, Index_* ibuffer) { @@ -52,7 +53,7 @@ struct SecondaryBase { // Using some kinda-big prime number as the number of slots. This // doesn't really matter too much as we only intend to store two - // chunks at most - see Hdf5CompressedSparseMatrix.hpp for the rationale. + // chunks at most - see CompressedSparseMatrix.hpp for the rationale. H5::FileAccPropList fapl(H5::FileAccPropList::DEFAULT.getId()); fapl.setCache(0, 511, details.h5_chunk_cache_size, 0); @@ -92,7 +93,7 @@ class MyopicSecondaryBase : public SecondaryBase { std::max( static_cast(1), // The general strategy here is to allocate a single giant slab based on what the 'cache_size' can afford. - static_cast(details.our_cache_size / (Hdf5CompressedSparseMatrix_internal::size_of_cached_element(needs_value, true) * extract_length)) + static_cast(details.our_cache_size / (CompressedSparseMatrix_internal::size_of_cached_element(needs_value, true) * extract_length)) ) ), extract_length(extract_length), diff --git a/include/tatami_hdf5/tatami_hdf5.hpp b/include/tatami_hdf5/tatami_hdf5.hpp index 968f483..ccbdf0b 100644 --- a/include/tatami_hdf5/tatami_hdf5.hpp +++ b/include/tatami_hdf5/tatami_hdf5.hpp @@ -12,9 +12,10 @@ */ namespace tatami_hdf5 {} -#include "Hdf5CompressedSparseMatrix.hpp" -#include "Hdf5DenseMatrix.hpp" -#include "load_hdf5_matrix.hpp" -#include "write_sparse_matrix_to_hdf5.hpp" +#include "CompressedSparseMatrix.hpp" +#include "DenseMatrix.hpp" +#include "load_dense_matrix.hpp" +#include "load_compressed_sparse_matrix.hpp" +#include "write_compressed_sparse_matrix.hpp" #endif diff --git a/include/tatami_hdf5/utils.hpp b/include/tatami_hdf5/utils.hpp index fd54e81..ba0e20f 100644 --- a/include/tatami_hdf5/utils.hpp +++ b/include/tatami_hdf5/utils.hpp @@ -19,37 +19,18 @@ namespace tatami_hdf5 { /** - * @brief Options for HDF5 extraction. + * Layout to use when saving the matrix inside the HDF5 group. */ -struct Hdf5Options { - /** - * Size of the in-memory cache in bytes. - * - * We cache all chunks required to read a row/column during a `tatami::DenseExtractor::fetch()` or `tatami::SparseExtractor::fetch()` call. - * This allows us to re-use the cached chunks when adjacent rows/columns are requested, rather than re-reading them from disk. - * - * Larger caches improve access speed at the cost of memory usage. - * Small values may be ignored if `require_minimum_cache` is `true`. - */ - size_t maximum_cache_size = 100000000; - - /** - * Whether to automatically enforce a minimum size for the cache, regardless of `maximum_cache_size`. - * This minimum is chosen to ensure that all chunks overlapping one row (or a slice/subset thereof) can be retained in memory, - * so that the same chunks are not repeatedly re-read from disk when iterating over consecutive rows/columns of the matrix. - * - * Note that this option is only relevant used for `Hdf5DenseMatrix` caching. - * The cache memory usage for compressed sparse matrices is less predictable, so we always require a minimal cache size in that case. - */ - bool require_minimum_cache = true; -}; +enum class WriteStorageLayout { AUTOMATIC, COLUMN, ROW }; /** - * @cond + * Numeric type for writing data into a HDF5 dataset. */ -template -using Stored = typename std::remove_reference()[0])>::type; +enum class WriteStorageType { AUTOMATIC, INT8, UINT8, INT16, UINT16, INT32, UINT32, DOUBLE }; +/** + * @cond + */ template const H5::PredType& define_mem_type() { if constexpr(std::is_same::value) { diff --git a/include/tatami_hdf5/write_sparse_matrix_to_hdf5.hpp b/include/tatami_hdf5/write_compressed_sparse_matrix.hpp similarity index 83% rename from include/tatami_hdf5/write_sparse_matrix_to_hdf5.hpp rename to include/tatami_hdf5/write_compressed_sparse_matrix.hpp index df25238..d0aa94f 100644 --- a/include/tatami_hdf5/write_sparse_matrix_to_hdf5.hpp +++ b/include/tatami_hdf5/write_compressed_sparse_matrix.hpp @@ -13,20 +13,20 @@ #include /** - * @file write_sparse_matrix_to_hdf5.hpp - * @brief Write a sparse matrix into a HDF5 file. + * @file write_compressed_sparse_matrix.hpp + * @brief Write a compressed sparse matrix into a HDF5 file. */ namespace tatami_hdf5 { /** - * @brief Parameters for `write_sparse_matrix_to_hdf5()`. + * @brief Parameters for `write_compressed_sparse_matrix()`. */ -struct WriteSparseMatrixToHdf5Parameters { +struct WriteCompressedSparseMatrixOptions { /** * @cond */ - WriteSparseMatrixToHdf5Parameters() : data_name("data"), index_name("indices"), ptr_name("indptr") {} + WriteCompressedSparseMatrixOptions() : data_name("data"), index_name("indices"), ptr_name("indptr") {} /** * @endcond */ @@ -49,27 +49,17 @@ struct WriteSparseMatrixToHdf5Parameters { */ std::string ptr_name; - /** - * Layout to use for saving the matrix inside the HDF5 group. - */ - enum class StorageLayout { AUTOMATIC, COLUMN, ROW }; - /** * Whether to save in the compressed sparse column layout. * If `false`, this is determined from the layout of the input matrix. */ - StorageLayout columnar = StorageLayout::AUTOMATIC; - - /** - * Numeric type for storage inside a HDF5 dataset. - */ - enum class StorageType { AUTOMATIC, INT8, UINT8, INT16, UINT16, INT32, UINT32, DOUBLE }; + WriteStorageLayout columnar = WriteStorageLayout::AUTOMATIC; /** * Storage type for the data values. * If `AUTOMATIC`, it is automatically determined from the range and integralness of the data in the input matrix. */ - StorageType data_type = StorageType::AUTOMATIC; + WriteStorageType data_type = WriteStorageType::AUTOMATIC; /** * Whether to force non-integer floating point values into an integer storage mode. @@ -83,7 +73,7 @@ struct WriteSparseMatrixToHdf5Parameters { * Storage type for the data values. * If `AUTOMATIC`, it is automatically determined from the range of the indices in the input matrix. */ - StorageType index_type = StorageType::AUTOMATIC; + WriteStorageType index_type = WriteStorageType::AUTOMATIC; /** * Compression level. @@ -122,28 +112,28 @@ inline H5::DataSet create_1d_compressed_hdf5_dataset(H5::Group& location, const return location.createDataSet(name, dtype, dspace, plist); } -inline H5::DataSet create_1d_compressed_hdf5_dataset(H5::Group& location, WriteSparseMatrixToHdf5Parameters::StorageType type, const std::string& name, hsize_t length, int deflate_level, hsize_t chunk) { +inline H5::DataSet create_1d_compressed_hdf5_dataset(H5::Group& location, WriteStorageType type, const std::string& name, hsize_t length, int deflate_level, hsize_t chunk) { const H5::PredType* dtype; switch (type) { - case WriteSparseMatrixToHdf5Parameters::StorageType::INT8: + case WriteStorageType::INT8: dtype = &(H5::PredType::NATIVE_INT8); break; - case WriteSparseMatrixToHdf5Parameters::StorageType::UINT8: + case WriteStorageType::UINT8: dtype = &(H5::PredType::NATIVE_UINT8); break; - case WriteSparseMatrixToHdf5Parameters::StorageType::INT16: + case WriteStorageType::INT16: dtype = &(H5::PredType::NATIVE_INT16); break; - case WriteSparseMatrixToHdf5Parameters::StorageType::UINT16: + case WriteStorageType::UINT16: dtype = &(H5::PredType::NATIVE_UINT16); break; - case WriteSparseMatrixToHdf5Parameters::StorageType::INT32: + case WriteStorageType::INT32: dtype = &(H5::PredType::NATIVE_INT32); break; - case WriteSparseMatrixToHdf5Parameters::StorageType::UINT32: + case WriteStorageType::UINT32: dtype = &(H5::PredType::NATIVE_UINT32); break; - case WriteSparseMatrixToHdf5Parameters::StorageType::DOUBLE: + case WriteStorageType::DOUBLE: dtype = &(H5::PredType::NATIVE_DOUBLE); break; default: @@ -315,35 +305,35 @@ WriteSparseHdf5Statistics write_sparse_hdf5_statistics(const tat * @param params Parameters to use when writing the matrix. */ template -void write_sparse_matrix_to_hdf5(const tatami::Matrix* mat, H5::Group& location, const WriteSparseMatrixToHdf5Parameters& params) { +void write_compressed_sparse_matrix(const tatami::Matrix* mat, H5::Group& location, const WriteCompressedSparseMatrixOptions& params) { auto data_type = params.data_type; auto index_type = params.index_type; - auto use_auto_data_type = (data_type == WriteSparseMatrixToHdf5Parameters::StorageType::AUTOMATIC); - auto use_auto_index_type = (index_type == WriteSparseMatrixToHdf5Parameters::StorageType::AUTOMATIC); + auto use_auto_data_type = (data_type == WriteStorageType::AUTOMATIC); + auto use_auto_index_type = (index_type == WriteStorageType::AUTOMATIC); auto stats = write_sparse_hdf5_statistics(mat, use_auto_data_type, use_auto_index_type, params.num_threads); // Choosing the types. if (use_auto_data_type) { if (stats.non_integer && !params.force_integer) { - data_type = WriteSparseMatrixToHdf5Parameters::StorageType::DOUBLE; + data_type = WriteStorageType::DOUBLE; } else { auto lower_data = stats.lower_data; auto upper_data = stats.upper_data; if (lower_data < 0) { if (fits_lower_limit(lower_data) && fits_upper_limit(upper_data)) { - data_type = WriteSparseMatrixToHdf5Parameters::StorageType::INT8; + data_type = WriteStorageType::INT8; } else if (fits_lower_limit(lower_data) && fits_upper_limit(upper_data)) { - data_type = WriteSparseMatrixToHdf5Parameters::StorageType::INT16; + data_type = WriteStorageType::INT16; } else { - data_type = WriteSparseMatrixToHdf5Parameters::StorageType::INT32; + data_type = WriteStorageType::INT32; } } else { if (fits_upper_limit(upper_data)) { - data_type = WriteSparseMatrixToHdf5Parameters::StorageType::UINT8; + data_type = WriteStorageType::UINT8; } else if (fits_upper_limit(upper_data)) { - data_type = WriteSparseMatrixToHdf5Parameters::StorageType::UINT16; + data_type = WriteStorageType::UINT16; } else { - data_type = WriteSparseMatrixToHdf5Parameters::StorageType::UINT32; + data_type = WriteStorageType::UINT32; } } } @@ -352,21 +342,21 @@ void write_sparse_matrix_to_hdf5(const tatami::Matrix* mat, H5:: if (use_auto_index_type) { auto upper_index = stats.upper_index; if (fits_upper_limit(upper_index)) { - index_type = WriteSparseMatrixToHdf5Parameters::StorageType::UINT8; + index_type = WriteStorageType::UINT8; } else if (fits_upper_limit(upper_index)) { - index_type = WriteSparseMatrixToHdf5Parameters::StorageType::UINT16; + index_type = WriteStorageType::UINT16; } else { - index_type = WriteSparseMatrixToHdf5Parameters::StorageType::UINT32; + index_type = WriteStorageType::UINT32; } } // Choosing the layout. auto layout = params.columnar; - if (layout == WriteSparseMatrixToHdf5Parameters::StorageLayout::AUTOMATIC) { + if (layout == WriteStorageLayout::AUTOMATIC) { if (mat->prefer_rows()) { - layout = WriteSparseMatrixToHdf5Parameters::StorageLayout::ROW; + layout = WriteStorageLayout::ROW; } else { - layout = WriteSparseMatrixToHdf5Parameters::StorageLayout::COLUMN; + layout = WriteStorageLayout::COLUMN; } } @@ -394,7 +384,7 @@ void write_sparse_matrix_to_hdf5(const tatami::Matrix* mat, H5:: }; if (mat->sparse()) { - if (layout == WriteSparseMatrixToHdf5Parameters::StorageLayout::ROW) { + if (layout == WriteStorageLayout::ROW) { ptrs.resize(NR + 1); std::vector xbuffer(NC); std::vector ibuffer(NC); @@ -437,7 +427,7 @@ void write_sparse_matrix_to_hdf5(const tatami::Matrix* mat, H5:: return count; }; - if (layout == WriteSparseMatrixToHdf5Parameters::StorageLayout::ROW) { + if (layout == WriteStorageLayout::ROW) { ptrs.resize(NR + 1); std::vector dbuffer(NC); auto wrk = tatami::consecutive_extractor(mat, true, static_cast(0), static_cast(NR)); @@ -480,9 +470,9 @@ void write_sparse_matrix_to_hdf5(const tatami::Matrix* mat, H5:: * @param location Handle to a HDF5 group in which to write the matrix contents. */ template -void write_sparse_matrix_to_hdf5(const tatami::Matrix* mat, H5::Group& location) { - WriteSparseMatrixToHdf5Parameters params; - write_sparse_matrix_to_hdf5(mat, location, params); +void write_compressed_sparse_matrix(const tatami::Matrix* mat, H5::Group& location) { + WriteCompressedSparseMatrixOptions params; + write_compressed_sparse_matrix(mat, location, params); return; } diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index f678706..e81ca55 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -24,10 +24,11 @@ include(GoogleTest) macro(create_h5test target) add_executable( ${target} - src/load_hdf5_matrix.cpp - src/write_sparse_matrix_to_hdf5.cpp - src/Hdf5DenseMatrix.cpp - src/Hdf5CompressedSparseMatrix.cpp + src/load_dense_matrix.cpp + src/load_compressed_sparse_matrix.cpp + src/write_compressed_sparse_matrix.cpp + src/DenseMatrix.cpp + src/CompressedSparseMatrix.cpp ) target_compile_definitions(${target} PRIVATE DEBUG=1) diff --git a/tests/src/Hdf5CompressedSparseMatrix.cpp b/tests/src/CompressedSparseMatrix.cpp similarity index 85% rename from tests/src/Hdf5CompressedSparseMatrix.cpp rename to tests/src/CompressedSparseMatrix.cpp index 6b89b8c..b1a39a6 100644 --- a/tests/src/Hdf5CompressedSparseMatrix.cpp +++ b/tests/src/CompressedSparseMatrix.cpp @@ -3,7 +3,7 @@ #include "H5Cpp.h" #include "tatami/tatami.hpp" -#include "tatami_hdf5/Hdf5CompressedSparseMatrix.hpp" +#include "tatami_hdf5/CompressedSparseMatrix.hpp" #include "tatami_test/tatami_test.hpp" #include "tatami_test/temp_file_path.hpp" @@ -47,16 +47,15 @@ static void dump_to_file(const tatami_test::CompressedSparseDetails& tri } } -static tatami_hdf5::Hdf5Options create_options(size_t NR, size_t NC, double cache_fraction) { +static tatami_hdf5::CompressedSparseMatrixOptions create_options(size_t NR, size_t NC, double cache_fraction) { // We limit the cache size to ensure that chunk management is not trivial. size_t actual_cache_size = static_cast(NR * NC) * cache_fraction * static_cast(sizeof(double) + sizeof(int)); - tatami_hdf5::Hdf5Options hopt; + tatami_hdf5::CompressedSparseMatrixOptions hopt; hopt.maximum_cache_size = actual_cache_size; - hopt.require_minimum_cache = actual_cache_size > 0; return hopt; } -class Hdf5SparseMatrixTestCore { +class SparseMatrixTestCore { public: typedef std::tuple SimulationParameters; @@ -94,7 +93,7 @@ class Hdf5SparseMatrixTestCore { std::string name = "stuff"; dump_to_file(triplets, fpath, name); - mat.reset(new tatami_hdf5::Hdf5CompressedSparseMatrix( + mat.reset(new tatami_hdf5::CompressedSparseMatrix( NR, NC, fpath, name + "/data", name + "/index", name + "/indptr", true, hopt )); ref.reset(new tatami::CompressedSparseRowMatrix( @@ -102,7 +101,7 @@ class Hdf5SparseMatrixTestCore { )); // Creating the transposed versions as well. - tmat.reset(new tatami_hdf5::Hdf5CompressedSparseMatrix( + tmat.reset(new tatami_hdf5::CompressedSparseMatrix( NC, NR, fpath, name + "/data", name + "/index", name + "/indptr", false, hopt )); tref.reset(new tatami::CompressedSparseColumnMatrix( @@ -114,13 +113,13 @@ class Hdf5SparseMatrixTestCore { /************************************* *************************************/ -class Hdf5SparseMatrixUtilsTest : public ::testing::Test, public Hdf5SparseMatrixTestCore { +class SparseMatrixUtilsTest : public ::testing::Test, public SparseMatrixTestCore { void SetUp() { assemble({ {200, 100}, { 0.1 } }); } }; -TEST_F(Hdf5SparseMatrixUtilsTest, Basic) { +TEST_F(SparseMatrixUtilsTest, Basic) { auto dimensions = std::get<0>(last_params); size_t NR = dimensions.first; size_t NC = dimensions.second; @@ -143,12 +142,12 @@ TEST_F(Hdf5SparseMatrixUtilsTest, Basic) { /************************************* *************************************/ -class Hdf5SparseMatrixFullAccessTest : - public ::testing::TestWithParam >, - public Hdf5SparseMatrixTestCore +class SparseMatrixFullAccessTest : + public ::testing::TestWithParam >, + public SparseMatrixTestCore {}; -TEST_P(Hdf5SparseMatrixFullAccessTest, Primary) { +TEST_P(SparseMatrixFullAccessTest, Primary) { auto param = GetParam(); assemble({ {200, 100}, std::get<0>(param) }); auto tparams = tatami_test::convert_access_parameters(std::get<1>(param)); @@ -160,7 +159,7 @@ TEST_P(Hdf5SparseMatrixFullAccessTest, Primary) { } } -TEST_P(Hdf5SparseMatrixFullAccessTest, Secondary) { +TEST_P(SparseMatrixFullAccessTest, Secondary) { auto param = GetParam(); assemble({ {50, 40}, std::get<0>(param) }); // smaller for the secondary dimension. auto tparams = tatami_test::convert_access_parameters(std::get<1>(param)); @@ -173,10 +172,10 @@ TEST_P(Hdf5SparseMatrixFullAccessTest, Secondary) { } INSTANTIATE_TEST_SUITE_P( - Hdf5SparseMatrix, - Hdf5SparseMatrixFullAccessTest, + SparseMatrix, + SparseMatrixFullAccessTest, ::testing::Combine( - Hdf5SparseMatrixTestCore::create_combinations(), + SparseMatrixTestCore::create_combinations(), tatami_test::standard_test_access_parameter_combinations() ) ); @@ -184,12 +183,12 @@ INSTANTIATE_TEST_SUITE_P( /************************************* *************************************/ -class Hdf5SparseMatrixBlockAccessTest : - public ::testing::TestWithParam > >, - public Hdf5SparseMatrixTestCore +class SparseMatrixBlockAccessTest : + public ::testing::TestWithParam > >, + public SparseMatrixTestCore {}; -TEST_P(Hdf5SparseMatrixBlockAccessTest, Primary) { +TEST_P(SparseMatrixBlockAccessTest, Primary) { auto param = GetParam(); assemble({ {128, 256}, std::get<0>(param) }); auto tparams = tatami_test::convert_access_parameters(std::get<1>(param)); @@ -204,7 +203,7 @@ TEST_P(Hdf5SparseMatrixBlockAccessTest, Primary) { } } -TEST_P(Hdf5SparseMatrixBlockAccessTest, Secondary) { +TEST_P(SparseMatrixBlockAccessTest, Secondary) { auto param = GetParam(); assemble({ {30, 50}, std::get<0>(param) }); // smaller for the secondary dimension. auto tparams = tatami_test::convert_access_parameters(std::get<1>(param)); @@ -220,10 +219,10 @@ TEST_P(Hdf5SparseMatrixBlockAccessTest, Secondary) { } INSTANTIATE_TEST_SUITE_P( - Hdf5SparseMatrix, - Hdf5SparseMatrixBlockAccessTest, + SparseMatrix, + SparseMatrixBlockAccessTest, ::testing::Combine( - Hdf5SparseMatrixTestCore::create_combinations(), + SparseMatrixTestCore::create_combinations(), tatami_test::standard_test_access_parameter_combinations(), ::testing::Values( std::make_pair(0.0, 0.333), @@ -236,12 +235,12 @@ INSTANTIATE_TEST_SUITE_P( /************************************* *************************************/ -class Hdf5SparseMatrixIndexedAccessTest : - public ::testing::TestWithParam > >, - public Hdf5SparseMatrixTestCore +class SparseMatrixIndexedAccessTest : + public ::testing::TestWithParam > >, + public SparseMatrixTestCore {}; -TEST_P(Hdf5SparseMatrixIndexedAccessTest, Primary) { +TEST_P(SparseMatrixIndexedAccessTest, Primary) { auto param = GetParam(); assemble({ {197, 125}, std::get<0>(param) }); auto tparams = tatami_test::convert_access_parameters(std::get<1>(param)); @@ -256,7 +255,7 @@ TEST_P(Hdf5SparseMatrixIndexedAccessTest, Primary) { } } -TEST_P(Hdf5SparseMatrixIndexedAccessTest, Secondary) { +TEST_P(SparseMatrixIndexedAccessTest, Secondary) { auto param = GetParam(); assemble({ {35, 40}, std::get<0>(param) }); // much smaller for the secondary dimension. auto tparams = tatami_test::convert_access_parameters(std::get<1>(param)); @@ -272,10 +271,10 @@ TEST_P(Hdf5SparseMatrixIndexedAccessTest, Secondary) { } INSTANTIATE_TEST_SUITE_P( - Hdf5SparseMatrix, - Hdf5SparseMatrixIndexedAccessTest, + SparseMatrix, + SparseMatrixIndexedAccessTest, ::testing::Combine( - Hdf5SparseMatrixTestCore::create_combinations(), + SparseMatrixTestCore::create_combinations(), tatami_test::standard_test_access_parameter_combinations(), ::testing::Values( std::make_pair(0.3, 5), @@ -288,9 +287,9 @@ INSTANTIATE_TEST_SUITE_P( /************************************* *************************************/ -class Hdf5SparseMatrixReusePrimaryCacheTest : +class SparseMatrixReusePrimaryCacheTest : public ::testing::TestWithParam >, - public Hdf5SparseMatrixTestCore + public SparseMatrixTestCore { protected: std::vector predictions; @@ -322,7 +321,7 @@ class Hdf5SparseMatrixReusePrimaryCacheTest : } }; -TEST_P(Hdf5SparseMatrixReusePrimaryCacheTest, FullExtent) { +TEST_P(SparseMatrixReusePrimaryCacheTest, FullExtent) { auto rwork = ref->dense_row(); auto mwork = mat->dense_row(); auto mwork2 = mat->dense_row(std::make_unique >(predictions.data(), predictions.size())); @@ -337,7 +336,7 @@ TEST_P(Hdf5SparseMatrixReusePrimaryCacheTest, FullExtent) { } } -TEST_P(Hdf5SparseMatrixReusePrimaryCacheTest, Block) { +TEST_P(SparseMatrixReusePrimaryCacheTest, Block) { auto full = ref->ncol(); auto cstart = full * 0.25, clen = full * 0.5; @@ -354,7 +353,7 @@ TEST_P(Hdf5SparseMatrixReusePrimaryCacheTest, Block) { } } -TEST_P(Hdf5SparseMatrixReusePrimaryCacheTest, Indexed) { +TEST_P(SparseMatrixReusePrimaryCacheTest, Indexed) { auto full = ref->ncol(); std::vector chosen; for (int i = 10; i < full; i += 7) { @@ -376,8 +375,8 @@ TEST_P(Hdf5SparseMatrixReusePrimaryCacheTest, Indexed) { } INSTANTIATE_TEST_SUITE_P( - Hdf5SparseMatrix, - Hdf5SparseMatrixReusePrimaryCacheTest, + SparseMatrix, + SparseMatrixReusePrimaryCacheTest, ::testing::Combine( ::testing::Values(0, 0.01, 0.1), // cache fraction ::testing::Values(1, 3), // jump between intervals @@ -388,7 +387,7 @@ INSTANTIATE_TEST_SUITE_P( /************************************* *************************************/ -class Hdf5SparseMatrixCacheTypeTest : public ::testing::TestWithParam > { +class SparseMatrixCacheTypeTest : public ::testing::TestWithParam > { protected: inline static std::shared_ptr > ref, mat; @@ -418,7 +417,7 @@ class Hdf5SparseMatrixCacheTypeTest : public ::testing::TestWithParam( + mat.reset(new tatami_hdf5::CompressedSparseMatrix( NR, NC, fpath, @@ -441,7 +440,7 @@ class Hdf5SparseMatrixCacheTypeTest : public ::testing::TestWithParam(tparam); @@ -455,8 +454,8 @@ TEST_P(Hdf5SparseMatrixCacheTypeTest, CastToInt) { } INSTANTIATE_TEST_SUITE_P( - Hdf5SparseMatrix, - Hdf5SparseMatrixCacheTypeTest, + SparseMatrix, + SparseMatrixCacheTypeTest, ::testing::Combine( ::testing::Values(0, 0.01, 0.1), // cache fraction ::testing::Values(true, false), // row access @@ -467,7 +466,7 @@ INSTANTIATE_TEST_SUITE_P( /************************************* *************************************/ -class Hdf5SparseMatrixUncompressedTest : public ::testing::TestWithParam > { +class SparseMatrixUncompressedTest : public ::testing::TestWithParam > { protected: inline static std::shared_ptr > ref, mat; @@ -497,12 +496,12 @@ class Hdf5SparseMatrixUncompressedTest : public ::testing::TestWithParam(NR, NC, fpath, name + "/data", name + "/index", name + "/indptr", true, hopt)); + mat.reset(new tatami_hdf5::CompressedSparseMatrix(NR, NC, fpath, name + "/data", name + "/index", name + "/indptr", true, hopt)); ref.reset(new tatami::CompressedSparseRowMatrix(NR, NC, std::move(triplets.value), std::move(triplets.index), triplets.ptr)); } }; -TEST_P(Hdf5SparseMatrixUncompressedTest, Basic) { +TEST_P(SparseMatrixUncompressedTest, Basic) { tatami_test::TestAccessParameters params; auto tparam = GetParam(); params.use_row = std::get<1>(tparam); @@ -516,8 +515,8 @@ TEST_P(Hdf5SparseMatrixUncompressedTest, Basic) { } INSTANTIATE_TEST_SUITE_P( - Hdf5SparseMatrix, - Hdf5SparseMatrixUncompressedTest, + SparseMatrix, + SparseMatrixUncompressedTest, ::testing::Combine( ::testing::Values(0, 0.01, 0.1), // cache fraction ::testing::Values(true, false), // row access @@ -528,7 +527,7 @@ INSTANTIATE_TEST_SUITE_P( /************************************* *************************************/ -class Hdf5SparseMatrixNearEmptyTest : public ::testing::TestWithParam > { +class SparseMatrixNearEmptyTest : public ::testing::TestWithParam > { protected: inline static std::shared_ptr > ref, mat; @@ -572,12 +571,12 @@ class Hdf5SparseMatrixNearEmptyTest : public ::testing::TestWithParam(NR, NC, fpath, name + "/data", name + "/index", name + "/indptr", true, hopt)); + mat.reset(new tatami_hdf5::CompressedSparseMatrix(NR, NC, fpath, name + "/data", name + "/index", name + "/indptr", true, hopt)); ref.reset(new tatami::CompressedSparseRowMatrix(NR, NC, std::move(triplets.value), std::move(triplets.index), triplets.ptr)); } }; -TEST_P(Hdf5SparseMatrixNearEmptyTest, Basic) { +TEST_P(SparseMatrixNearEmptyTest, Basic) { tatami_test::TestAccessParameters params; auto tparam = GetParam(); params.use_row = std::get<1>(tparam); @@ -591,8 +590,8 @@ TEST_P(Hdf5SparseMatrixNearEmptyTest, Basic) { } INSTANTIATE_TEST_SUITE_P( - Hdf5SparseMatrix, - Hdf5SparseMatrixNearEmptyTest, + SparseMatrix, + SparseMatrixNearEmptyTest, ::testing::Combine( ::testing::Values(0, 0.01, 0.1), // cache fraction ::testing::Values(true, false), // row access @@ -603,9 +602,9 @@ INSTANTIATE_TEST_SUITE_P( /************************************* *************************************/ -class Hdf5SparseMatrixParallelTest : - public ::testing::TestWithParam >, - public Hdf5SparseMatrixTestCore +class SparseMatrixParallelTest : + public ::testing::TestWithParam >, + public SparseMatrixTestCore { protected: void SetUp() { @@ -649,7 +648,7 @@ class Hdf5SparseMatrixParallelTest : } }; -TEST_P(Hdf5SparseMatrixParallelTest, Simple) { +TEST_P(SparseMatrixParallelTest, Simple) { auto param = GetParam(); bool row = std::get<1>(param); bool oracle = std::get<2>(param); @@ -664,10 +663,10 @@ TEST_P(Hdf5SparseMatrixParallelTest, Simple) { } INSTANTIATE_TEST_SUITE_P( - Hdf5SparseMatrix, - Hdf5SparseMatrixParallelTest, + SparseMatrix, + SparseMatrixParallelTest, ::testing::Combine( - Hdf5SparseMatrixTestCore::create_combinations(), + SparseMatrixTestCore::create_combinations(), ::testing::Values(true, false), // row access ::testing::Values(true, false) // oracle usage ) diff --git a/tests/src/Hdf5DenseMatrix.cpp b/tests/src/DenseMatrix.cpp similarity index 81% rename from tests/src/Hdf5DenseMatrix.cpp rename to tests/src/DenseMatrix.cpp index 5a6174e..336f8d1 100644 --- a/tests/src/Hdf5DenseMatrix.cpp +++ b/tests/src/DenseMatrix.cpp @@ -3,7 +3,7 @@ #include "H5Cpp.h" #include "tatami/tatami.hpp" -#include "tatami_hdf5/Hdf5DenseMatrix.hpp" +#include "tatami_hdf5/DenseMatrix.hpp" #include "tatami_test/tatami_test.hpp" #include "tatami_test/temp_file_path.hpp" @@ -12,7 +12,7 @@ #include #include -class Hdf5DenseMatrixTestCore { +class DenseMatrixTestCore { public: static constexpr size_t NR = 200, NC = 100; @@ -78,12 +78,12 @@ class Hdf5DenseMatrixTestCore { ref.reset(new tatami::DenseRowMatrix(NR, NC, std::move(values))); tref.reset(new tatami::DelayedTranspose(ref)); - tatami_hdf5::Hdf5Options opt; + tatami_hdf5::DenseMatrixOptions opt; opt.maximum_cache_size = sizeof(double) * cache_size; opt.require_minimum_cache = (cache_size > 0); - mat.reset(new tatami_hdf5::Hdf5DenseMatrix(fpath, name, false, opt)); - tmat.reset(new tatami_hdf5::Hdf5DenseMatrix(fpath, name, true, opt)); + mat.reset(new tatami_hdf5::DenseMatrix(fpath, name, false, opt)); + tmat.reset(new tatami_hdf5::DenseMatrix(fpath, name, true, opt)); return; } }; @@ -91,9 +91,9 @@ class Hdf5DenseMatrixTestCore { /************************************* *************************************/ -class Hdf5DenseMatrixUtilsTest : public ::testing::Test, public Hdf5DenseMatrixTestCore {}; +class DenseMatrixUtilsTest : public ::testing::Test, public DenseMatrixTestCore {}; -TEST_F(Hdf5DenseMatrixUtilsTest, Basic) { +TEST_F(DenseMatrixUtilsTest, Basic) { { assemble(SimulationParameters(std::pair(10, 10), 10)); EXPECT_EQ(mat->nrow(), NR); @@ -127,26 +127,26 @@ TEST_F(Hdf5DenseMatrixUtilsTest, Basic) { /************************************* *************************************/ -class Hdf5DenseMatrixAccessFullTest : - public ::testing::TestWithParam >, - public Hdf5DenseMatrixTestCore { +class DenseMatrixAccessFullTest : + public ::testing::TestWithParam >, + public DenseMatrixTestCore { protected: void SetUp() { assemble(std::get<0>(GetParam())); } }; -TEST_P(Hdf5DenseMatrixAccessFullTest, Basic) { +TEST_P(DenseMatrixAccessFullTest, Basic) { auto params = tatami_test::convert_access_parameters(std::get<1>(GetParam())); tatami_test::test_full_access(params, mat.get(), ref.get()); tatami_test::test_full_access(params, tmat.get(), tref.get()); } INSTANTIATE_TEST_SUITE_P( - Hdf5DenseMatrix, - Hdf5DenseMatrixAccessFullTest, + DenseMatrix, + DenseMatrixAccessFullTest, ::testing::Combine( - Hdf5DenseMatrixTestCore::create_combinations(), + DenseMatrixTestCore::create_combinations(), tatami_test::standard_test_access_parameter_combinations() ) ); @@ -154,16 +154,16 @@ INSTANTIATE_TEST_SUITE_P( /************************************* *************************************/ -class Hdf5DenseSlicedTest : - public ::testing::TestWithParam > >, - public Hdf5DenseMatrixTestCore { +class DenseSlicedTest : + public ::testing::TestWithParam > >, + public DenseMatrixTestCore { protected: void SetUp() { assemble(std::get<0>(GetParam())); } }; -TEST_P(Hdf5DenseSlicedTest, Basic) { +TEST_P(DenseSlicedTest, Basic) { auto tparam = GetParam(); auto params = tatami_test::convert_access_parameters(std::get<1>(tparam)); auto block = std::get<2>(tparam); @@ -182,10 +182,10 @@ TEST_P(Hdf5DenseSlicedTest, Basic) { } INSTANTIATE_TEST_SUITE_P( - Hdf5DenseMatrix, - Hdf5DenseSlicedTest, + DenseMatrix, + DenseSlicedTest, ::testing::Combine( - Hdf5DenseMatrixTestCore::create_combinations(), + DenseMatrixTestCore::create_combinations(), tatami_test::standard_test_access_parameter_combinations(), ::testing::Values( std::make_pair(0.0, 0.5), @@ -198,16 +198,16 @@ INSTANTIATE_TEST_SUITE_P( /************************************* *************************************/ -class Hdf5DenseIndexedTest : - public ::testing::TestWithParam > >, - public Hdf5DenseMatrixTestCore { +class DenseIndexedTest : + public ::testing::TestWithParam > >, + public DenseMatrixTestCore { protected: void SetUp() { assemble(std::get<0>(GetParam())); } }; -TEST_P(Hdf5DenseIndexedTest, Basic) { +TEST_P(DenseIndexedTest, Basic) { auto tparam = GetParam(); auto params = tatami_test::convert_access_parameters(std::get<1>(tparam)); auto index = std::get<2>(tparam); @@ -226,10 +226,10 @@ TEST_P(Hdf5DenseIndexedTest, Basic) { } INSTANTIATE_TEST_SUITE_P( - Hdf5DenseMatrix, - Hdf5DenseIndexedTest, + DenseMatrix, + DenseIndexedTest, ::testing::Combine( - Hdf5DenseMatrixTestCore::create_combinations(), + DenseMatrixTestCore::create_combinations(), tatami_test::standard_test_access_parameter_combinations(), ::testing::Values( std::make_pair(0.3, 5), @@ -242,12 +242,12 @@ INSTANTIATE_TEST_SUITE_P( /************************************* *************************************/ -class Hdf5DenseMatrixCacheTypeTest : public ::testing::TestWithParam >, public Hdf5DenseMatrixTestCore {}; +class DenseMatrixCacheTypeTest : public ::testing::TestWithParam >, public DenseMatrixTestCore {}; -TEST_P(Hdf5DenseMatrixCacheTypeTest, CastToInt) { +TEST_P(DenseMatrixCacheTypeTest, CastToInt) { assemble(SimulationParameters(std::make_pair(9, 13), 1)); - tatami_hdf5::Hdf5DenseMatrix mat(fpath, name, false); + tatami_hdf5::DenseMatrix mat(fpath, name, false); auto altref = tatami::convert_to_dense(ref.get(), true); tatami_test::TestAccessParameters params; @@ -261,8 +261,8 @@ TEST_P(Hdf5DenseMatrixCacheTypeTest, CastToInt) { } INSTANTIATE_TEST_SUITE_P( - Hdf5DenseMatrix, - Hdf5DenseMatrixCacheTypeTest, + DenseMatrix, + DenseMatrixCacheTypeTest, ::testing::Combine( ::testing::Values(true, false), // row access ::testing::Values(true, false) // oracle usage @@ -272,7 +272,7 @@ INSTANTIATE_TEST_SUITE_P( /************************************* *************************************/ -class Hdf5DenseMatrixParallelTest : public ::testing::TestWithParam >, public Hdf5DenseMatrixTestCore { +class DenseMatrixParallelTest : public ::testing::TestWithParam >, public DenseMatrixTestCore { protected: void SetUp() { assemble(std::get<0>(GetParam())); @@ -314,7 +314,7 @@ class Hdf5DenseMatrixParallelTest : public ::testing::TestWithParam(param); bool oracle = std::get<2>(param); @@ -329,10 +329,10 @@ TEST_P(Hdf5DenseMatrixParallelTest, Simple) { } INSTANTIATE_TEST_SUITE_P( - Hdf5DenseMatrix, - Hdf5DenseMatrixParallelTest, + DenseMatrix, + DenseMatrixParallelTest, ::testing::Combine( - Hdf5DenseMatrixTestCore::create_combinations(), + DenseMatrixTestCore::create_combinations(), ::testing::Values(true, false), // row access ::testing::Values(true, false) // oracle usage ) diff --git a/tests/src/load_hdf5_matrix.cpp b/tests/src/load_compressed_sparse_matrix.cpp similarity index 55% rename from tests/src/load_hdf5_matrix.cpp rename to tests/src/load_compressed_sparse_matrix.cpp index 3ac7e05..6f1c7bb 100644 --- a/tests/src/load_hdf5_matrix.cpp +++ b/tests/src/load_compressed_sparse_matrix.cpp @@ -2,7 +2,7 @@ #include "custom_parallel.h" // make sure this is included before tatami libs. #include "H5Cpp.h" -#include "tatami_hdf5/load_hdf5_matrix.hpp" +#include "tatami_hdf5/load_compressed_sparse_matrix.hpp" #include "tatami_test/tatami_test.hpp" #include "tatami_test/temp_file_path.hpp" @@ -10,7 +10,7 @@ #include #include -TEST(LoadHDF5MatrixTest, Sparse) { +TEST(LoadCompressedSparseMatrixTest, Basic) { const size_t NR = 200, NC = 100; // Dumping a sparse matrix. @@ -47,7 +47,7 @@ TEST(LoadHDF5MatrixTest, Sparse) { // Basic load as a CSR matrix (as rows are the primary dimension in this simulation) { - auto mat = tatami_hdf5::load_hdf5_compressed_sparse_matrix(NR, NC, fpath, name + "/data", name + "/index", name + "/indptr"); + auto mat = tatami_hdf5::load_compressed_sparse_matrix(NR, NC, fpath, name + "/data", name + "/index", name + "/indptr", true); tatami::CompressedSparseRowMatrix< double, int, @@ -56,12 +56,12 @@ TEST(LoadHDF5MatrixTest, Sparse) { decltype(triplets.ptr) > ref(NR, NC, triplets.value, triplets.index, triplets.ptr); - tatami_test::test_simple_row_access(&mat, &ref); + tatami_test::test_simple_row_access(mat.get(), &ref); } // Pretending it's a CSC matrix. { - auto mat = tatami_hdf5::load_hdf5_compressed_sparse_matrix(NC, NR, fpath, name + "/data", name + "/index", name + "/indptr"); + auto mat = tatami_hdf5::load_compressed_sparse_matrix(NC, NR, fpath, name + "/data", name + "/index", name + "/indptr", false); tatami::CompressedSparseColumnMatrix< double, int, @@ -70,19 +70,18 @@ TEST(LoadHDF5MatrixTest, Sparse) { decltype(triplets.ptr) > ref(NC, NR, triplets.value, triplets.index, triplets.ptr); - tatami_test::test_simple_column_access(&mat, &ref); + tatami_test::test_simple_column_access(mat.get(), &ref); } // Trying a variety of storage types. { - auto mat = tatami_hdf5::load_hdf5_compressed_sparse_matrix< - true, + auto mat = tatami_hdf5::load_compressed_sparse_matrix< double, int, std::vector, std::vector, std::vector - >(NR, NC, fpath, name + "/data", name + "/index", name + "/indptr"); + >(NR, NC, fpath, name + "/data", name + "/index", name + "/indptr", true); std::vector truncated = triplets.value; for (auto& x : truncated) { @@ -97,52 +96,6 @@ TEST(LoadHDF5MatrixTest, Sparse) { decltype(triplets.ptr) > ref(NR, NC, std::move(truncated), triplets.index, triplets.ptr); - tatami_test::test_simple_column_access(&mat, &ref); - } -} - -TEST(LoadHDF5MatrixTest, Dense) { - size_t NR = 200, NC = 100; - auto fpath = tatami_test::temp_file_path("tatami-dense-test.h5"); - std::string name = "stuff"; - - std::vector values = tatami_test::simulate_dense_vector(NR * NC, 0, 100); - - { - H5::H5File fhandle(fpath, H5F_ACC_TRUNC); - hsize_t dims[2]; - dims[0] = NR; - dims[1] = NC; - H5::DataSpace dspace(2, dims); - H5::DataType dtype(H5::PredType::NATIVE_DOUBLE); - auto dhandle = fhandle.createDataSet(name, dtype, dspace); - dhandle.write(values.data(), H5::PredType::NATIVE_DOUBLE); - } - - // Basic load as a row-major matrix. - { - auto mat = tatami_hdf5::load_hdf5_dense_matrix(fpath, name, false); - tatami::DenseRowMatrix ref(NR, NC, values); - tatami_test::test_simple_row_access(&mat, &ref); - } - - // Pretending it's a column-major matrix. - { - auto mat = tatami_hdf5::load_hdf5_dense_matrix >(fpath, name, true); - tatami::DenseColumnMatrix ref(NC, NR, values); - tatami_test::test_simple_column_access(&mat, &ref); - } - - // Trying a different storage type. - { - auto mat = tatami_hdf5::load_hdf5_dense_matrix >(fpath, name); - - std::vector truncated = values; - for (auto& x : truncated) { - x = std::trunc(x); - } - tatami::DenseRowMatrix ref(NR, NC, std::move(truncated)); - - tatami_test::test_simple_column_access(&mat, &ref); + tatami_test::test_simple_column_access(mat.get(), &ref); } } diff --git a/tests/src/load_dense_matrix.cpp b/tests/src/load_dense_matrix.cpp new file mode 100644 index 0000000..0696a5a --- /dev/null +++ b/tests/src/load_dense_matrix.cpp @@ -0,0 +1,57 @@ +#include +#include "custom_parallel.h" // make sure this is included before tatami libs. + +#include "H5Cpp.h" +#include "tatami_hdf5/load_dense_matrix.hpp" + +#include "tatami_test/tatami_test.hpp" +#include "tatami_test/temp_file_path.hpp" + +#include +#include + +TEST(LoadDenseMatrixTest, Basic) { + size_t NR = 200, NC = 100; + auto fpath = tatami_test::temp_file_path("tatami-dense-test.h5"); + std::string name = "stuff"; + + std::vector values = tatami_test::simulate_dense_vector(NR * NC, 0, 100); + + { + H5::H5File fhandle(fpath, H5F_ACC_TRUNC); + hsize_t dims[2]; + dims[0] = NR; + dims[1] = NC; + H5::DataSpace dspace(2, dims); + H5::DataType dtype(H5::PredType::NATIVE_DOUBLE); + auto dhandle = fhandle.createDataSet(name, dtype, dspace); + dhandle.write(values.data(), H5::PredType::NATIVE_DOUBLE); + } + + // Basic load as a row-major matrix. + { + auto mat = tatami_hdf5::load_dense_matrix(fpath, name, false); + tatami::DenseRowMatrix ref(NR, NC, values); + tatami_test::test_simple_row_access(mat.get(), &ref); + } + + // Pretending it's a column-major matrix. + { + auto mat = tatami_hdf5::load_dense_matrix >(fpath, name, true); + tatami::DenseColumnMatrix ref(NC, NR, values); + tatami_test::test_simple_column_access(mat.get(), &ref); + } + + // Trying a different storage type. + { + auto mat = tatami_hdf5::load_dense_matrix >(fpath, name, false); + + std::vector truncated = values; + for (auto& x : truncated) { + x = std::trunc(x); + } + tatami::DenseRowMatrix ref(NR, NC, std::move(truncated)); + + tatami_test::test_simple_column_access(mat.get(), &ref); + } +} diff --git a/tests/src/write_sparse_matrix_to_hdf5.cpp b/tests/src/write_compressed_sparse_matrix.cpp similarity index 57% rename from tests/src/write_sparse_matrix_to_hdf5.cpp rename to tests/src/write_compressed_sparse_matrix.cpp index f998d6c..d42dbc8 100644 --- a/tests/src/write_sparse_matrix_to_hdf5.cpp +++ b/tests/src/write_compressed_sparse_matrix.cpp @@ -3,8 +3,8 @@ #include "H5Cpp.h" #include "tatami/tatami.hpp" -#include "tatami_hdf5/load_hdf5_matrix.hpp" -#include "tatami_hdf5/write_sparse_matrix_to_hdf5.hpp" +#include "tatami_hdf5/load_compressed_sparse_matrix.hpp" +#include "tatami_hdf5/write_compressed_sparse_matrix.hpp" #include "tatami_test/tatami_test.hpp" #include "tatami_test/temp_file_path.hpp" @@ -15,14 +15,14 @@ /***************************************** *****************************************/ -class WriteSparseMatrixToHdf5BasicTest : public ::testing::TestWithParam {}; +class WriteCompressedSparseMatrixBasicTest : public ::testing::TestWithParam {}; -TEST_P(WriteSparseMatrixToHdf5BasicTest, SparseColumn) { +TEST_P(WriteCompressedSparseMatrixBasicTest, SparseColumn) { const size_t NR = 200, NC = 100; auto triplets = tatami_test::simulate_sparse_compressed(NC, NR, 0.05, 0, 100); tatami::CompressedSparseColumnMatrix mat(NR, NC, std::move(triplets.value), std::move(triplets.index), std::move(triplets.ptr)); - tatami_hdf5::WriteSparseMatrixToHdf5Parameters param_core; + tatami_hdf5::WriteCompressedSparseMatrixOptions param_core; param_core.num_threads = GetParam(); // Dumping it. @@ -30,7 +30,7 @@ TEST_P(WriteSparseMatrixToHdf5BasicTest, SparseColumn) { { H5::H5File fhandle(fpath, H5F_ACC_TRUNC); auto mhandle = fhandle.createGroup("matrix"); - tatami_hdf5::write_sparse_matrix_to_hdf5(&mat, mhandle, param_core); + tatami_hdf5::write_compressed_sparse_matrix(&mat, mhandle, param_core); } // Checking the dumped contents. @@ -48,8 +48,8 @@ TEST_P(WriteSparseMatrixToHdf5BasicTest, SparseColumn) { // Roundtripping. { - auto reloaded = tatami_hdf5::load_hdf5_compressed_sparse_matrix(NR, NC, fpath, "matrix/data", "matrix/indices", "matrix/indptr"); - tatami_test::test_simple_row_access(&reloaded, &mat); + auto reloaded = tatami_hdf5::load_compressed_sparse_matrix(NR, NC, fpath, "matrix/data", "matrix/indices", "matrix/indptr", false); + tatami_test::test_simple_row_access(reloaded.get(), &mat); } // Forcing it to be integer. @@ -58,7 +58,7 @@ TEST_P(WriteSparseMatrixToHdf5BasicTest, SparseColumn) { auto mhandle = fhandle.createGroup("matrix"); auto params = param_core; params.force_integer = true; - tatami_hdf5::write_sparse_matrix_to_hdf5(&mat, mhandle, params); + tatami_hdf5::write_compressed_sparse_matrix(&mat, mhandle, params); } { @@ -68,10 +68,10 @@ TEST_P(WriteSparseMatrixToHdf5BasicTest, SparseColumn) { } { - auto reloaded = tatami_hdf5::load_hdf5_compressed_sparse_matrix(NR, NC, fpath, "matrix/data", "matrix/indices", "matrix/indptr"); + auto reloaded = tatami_hdf5::load_compressed_sparse_matrix(NR, NC, fpath, "matrix/data", "matrix/indices", "matrix/indptr", false); auto mwrk = mat.dense_row(); - auto rwrk = reloaded.dense_row(); + auto rwrk = reloaded->dense_row(); for (size_t r = 0; r < NR; ++r) { auto matrow = tatami_test::fetch(mwrk.get(), static_cast(r), NC); for (auto& x : matrow) { @@ -83,12 +83,12 @@ TEST_P(WriteSparseMatrixToHdf5BasicTest, SparseColumn) { } } -TEST_P(WriteSparseMatrixToHdf5BasicTest, SparseRow) { +TEST_P(WriteCompressedSparseMatrixBasicTest, SparseRow) { const size_t NR = 200, NC = 100; auto triplets = tatami_test::simulate_sparse_compressed(NR, NC, 0.05, 0, 100); tatami::CompressedSparseRowMatrix mat(NR, NC, std::move(triplets.value), std::move(triplets.index), std::move(triplets.ptr)); - tatami_hdf5::WriteSparseMatrixToHdf5Parameters param_core; + tatami_hdf5::WriteCompressedSparseMatrixOptions param_core; param_core.num_threads = GetParam(); // Dumping it. @@ -96,7 +96,7 @@ TEST_P(WriteSparseMatrixToHdf5BasicTest, SparseRow) { { H5::H5File fhandle(fpath, H5F_ACC_TRUNC); auto mhandle = fhandle.createGroup("matrix"); - tatami_hdf5::write_sparse_matrix_to_hdf5(&mat, mhandle, param_core); + tatami_hdf5::write_compressed_sparse_matrix(&mat, mhandle, param_core); } // Checking the dumped contents. @@ -111,8 +111,8 @@ TEST_P(WriteSparseMatrixToHdf5BasicTest, SparseRow) { // Roundtripping. { - auto reloaded = tatami_hdf5::load_hdf5_compressed_sparse_matrix(NR, NC, fpath, "matrix/data", "matrix/indices", "matrix/indptr"); - tatami_test::test_simple_row_access(&reloaded, &mat); + auto reloaded = tatami_hdf5::load_compressed_sparse_matrix(NR, NC, fpath, "matrix/data", "matrix/indices", "matrix/indptr", true); + tatami_test::test_simple_row_access(reloaded.get(), &mat); } // Forcing it to be columnar. @@ -120,8 +120,8 @@ TEST_P(WriteSparseMatrixToHdf5BasicTest, SparseRow) { H5::H5File fhandle(fpath, H5F_ACC_TRUNC); auto mhandle = fhandle.createGroup("matrix"); auto params = param_core; - params.columnar = tatami_hdf5::WriteSparseMatrixToHdf5Parameters::StorageLayout::COLUMN; - tatami_hdf5::write_sparse_matrix_to_hdf5(&mat, mhandle, params); + params.columnar = tatami_hdf5::WriteStorageLayout::COLUMN; + tatami_hdf5::write_compressed_sparse_matrix(&mat, mhandle, params); } { @@ -134,17 +134,17 @@ TEST_P(WriteSparseMatrixToHdf5BasicTest, SparseRow) { } { - auto reloaded = tatami_hdf5::load_hdf5_compressed_sparse_matrix(NR, NC, fpath, "matrix/data", "matrix/indices", "matrix/indptr"); - tatami_test::test_simple_row_access(&reloaded, &mat); + auto reloaded = tatami_hdf5::load_compressed_sparse_matrix(NR, NC, fpath, "matrix/data", "matrix/indices", "matrix/indptr", false); + tatami_test::test_simple_row_access(reloaded.get(), &mat); } } -TEST_P(WriteSparseMatrixToHdf5BasicTest, DenseColumn) { +TEST_P(WriteCompressedSparseMatrixBasicTest, DenseColumn) { const size_t NR = 190, NC = 210; auto vec = tatami_test::simulate_sparse_vector(NR * NC, 0.05, 0, 100); tatami::DenseColumnMatrix mat(NR, NC, std::move(vec)); - tatami_hdf5::WriteSparseMatrixToHdf5Parameters param_core; + tatami_hdf5::WriteCompressedSparseMatrixOptions param_core; param_core.num_threads = GetParam(); // Dumping it. @@ -152,20 +152,20 @@ TEST_P(WriteSparseMatrixToHdf5BasicTest, DenseColumn) { { H5::H5File fhandle(fpath, H5F_ACC_TRUNC); auto mhandle = fhandle.createGroup("matrix"); - tatami_hdf5::write_sparse_matrix_to_hdf5(&mat, mhandle, param_core); + tatami_hdf5::write_compressed_sparse_matrix(&mat, mhandle, param_core); } // Roundtripping. - auto reloaded = tatami_hdf5::load_hdf5_compressed_sparse_matrix(NR, NC, fpath, "matrix/data", "matrix/indices", "matrix/indptr"); - tatami_test::test_simple_row_access(&reloaded, &mat); + auto reloaded = tatami_hdf5::load_compressed_sparse_matrix(NR, NC, fpath, "matrix/data", "matrix/indices", "matrix/indptr", false); + tatami_test::test_simple_row_access(reloaded.get(), &mat); } -TEST_P(WriteSparseMatrixToHdf5BasicTest, DenseRow) { +TEST_P(WriteCompressedSparseMatrixBasicTest, DenseRow) { const size_t NR = 90, NC = 300; auto vec = tatami_test::simulate_sparse_vector(NR * NC, 0.05, 0, 100); tatami::DenseRowMatrix mat(NR, NC, std::move(vec)); - tatami_hdf5::WriteSparseMatrixToHdf5Parameters param_core; + tatami_hdf5::WriteCompressedSparseMatrixOptions param_core; param_core.num_threads = GetParam(); // Dumping it. @@ -173,26 +173,26 @@ TEST_P(WriteSparseMatrixToHdf5BasicTest, DenseRow) { { H5::H5File fhandle(fpath, H5F_ACC_TRUNC); auto mhandle = fhandle.createGroup("matrix"); - tatami_hdf5::write_sparse_matrix_to_hdf5(&mat, mhandle, param_core); + tatami_hdf5::write_compressed_sparse_matrix(&mat, mhandle, param_core); } // Roundtripping. - auto reloaded = tatami_hdf5::load_hdf5_compressed_sparse_matrix(NR, NC, fpath, "matrix/data", "matrix/indices", "matrix/indptr"); - tatami_test::test_simple_row_access(&reloaded, &mat); + auto reloaded = tatami_hdf5::load_compressed_sparse_matrix(NR, NC, fpath, "matrix/data", "matrix/indices", "matrix/indptr", true); + tatami_test::test_simple_row_access(reloaded.get(), &mat); } INSTANTIATE_TEST_SUITE_P( - WriteSparseMatrixToHdf5, - WriteSparseMatrixToHdf5BasicTest, + WriteCompressedSparseMatrix, + WriteCompressedSparseMatrixBasicTest, ::testing::Values(1, 3) // Number of threads ); /***************************************** *****************************************/ -class WriteSparseMatrixToHdf5UnsignedDataTypeTest : public ::testing::TestWithParam > {}; +class WriteCompressedSparseMatrixUnsignedDataTypeTest : public ::testing::TestWithParam > {}; -TEST_P(WriteSparseMatrixToHdf5UnsignedDataTypeTest, Check) { +TEST_P(WriteCompressedSparseMatrixUnsignedDataTypeTest, Check) { auto params = GetParam(); auto type = std::get<0>(params); auto nthreads = std::get<1>(params); @@ -201,15 +201,15 @@ TEST_P(WriteSparseMatrixToHdf5UnsignedDataTypeTest, Check) { auto triplets = tatami_test::simulate_sparse_compressed(NC, NR, 0.05, 0, 100); for (auto& x : triplets.value) { x = std::round(x); - if (type == tatami_hdf5::WriteSparseMatrixToHdf5Parameters::StorageType::UINT16) { + if (type == tatami_hdf5::WriteStorageType::UINT16) { x *= 10; - } else if (type == tatami_hdf5::WriteSparseMatrixToHdf5Parameters::StorageType::UINT32) { + } else if (type == tatami_hdf5::WriteStorageType::UINT32) { x *= 1000; } } tatami::CompressedSparseColumnMatrix mat(NR, NC, std::move(triplets.value), std::move(triplets.index), std::move(triplets.ptr)); - tatami_hdf5::WriteSparseMatrixToHdf5Parameters param_core; + tatami_hdf5::WriteCompressedSparseMatrixOptions param_core; param_core.num_threads = nthreads; // Dumping it. @@ -217,7 +217,7 @@ TEST_P(WriteSparseMatrixToHdf5UnsignedDataTypeTest, Check) { { H5::H5File fhandle(fpath, H5F_ACC_TRUNC); auto mhandle = fhandle.createGroup("matrix"); - tatami_hdf5::write_sparse_matrix_to_hdf5(&mat, mhandle, param_core); + tatami_hdf5::write_compressed_sparse_matrix(&mat, mhandle, param_core); } // Checking the dumped contents. @@ -228,9 +228,9 @@ TEST_P(WriteSparseMatrixToHdf5UnsignedDataTypeTest, Check) { H5::IntType dtype(dhandle); EXPECT_EQ(dtype.getSign(), H5T_SGN_NONE); - if (type == tatami_hdf5::WriteSparseMatrixToHdf5Parameters::StorageType::UINT8) { + if (type == tatami_hdf5::WriteStorageType::UINT8) { EXPECT_TRUE(dtype.getSize() <= 8); - } else if (type == tatami_hdf5::WriteSparseMatrixToHdf5Parameters::StorageType::UINT16) { + } else if (type == tatami_hdf5::WriteStorageType::UINT16) { EXPECT_TRUE(dtype.getSize() <= 16); } else { EXPECT_TRUE(dtype.getSize() <= 32); @@ -239,8 +239,8 @@ TEST_P(WriteSparseMatrixToHdf5UnsignedDataTypeTest, Check) { // Roundtripping. { - auto reloaded = tatami_hdf5::load_hdf5_compressed_sparse_matrix(NR, NC, fpath, "matrix/data", "matrix/indices", "matrix/indptr"); - tatami_test::test_simple_row_access(&reloaded, &mat); + auto reloaded = tatami_hdf5::load_compressed_sparse_matrix(NR, NC, fpath, "matrix/data", "matrix/indices", "matrix/indptr", false); + tatami_test::test_simple_row_access(reloaded.get(), &mat); } // But we can always force it to a float. @@ -248,8 +248,8 @@ TEST_P(WriteSparseMatrixToHdf5UnsignedDataTypeTest, Check) { H5::H5File fhandle(fpath, H5F_ACC_TRUNC); auto mhandle = fhandle.createGroup("matrix"); auto params = param_core; - params.data_type = tatami_hdf5::WriteSparseMatrixToHdf5Parameters::StorageType::DOUBLE; - tatami_hdf5::write_sparse_matrix_to_hdf5(&mat, mhandle, params); + params.data_type = tatami_hdf5::WriteStorageType::DOUBLE; + tatami_hdf5::write_compressed_sparse_matrix(&mat, mhandle, params); } { @@ -259,19 +259,19 @@ TEST_P(WriteSparseMatrixToHdf5UnsignedDataTypeTest, Check) { } { - auto reloaded = tatami_hdf5::load_hdf5_compressed_sparse_matrix(NR, NC, fpath, "matrix/data", "matrix/indices", "matrix/indptr"); - tatami_test::test_simple_row_access(&reloaded, &mat); + auto reloaded = tatami_hdf5::load_compressed_sparse_matrix(NR, NC, fpath, "matrix/data", "matrix/indices", "matrix/indptr", false); + tatami_test::test_simple_row_access(reloaded.get(), &mat); } } INSTANTIATE_TEST_SUITE_P( - WriteSparseMatrixToHdf5, - WriteSparseMatrixToHdf5UnsignedDataTypeTest, + WriteCompressedSparseMatrix, + WriteCompressedSparseMatrixUnsignedDataTypeTest, ::testing::Combine( ::testing::Values( - tatami_hdf5::WriteSparseMatrixToHdf5Parameters::StorageType::UINT8, - tatami_hdf5::WriteSparseMatrixToHdf5Parameters::StorageType::UINT16, - tatami_hdf5::WriteSparseMatrixToHdf5Parameters::StorageType::UINT32 + tatami_hdf5::WriteStorageType::UINT8, + tatami_hdf5::WriteStorageType::UINT16, + tatami_hdf5::WriteStorageType::UINT32 ), ::testing::Values(1, 3) ) @@ -280,9 +280,9 @@ INSTANTIATE_TEST_SUITE_P( /***************************************** *****************************************/ -class WriteSparseMatrixToHdf5SignedDataTypeTest : public ::testing::TestWithParam > {}; +class WriteCompressedSparseMatrixSignedDataTypeTest : public ::testing::TestWithParam > {}; -TEST_P(WriteSparseMatrixToHdf5SignedDataTypeTest, Check) { +TEST_P(WriteCompressedSparseMatrixSignedDataTypeTest, Check) { auto params = GetParam(); auto type = std::get<0>(params); auto nthreads = std::get<1>(params); @@ -291,9 +291,9 @@ TEST_P(WriteSparseMatrixToHdf5SignedDataTypeTest, Check) { auto triplets = tatami_test::simulate_sparse_compressed(NC, NR, 0.05, -100, 100); for (auto& x : triplets.value) { x = std::round(x); - if (type == tatami_hdf5::WriteSparseMatrixToHdf5Parameters::StorageType::INT16) { + if (type == tatami_hdf5::WriteStorageType::INT16) { x *= 10; - } else if (type == tatami_hdf5::WriteSparseMatrixToHdf5Parameters::StorageType::INT32) { + } else if (type == tatami_hdf5::WriteStorageType::INT32) { x *= 1000; } } @@ -304,9 +304,9 @@ TEST_P(WriteSparseMatrixToHdf5SignedDataTypeTest, Check) { { H5::H5File fhandle(fpath, H5F_ACC_TRUNC); auto mhandle = fhandle.createGroup("matrix"); - tatami_hdf5::WriteSparseMatrixToHdf5Parameters params; + tatami_hdf5::WriteCompressedSparseMatrixOptions params; params.num_threads = nthreads; - tatami_hdf5::write_sparse_matrix_to_hdf5(&mat, mhandle, params); + tatami_hdf5::write_compressed_sparse_matrix(&mat, mhandle, params); } // Checking the dumped contents. @@ -317,9 +317,9 @@ TEST_P(WriteSparseMatrixToHdf5SignedDataTypeTest, Check) { H5::IntType dtype(dhandle); EXPECT_EQ(dtype.getSign(), H5T_SGN_2); - if (type == tatami_hdf5::WriteSparseMatrixToHdf5Parameters::StorageType::INT8) { + if (type == tatami_hdf5::WriteStorageType::INT8) { EXPECT_TRUE(dtype.getSize() <= 8); - } else if (type == tatami_hdf5::WriteSparseMatrixToHdf5Parameters::StorageType::INT16) { + } else if (type == tatami_hdf5::WriteStorageType::INT16) { EXPECT_TRUE(dtype.getSize() <= 16); } else { EXPECT_TRUE(dtype.getSize() <= 32); @@ -327,18 +327,18 @@ TEST_P(WriteSparseMatrixToHdf5SignedDataTypeTest, Check) { } // Roundtripping. - auto reloaded = tatami_hdf5::load_hdf5_compressed_sparse_matrix(NR, NC, fpath, "matrix/data", "matrix/indices", "matrix/indptr"); - tatami_test::test_simple_row_access(&reloaded, &mat); + auto reloaded = tatami_hdf5::load_compressed_sparse_matrix(NR, NC, fpath, "matrix/data", "matrix/indices", "matrix/indptr", false); + tatami_test::test_simple_row_access(reloaded.get(), &mat); } INSTANTIATE_TEST_SUITE_P( - WriteSparseMatrixToHdf5, - WriteSparseMatrixToHdf5SignedDataTypeTest, + WriteCompressedSparseMatrix, + WriteCompressedSparseMatrixSignedDataTypeTest, ::testing::Combine( ::testing::Values( - tatami_hdf5::WriteSparseMatrixToHdf5Parameters::StorageType::INT8, - tatami_hdf5::WriteSparseMatrixToHdf5Parameters::StorageType::INT16, - tatami_hdf5::WriteSparseMatrixToHdf5Parameters::StorageType::INT32 + tatami_hdf5::WriteStorageType::INT8, + tatami_hdf5::WriteStorageType::INT16, + tatami_hdf5::WriteStorageType::INT32 ), ::testing::Values(1,3) ) @@ -347,18 +347,18 @@ INSTANTIATE_TEST_SUITE_P( /***************************************** *****************************************/ -class WriteSparseMatrixToHdf5IndexTypeTest : public ::testing::TestWithParam > {}; +class WriteCompressedSparseMatrixIndexTypeTest : public ::testing::TestWithParam > {}; -TEST_P(WriteSparseMatrixToHdf5IndexTypeTest, Check) { +TEST_P(WriteCompressedSparseMatrixIndexTypeTest, Check) { auto params = GetParam(); auto type = std::get<0>(params); auto nthreads = std::get<1>(params); const size_t NC = 10; size_t NR = 200; - if (type == tatami_hdf5::WriteSparseMatrixToHdf5Parameters::StorageType::UINT16) { + if (type == tatami_hdf5::WriteStorageType::UINT16) { NR = 2000; - } else if (type == tatami_hdf5::WriteSparseMatrixToHdf5Parameters::StorageType::UINT32) { + } else if (type == tatami_hdf5::WriteStorageType::UINT32) { NR = 100000; } @@ -370,9 +370,9 @@ TEST_P(WriteSparseMatrixToHdf5IndexTypeTest, Check) { { H5::H5File fhandle(fpath, H5F_ACC_TRUNC); auto mhandle = fhandle.createGroup("matrix"); - tatami_hdf5::WriteSparseMatrixToHdf5Parameters params; + tatami_hdf5::WriteCompressedSparseMatrixOptions params; params.num_threads = nthreads; - tatami_hdf5::write_sparse_matrix_to_hdf5(&mat, mhandle, params); + tatami_hdf5::write_compressed_sparse_matrix(&mat, mhandle, params); } // Checking the dumped contents. @@ -383,9 +383,9 @@ TEST_P(WriteSparseMatrixToHdf5IndexTypeTest, Check) { H5::IntType itype(ihandle); EXPECT_EQ(itype.getSign(), H5T_SGN_NONE); - if (type == tatami_hdf5::WriteSparseMatrixToHdf5Parameters::StorageType::UINT8) { + if (type == tatami_hdf5::WriteStorageType::UINT8) { EXPECT_TRUE(itype.getSize() <= 8); - } else if (type == tatami_hdf5::WriteSparseMatrixToHdf5Parameters::StorageType::UINT16) { + } else if (type == tatami_hdf5::WriteStorageType::UINT16) { EXPECT_TRUE(itype.getSize() <= 16); } else { EXPECT_TRUE(itype.getSize() <= 32); @@ -393,18 +393,18 @@ TEST_P(WriteSparseMatrixToHdf5IndexTypeTest, Check) { } // Roundtripping. - auto reloaded = tatami_hdf5::load_hdf5_compressed_sparse_matrix(NR, NC, fpath, "matrix/data", "matrix/indices", "matrix/indptr"); - tatami_test::test_simple_row_access(&reloaded, &mat); + auto reloaded = tatami_hdf5::load_compressed_sparse_matrix(NR, NC, fpath, "matrix/data", "matrix/indices", "matrix/indptr", false); + tatami_test::test_simple_row_access(reloaded.get(), &mat); } INSTANTIATE_TEST_SUITE_P( - WriteSparseMatrixToHdf5, - WriteSparseMatrixToHdf5IndexTypeTest, + WriteCompressedSparseMatrix, + WriteCompressedSparseMatrixIndexTypeTest, ::testing::Combine( ::testing::Values( - tatami_hdf5::WriteSparseMatrixToHdf5Parameters::StorageType::UINT8, - tatami_hdf5::WriteSparseMatrixToHdf5Parameters::StorageType::UINT16, - tatami_hdf5::WriteSparseMatrixToHdf5Parameters::StorageType::UINT32 + tatami_hdf5::WriteStorageType::UINT8, + tatami_hdf5::WriteStorageType::UINT16, + tatami_hdf5::WriteStorageType::UINT32 ), ::testing::Values(1,3) )