From 120546e5a7e7de5e52ffd2a8cd423ccf25fe5621 Mon Sep 17 00:00:00 2001 From: LTLA Date: Thu, 3 Oct 2024 16:44:27 -0700 Subject: [PATCH] Shifted row= and parallel= to regular arguments in a Options class. This is easier to use and aligns with new tatami interface where the row/column layout is specified in the constructor. The Options class avoids having too many default arguments in the function signature. --- include/tatami_mtx/load_matrix.hpp | 260 ++++++++++++++++------------- tests/src/load_matrix.cpp | 103 +++++++++--- 2 files changed, 226 insertions(+), 137 deletions(-) diff --git a/include/tatami_mtx/load_matrix.hpp b/include/tatami_mtx/load_matrix.hpp index aab6a90..7d3a297 100644 --- a/include/tatami_mtx/load_matrix.hpp +++ b/include/tatami_mtx/load_matrix.hpp @@ -19,15 +19,47 @@ namespace tatami_mtx { */ struct Automatic {}; +/** + * @brief Options for `load_matrix()` and friends. + */ +struct Options { + /** + * Whether to produce a dense row-major or compressed sparse row matrix. + * If false, column-based matrices are returned instead. + */ + bool row = true; + + /** + * Size of the buffer (in bytes) to use when reading the file contents. + * This buffer size is also used for Gzip/Zlib decompression. + * Ignored for `load_matrix_from_text_buffer()`. + */ + size_t buffer_size = 65536; + + /** + * Whether to parallelize the reading and parsing. + * If true, chunks of the file are read (and decompressed) in one thread while the contents are parsed in another thread. + */ + bool parallel = false; + + /** + * Compression of a Zlib-compressed buffer in `load_matrix_from_zlib_buffer()`. + * The default of 3 will auto-detect the compression method, see `byteme::ZlibBufferReader` for details. + */ + int compression = 3; +}; + /** * @cond */ -template -std::shared_ptr > load_sparse_matrix_basic(Parser_& parser, eminem::Field field, size_t NR, size_t NC, size_t NL) { +namespace internal { + +template +std::shared_ptr > load_sparse_matrix_basic(Parser_& parser, eminem::Field field, size_t NR, size_t NC, size_t NL) { std::vector::type> rows; std::vector::type> columns; rows.reserve(NL), columns.reserve(NL); - std::vector values; + std::vector values; values.reserve(NL); if (field == eminem::Field::INTEGER) { @@ -56,57 +88,51 @@ std::shared_ptr > load_sparse_matrix_basic(Parser_ indices.swap(rows); } - return std::shared_ptr >( - new tatami::CompressedSparseMatrix( - NR, NC, std::move(values), std::move(indices), std::move(ptr), false + return std::shared_ptr >( + new tatami::CompressedSparseMatrix( + NR, NC, std::move(values), std::move(indices), std::move(ptr), row_, false ) ); } -template -std::shared_ptr > load_sparse_matrix_data(Parser_& parser, eminem::Field field, size_t NR, size_t NC, size_t NL) { - if constexpr(std::is_same::value) { +template +std::shared_ptr > load_sparse_matrix_data(Parser_& parser, eminem::Field field, size_t NR, size_t NC, size_t NL) { + if constexpr(std::is_same::value) { if (field == eminem::Field::REAL || field == eminem::Field::DOUBLE) { - return load_sparse_matrix_basic(parser, field, NR, NC, NL); + return load_sparse_matrix_basic(parser, field, NR, NC, NL); } if (field != eminem::Field::INTEGER) { throw std::runtime_error("unsupported Matrix Market field type"); } - return load_sparse_matrix_basic(parser, field, NR, NC, NL); + return load_sparse_matrix_basic(parser, field, NR, NC, NL); } else { - return load_sparse_matrix_basic(parser, field, NR, NC, NL); + return load_sparse_matrix_basic(parser, field, NR, NC, NL); } } -template -std::shared_ptr > load_sparse_matrix_index(Parser_& parser, eminem::Field field, size_t NR, size_t NC, size_t NL) { +template +std::shared_ptr > load_sparse_matrix_index(Parser_& parser, eminem::Field field, size_t NR, size_t NC, size_t NL) { if constexpr(std::is_same::value) { // Automatically choosing a smaller integer type, if it fits. constexpr size_t limit8 = std::numeric_limits::max(), limit16 = std::numeric_limits::max(); size_t target = (row_ ? NC : NR); if (target <= limit8) { - return load_sparse_matrix_data(parser, field, NR, NC, NL); + return load_sparse_matrix_data(parser, field, NR, NC, NL); } else if (target <= limit16) { - return load_sparse_matrix_data(parser, field, NR, NC, NL); + return load_sparse_matrix_data(parser, field, NR, NC, NL); } else { - return load_sparse_matrix_data(parser, field, NR, NC, NL); + return load_sparse_matrix_data(parser, field, NR, NC, NL); } } else { - return load_sparse_matrix_data(parser, field, NR, NC, NL); + return load_sparse_matrix_data(parser, field, NR, NC, NL); } } -/** - * @endcond - */ -/** - * @cond - */ -template -std::shared_ptr > load_dense_matrix_basic(Parser_& parser, eminem::Field field, size_t NR, size_t NC) { - std::vector values; +template +std::shared_ptr > load_dense_matrix_basic(Parser_& parser, eminem::Field field, size_t NR, size_t NC) { + std::vector values; if constexpr(row_) { values.resize(NR * NC); } else { @@ -135,67 +161,85 @@ std::shared_ptr > load_dense_matrix_basic(Parser_& throw std::runtime_error("unsupported Matrix Market field type"); } - return std::shared_ptr >( - new tatami::DenseMatrix(NR, NC, std::move(values)) + return std::shared_ptr >( + new tatami::DenseMatrix(NR, NC, std::move(values), row_) ); } -/** - * @endcond - */ -/** - * Load a `tatami::Matrix` from a Matrix Market file. - * Coordinate formats will yield a sparse matrix, while array formats will yield a dense matrix. - * The storage types depend on the Matrix Market field type as well as the settings of `StoredData_` and `StoredIndex_`. - * - * @tparam row_ Whether to produce a dense row-major or compressed sparse row matrix. - * If `false`, column-based matrices are returned instead. - * @tparam Data_ Data type for the `tatami::Matrix` interface. - * @tparam Index_ Integer index type for the `tatami::Matrix` interface. - * @tparam StoredData_ Matrix data type that is stored in memory. - * If set to `Automatic`, it defaults to `double` for real/double fields and `int` for integer fields. - * @tparam StoredIndex_ Index data type that is stored in memory for sparse matrices. - * If set to `Automatic`, it defaults to `uint8_t` if no dimension is greater than 255; `uint16_t` if no dimension is greater than 65536; and `int` otherwise. - * @tparam parallel_ Whether to parallelize the loading and parsing. - * - * @param reader A `byteme::Reader` instance containing bytes from a Matrix Market file. - * - * @return Pointer to a `tatami::Matrix` instance containing data from the Matrix Market file. - */ -template -std::shared_ptr > load_matrix(byteme::Reader& reader) { +template +std::shared_ptr > load_matrix(byteme::Reader& reader) { eminem::Parser parser(&reader); parser.scan_preamble(); const auto& banner = parser.get_banner(); auto field = banner.field; + auto format = banner.format; size_t NR = parser.get_nrows(), NC = parser.get_ncols(), NL = parser.get_nlines(); - if (banner.format == eminem::Format::COORDINATE) { + if (format == eminem::Format::COORDINATE) { // Automatically choosing a smaller integer type for the temporary index. constexpr size_t limit8 = std::numeric_limits::max(), limit16 = std::numeric_limits::max(); auto primary = (row_ ? NR : NC); if (primary <= limit8) { - return load_sparse_matrix_index(parser, field, NR, NC, NL); + return load_sparse_matrix_index(parser, field, NR, NC, NL); } else if (primary <= limit16) { - return load_sparse_matrix_index(parser, field, NR, NC, NL); + return load_sparse_matrix_index(parser, field, NR, NC, NL); } else { - return load_sparse_matrix_index(parser, field, NR, NC, NL); + return load_sparse_matrix_index(parser, field, NR, NC, NL); } } else { - if constexpr(std::is_same::value) { + if constexpr(std::is_same::value) { if (field == eminem::Field::REAL || field == eminem::Field::DOUBLE) { - return load_dense_matrix_basic(parser, field, NR, NC); + return load_dense_matrix_basic(parser, field, NR, NC); } if (field != eminem::Field::INTEGER) { throw std::runtime_error("unsupported Matrix Market field type"); } - return load_dense_matrix_basic(parser, field, NR, NC); + return load_dense_matrix_basic(parser, field, NR, NC); + + } else { + return load_dense_matrix_basic(parser, field, NR, NC); + } + } +} + +} +/** + * @endcond + */ +/** + * Load a `tatami::Matrix` from a Matrix Market file. + * Coordinate formats will yield a sparse matrix, while array formats will yield a dense matrix. + * The storage types depend on the Matrix Market field type as well as the settings of `StoredValue_` and `StoredIndex_`. + * + * @tparam Value_ Data type for the `tatami::Matrix` interface. + * @tparam Index_ Integer index type for the `tatami::Matrix` interface. + * @tparam StoredValue_ Matrix data type that is stored in memory. + * If set to `Automatic`, it defaults to `double` for real/double fields and `int` for integer fields. + * @tparam StoredIndex_ Index data type that is stored in memory for sparse matrices. + * If set to `Automatic`, it defaults to `uint8_t` if no dimension is greater than 255; `uint16_t` if no dimension is greater than 65536; and `int` otherwise. + * + * @param reader A `byteme::Reader` instance containing bytes from a Matrix Market file. + * @param options Options for loading the matrix. + * + * @return Pointer to a `tatami::Matrix` instance containing data from the Matrix Market file. + */ +template +std::shared_ptr > load_matrix(byteme::Reader& reader, const Options& options) { + if (options.row) { + if (options.parallel) { + return internal::load_matrix(reader); + } else { + return internal::load_matrix(reader); + } + } else { + if (options.parallel) { + return internal::load_matrix(reader); } else { - return load_dense_matrix_basic(parser, field, NR, NC); + return internal::load_matrix(reader); } } } @@ -203,22 +247,21 @@ std::shared_ptr > load_matrix(byteme::Reader& read /** * Load a `tatami::Matrix` from a Matrix Market text file, see `load_matrix()` for details. * - * @tparam row_ Whether to produce a row-based matrix, see `load_matrix()` for details. - * @tparam Data_ Data type for the `tatami::Matrix` interface. + * @tparam Value_ Data type for the `tatami::Matrix` interface. * @tparam Index_ Integer index type for the `tatami::Matrix` interface. - * @tparam StoredData_ Matrix data type that is stored in memory, see `load_matrix()` for details. + * @tparam StoredValue_ Matrix data type that is stored in memory, see `load_matrix()` for details. * @tparam StoredIndex_ Index data type that is stored in memory for sparse matrices, see `load_matrix()` for details. * @tparam parallel_ Whether to parallelize the loading and parsing. * * @param filepath Path to a Matrix Market file. - * @param bufsize Size of the buffer (in bytes) to use when reading from file. + * @param options Options for loading the matrix. * * @return Pointer to a `tatami::Matrix` instance containing data from the Matrix Market file. */ -template -std::shared_ptr > load_matrix_from_text_file(const char* filepath, size_t bufsize = 65536) { - byteme::RawFileReader reader(filepath, bufsize); - return load_matrix(reader); +template +std::shared_ptr > load_matrix_from_text_file(const char* filepath, const Options& options) { + byteme::RawFileReader reader(filepath, options.buffer_size); + return load_matrix(reader, options); } #if __has_include("zlib.h") @@ -226,43 +269,39 @@ std::shared_ptr > load_matrix_from_text_file(const /** * Load a `tatami::Matrix` from a Gzip-compressed Matrix Market file, see `load_matrix()` for details. * - * @tparam row_ Whether to produce a row-based matrix, see `load_matrix()` for details. - * @tparam Data_ Data type for the `tatami::Matrix` interface. + * @tparam Value_ Data type for the `tatami::Matrix` interface. * @tparam Index_ Integer index type for the `tatami::Matrix` interface. - * @tparam StoredData_ Matrix data type that is stored in memory, see `load_matrix()` for details. + * @tparam StoredValue_ Matrix data type that is stored in memory, see `load_matrix()` for details. * @tparam StoredIndex_ Index data type that is stored in memory for sparse matrices, see `load_matrix()` for details. - * @tparam parallel_ Whether to parallelize the loading and parsing. * * @param filepath Path to a Matrix Market file. - * @param bufsize Size of the buffer (in bytes) to use when reading from file. + * @param options Options for loading the matrix. * * @return Pointer to a `tatami::Matrix` instance containing data from the Matrix Market file. */ -template -std::shared_ptr > load_matrix_from_gzip_file(const char* filepath, size_t bufsize = 65536) { - byteme::GzipFileReader reader(filepath, bufsize); - return load_matrix(reader); +template +std::shared_ptr > load_matrix_from_gzip_file(const char* filepath, const Options& options) { + byteme::GzipFileReader reader(filepath, options.buffer_size); + return load_matrix(reader, options); } /** * Load a `tatami::Matrix` from a possibly Gzip-compressed Matrix Market file, see `load_matrix()` for details. * - * @tparam row_ Whether to produce a row-based matrix, see `load_matrix()` for details. - * @tparam Data_ Data type for the `tatami::Matrix` interface. + * @tparam Value_ Data type for the `tatami::Matrix` interface. * @tparam Index_ Integer index type for the `tatami::Matrix` interface. - * @tparam StoredData_ Matrix data type that is stored in memory, see `load_matrix()` for details. + * @tparam StoredValue_ Matrix data type that is stored in memory, see `load_matrix()` for details. * @tparam StoredIndex_ Index data type that is stored in memory for sparse matrices, see `load_matrix()` for details. - * @tparam parallel_ Whether to parallelize the loading and parsing. * * @param filepath Path to a Matrix Market file. - * @param bufsize Size of the buffer (in bytes) to use when reading from file. + * @param options Options for loading the matrix. * * @return Pointer to a `tatami::Matrix` instance containing data from the Matrix Market file. */ -template -std::shared_ptr > load_matrix_from_some_file(const char* filepath, size_t bufsize = 65536) { - byteme::SomeFileReader reader(filepath, bufsize); - return load_matrix(reader); +template +std::shared_ptr > load_matrix_from_some_file(const char* filepath, const Options& options) { + byteme::SomeFileReader reader(filepath, options.buffer_size); + return load_matrix(reader, options); } #endif @@ -270,22 +309,21 @@ std::shared_ptr > load_matrix_from_some_file(const /** * Load a `tatami::Matrix` from a buffer containing a Matrix Market file, see `load_matrix()` for details. * - * @tparam row_ Whether to produce a row-based matrix, see `load_matrix()` for details. - * @tparam Data_ Data type for the `tatami::Matrix` interface. + * @tparam Value_ Data type for the `tatami::Matrix` interface. * @tparam Index_ Integer index type for the `tatami::Matrix` interface. - * @tparam StoredData_ Matrix data type that is stored in memory, see `load_matrix()` for details. + * @tparam StoredValue_ Matrix data type that is stored in memory, see `load_matrix()` for details. * @tparam StoredIndex_ Index data type that is stored in memory for sparse matrices, see `load_matrix()` for details. - * @tparam parallel_ Whether to parallelize the loading and parsing. * * @param buffer Array containing the contents of an uncompressed Matrix Market file. * @param n Length of the array. + * @param options Options for loading the matrix. * * @return Pointer to a `tatami::Matrix` instance containing data from the Matrix Market file. */ -template -std::shared_ptr > load_matrix_from_text_buffer(const unsigned char* buffer, size_t n) { +template +std::shared_ptr > load_matrix_from_text_buffer(const unsigned char* buffer, size_t n, const Options& options) { byteme::RawBufferReader reader(buffer, n); - return load_matrix(reader); + return load_matrix(reader, options); } #if __has_include("zlib.h") @@ -293,47 +331,41 @@ std::shared_ptr > load_matrix_from_text_buffer(con /** * Load a `tatami::Matrix` from a buffer containing a Gzip/Zlib-compressed Matrix Market file, see `load_matrix()` for details. * - * @tparam row_ Whether to produce a row-based matrix, see `load_matrix()` for details. - * @tparam Data_ Data type for the `tatami::Matrix` interface. + * @tparam Value_ Data type for the `tatami::Matrix` interface. * @tparam Index_ Integer index type for the `tatami::Matrix` interface. - * @tparam StoredData_ Matrix data type that is stored in memory, see `load_matrix()` for details. + * @tparam StoredValue_ Matrix data type that is stored in memory, see `load_matrix()` for details. * @tparam StoredIndex_ Index data type that is stored in memory for sparse matrices, see `load_matrix()` for details. - * @tparam parallel_ Whether to parallelize the loading and parsing. * * @param buffer Array containing the contents of a Matrix Market file after Gzip/Zlib compression. * @param n Length of the array. - * @param compression Compression of the stream - DEFLATE (0), Zlib (1) or Gzip (2). - * Default of 3 will auto-detect between Zlib and Gzip based on the headers. - * @param bufsize Size of the buffer (in bytes) to use when decompressing the file contents. + * @param options Options for loading the matrix. * * @return Pointer to a `tatami::Matrix` instance containing data from the Matrix Market file. */ -template -std::shared_ptr > load_matrix_from_zlib_buffer(const unsigned char* buffer, size_t n, int compression = 3, size_t bufsize = 65536) { - byteme::ZlibBufferReader reader(buffer, n, compression, bufsize); - return load_matrix(reader); +template +std::shared_ptr > load_matrix_from_zlib_buffer(const unsigned char* buffer, size_t n, const Options& options) { + byteme::ZlibBufferReader reader(buffer, n, options.compression, options.buffer_size); + return load_matrix(reader, options); } /** * Load a `tatami::Matrix` from a buffer containing a possibly Gzip/Zlib-compressed Matrix Market file, see `load_matrix()` for details. * - * @tparam row_ Whether to produce a row-based matrix, see `load_matrix()` for details. - * @tparam Data_ Data type for the `tatami::Matrix` interface. + * @tparam Value_ Data type for the `tatami::Matrix` interface. * @tparam Index_ Integer index type for the `tatami::Matrix` interface. - * @tparam StoredData_ Matrix data type that is stored in memory, see `load_matrix()` for details. + * @tparam StoredValue_ Matrix data type that is stored in memory, see `load_matrix()` for details. * @tparam StoredIndex_ Index data type that is stored in memory for sparse matrices, see `load_matrix()` for details. - * @tparam parallel_ Whether to parallelize the loading and parsing. * * @param buffer Array containing the contents of a Matrix Market file, possibly after Gzip/Zlib compression. * @param n Length of the array. - * @param bufsize Size of the buffer (in bytes) to use when decompressing the file contents. + * @param options Options for loading the matrix. * * @return Pointer to a `tatami::Matrix` instance containing data from the Matrix Market file. */ -template -std::shared_ptr > load_matrix_from_some_buffer(const unsigned char* buffer, size_t n, size_t bufsize = 65536) { - byteme::SomeBufferReader reader(buffer, n, bufsize); - return load_matrix(reader); +template +std::shared_ptr > load_matrix_from_some_buffer(const unsigned char* buffer, size_t n, const Options& options) { + byteme::SomeBufferReader reader(buffer, n, options.buffer_size); + return load_matrix(reader, options); } #endif diff --git a/tests/src/load_matrix.cpp b/tests/src/load_matrix.cpp index c725b4a..c787147 100644 --- a/tests/src/load_matrix.cpp +++ b/tests/src/load_matrix.cpp @@ -117,9 +117,12 @@ TEST_F(LoadMatrixInputTest, SimpleBuffer) { write_coordinate(writer); const auto& buffer = writer.output; + tatami_mtx::Options opt; + opt.row = false; + // Uncompressed. { - auto out = tatami_mtx::load_matrix_from_text_buffer(buffer.data(), buffer.size()); + auto out = tatami_mtx::load_matrix_from_text_buffer(buffer.data(), buffer.size(), opt); EXPECT_FALSE(out->prefer_rows()); EXPECT_TRUE(out->sparse()); tatami_test::test_simple_row_access(out.get(), ref.get()); @@ -128,7 +131,7 @@ TEST_F(LoadMatrixInputTest, SimpleBuffer) { // Automatic. { - auto out = tatami_mtx::load_matrix_from_some_buffer(buffer.data(), buffer.size()); + auto out = tatami_mtx::load_matrix_from_some_buffer(buffer.data(), buffer.size(), opt); EXPECT_FALSE(out->prefer_rows()); EXPECT_TRUE(out->sparse()); tatami_test::test_simple_row_access(out.get(), ref.get()); @@ -143,9 +146,12 @@ TEST_F(LoadMatrixInputTest, SimpleText) { byteme::RawFileWriter writer(path.c_str()); write_coordinate(writer); + tatami_mtx::Options opt; + opt.row = true; + // Uncompressed. { - auto out = tatami_mtx::load_matrix_from_text_file(path.c_str()); + auto out = tatami_mtx::load_matrix_from_text_file(path.c_str(), opt); EXPECT_TRUE(out->prefer_rows()); EXPECT_TRUE(out->sparse()); tatami_test::test_simple_row_access(out.get(), ref.get()); @@ -154,7 +160,7 @@ TEST_F(LoadMatrixInputTest, SimpleText) { // Automatic. { - auto out = tatami_mtx::load_matrix_from_some_file(path.c_str()); + auto out = tatami_mtx::load_matrix_from_some_file(path.c_str(), opt); EXPECT_TRUE(out->prefer_rows()); EXPECT_TRUE(out->sparse()); tatami_test::test_simple_row_access(out.get(), ref.get()); @@ -169,9 +175,12 @@ TEST_F(LoadMatrixInputTest, ZlibBuffer) { write_coordinate(writer); const auto& buffer = writer.output; + tatami_mtx::Options opt; + opt.row = false; + // Compressed. { - auto out = tatami_mtx::load_matrix_from_zlib_buffer(buffer.data(), buffer.size()); + auto out = tatami_mtx::load_matrix_from_zlib_buffer(buffer.data(), buffer.size(), opt); EXPECT_FALSE(out->prefer_rows()); EXPECT_TRUE(out->sparse()); tatami_test::test_simple_row_access(out.get(), ref.get()); @@ -180,7 +189,7 @@ TEST_F(LoadMatrixInputTest, ZlibBuffer) { // Automatic. { - auto out = tatami_mtx::load_matrix_from_some_buffer(buffer.data(), buffer.size()); + auto out = tatami_mtx::load_matrix_from_some_buffer(buffer.data(), buffer.size(), opt); EXPECT_FALSE(out->prefer_rows()); EXPECT_TRUE(out->sparse()); tatami_test::test_simple_row_access(out.get(), ref.get()); @@ -195,9 +204,12 @@ TEST_F(LoadMatrixInputTest, GzipFile) { byteme::GzipFileWriter writer(path.c_str()); write_coordinate(writer); + tatami_mtx::Options opt; + opt.row = true; + // Compressed. { - auto out = tatami_mtx::load_matrix_from_gzip_file(path.c_str()); + auto out = tatami_mtx::load_matrix_from_gzip_file(path.c_str(), opt); EXPECT_TRUE(out->prefer_rows()); EXPECT_TRUE(out->sparse()); tatami_test::test_simple_row_access(out.get(), ref.get()); @@ -206,7 +218,7 @@ TEST_F(LoadMatrixInputTest, GzipFile) { // Automatic. { - auto out = tatami_mtx::load_matrix_from_some_file(path.c_str()); + auto out = tatami_mtx::load_matrix_from_some_file(path.c_str(), opt); EXPECT_TRUE(out->prefer_rows()); EXPECT_TRUE(out->sparse()); tatami_test::test_simple_row_access(out.get(), ref.get()); @@ -227,7 +239,10 @@ TEST_F(LoadMatrixIndexTest, Index8) { write_coordinate(writer); const auto& buffer = writer.output; - auto out = tatami_mtx::load_matrix_from_text_buffer(buffer.data(), buffer.size()); + tatami_mtx::Options opt; + opt.row = false; + + auto out = tatami_mtx::load_matrix_from_text_buffer(buffer.data(), buffer.size(), opt); EXPECT_FALSE(out->prefer_rows()); EXPECT_TRUE(out->sparse()); tatami_test::test_simple_row_access(out.get(), ref.get()); @@ -241,7 +256,10 @@ TEST_F(LoadMatrixIndexTest, Index16) { write_coordinate(writer); const auto& buffer = writer.output; - auto out = tatami_mtx::load_matrix_from_text_buffer(buffer.data(), buffer.size()); + tatami_mtx::Options opt; + opt.row = false; + + auto out = tatami_mtx::load_matrix_from_text_buffer(buffer.data(), buffer.size(), opt); EXPECT_FALSE(out->prefer_rows()); EXPECT_TRUE(out->sparse()); tatami_test::test_simple_row_access(out.get(), ref.get()); @@ -255,7 +273,10 @@ TEST_F(LoadMatrixIndexTest, Index32) { write_coordinate(writer); const auto& buffer = writer.output; - auto out = tatami_mtx::load_matrix_from_text_buffer(buffer.data(), buffer.size()); + tatami_mtx::Options opt; + opt.row = false; + + auto out = tatami_mtx::load_matrix_from_text_buffer(buffer.data(), buffer.size(), opt); EXPECT_FALSE(out->prefer_rows()); EXPECT_TRUE(out->sparse()); tatami_test::test_simple_row_access(out.get(), ref.get()); @@ -269,7 +290,10 @@ TEST_F(LoadMatrixIndexTest, IndexCustom) { write_coordinate(writer); const auto& buffer = writer.output; - auto out = tatami_mtx::load_matrix_from_text_buffer(buffer.data(), buffer.size()); + tatami_mtx::Options opt; + opt.row = false; + + auto out = tatami_mtx::load_matrix_from_text_buffer(buffer.data(), buffer.size(), opt); EXPECT_FALSE(out->prefer_rows()); EXPECT_TRUE(out->sparse()); tatami_test::test_simple_row_access(out.get(), ref.get()); @@ -287,7 +311,10 @@ TEST_F(LoadMatrixIndexTest, TempIndex8) { write_coordinate(writer); const auto& buffer = writer.output; - auto out = tatami_mtx::load_matrix_from_text_buffer(buffer.data(), buffer.size()); + tatami_mtx::Options opt; + opt.row = true; + + auto out = tatami_mtx::load_matrix_from_text_buffer(buffer.data(), buffer.size(), opt); EXPECT_TRUE(out->prefer_rows()); EXPECT_TRUE(out->sparse()); tatami_test::test_simple_row_access(out.get(), ref.get()); @@ -301,7 +328,10 @@ TEST_F(LoadMatrixIndexTest, TempIndex16) { write_coordinate(writer); const auto& buffer = writer.output; - auto out = tatami_mtx::load_matrix_from_text_buffer(buffer.data(), buffer.size()); + tatami_mtx::Options opt; + opt.row = true; + + auto out = tatami_mtx::load_matrix_from_text_buffer(buffer.data(), buffer.size(), opt); EXPECT_TRUE(out->prefer_rows()); EXPECT_TRUE(out->sparse()); tatami_test::test_simple_row_access(out.get(), ref.get()); @@ -315,7 +345,10 @@ TEST_F(LoadMatrixIndexTest, TempIndex32) { write_coordinate(writer); const auto& buffer = writer.output; - auto out = tatami_mtx::load_matrix_from_text_buffer(buffer.data(), buffer.size()); + tatami_mtx::Options opt; + opt.row = true; + + auto out = tatami_mtx::load_matrix_from_text_buffer(buffer.data(), buffer.size(), opt); EXPECT_TRUE(out->prefer_rows()); EXPECT_TRUE(out->sparse()); tatami_test::test_simple_row_access(out.get(), ref.get()); @@ -335,7 +368,10 @@ TEST_F(LoadMatrixIntegerTypeTest, CoordinateAutomatic) { write_coordinate(writer); const auto& buffer = writer.output; - auto out = tatami_mtx::load_matrix_from_text_buffer(buffer.data(), buffer.size()); + tatami_mtx::Options opt; + opt.row = true; + + auto out = tatami_mtx::load_matrix_from_text_buffer(buffer.data(), buffer.size(), opt); EXPECT_TRUE(out->prefer_rows()); EXPECT_TRUE(out->sparse()); tatami_test::test_simple_row_access(out.get(), ref.get()); @@ -349,7 +385,10 @@ TEST_F(LoadMatrixIntegerTypeTest, CoordinateCustom) { write_coordinate(writer); const auto& buffer = writer.output; - auto out = tatami_mtx::load_matrix_from_text_buffer(buffer.data(), buffer.size()); + tatami_mtx::Options opt; + opt.row = false; + + auto out = tatami_mtx::load_matrix_from_text_buffer(buffer.data(), buffer.size(), opt); EXPECT_FALSE(out->prefer_rows()); EXPECT_TRUE(out->sparse()); tatami_test::test_simple_row_access(out.get(), ref.get()); @@ -363,7 +402,10 @@ TEST_F(LoadMatrixIntegerTypeTest, ArrayAutomatic) { write_array(writer); const auto& buffer = writer.output; - auto out = tatami_mtx::load_matrix_from_text_buffer(buffer.data(), buffer.size()); + tatami_mtx::Options opt; + opt.row = true; + + auto out = tatami_mtx::load_matrix_from_text_buffer(buffer.data(), buffer.size(), opt); EXPECT_TRUE(out->prefer_rows()); EXPECT_FALSE(out->sparse()); tatami_test::test_simple_row_access(out.get(), ref.get()); @@ -377,7 +419,10 @@ TEST_F(LoadMatrixIntegerTypeTest, ArrayCustom) { write_array(writer); const auto& buffer = writer.output; - auto out = tatami_mtx::load_matrix_from_text_buffer(buffer.data(), buffer.size()); + tatami_mtx::Options opt; + opt.row = false; + + auto out = tatami_mtx::load_matrix_from_text_buffer(buffer.data(), buffer.size(), opt); EXPECT_FALSE(out->prefer_rows()); EXPECT_FALSE(out->sparse()); tatami_test::test_simple_row_access(out.get(), ref.get()); @@ -397,7 +442,10 @@ TEST_F(LoadMatrixFloatTypeTest, CoordinateAutomatic) { write_coordinate(writer); const auto& buffer = writer.output; - auto out = tatami_mtx::load_matrix_from_text_buffer(buffer.data(), buffer.size()); + tatami_mtx::Options opt; + opt.row = true; + + auto out = tatami_mtx::load_matrix_from_text_buffer(buffer.data(), buffer.size(), opt); EXPECT_TRUE(out->prefer_rows()); EXPECT_TRUE(out->sparse()); tatami_test::test_simple_row_access(out.get(), ref.get()); @@ -411,7 +459,10 @@ TEST_F(LoadMatrixFloatTypeTest, CoordinateCustom) { write_coordinate(writer); const auto& buffer = writer.output; - auto out = tatami_mtx::load_matrix_from_text_buffer(buffer.data(), buffer.size()); + tatami_mtx::Options opt; + opt.row = false; + + auto out = tatami_mtx::load_matrix_from_text_buffer(buffer.data(), buffer.size(), opt); EXPECT_FALSE(out->prefer_rows()); EXPECT_TRUE(out->sparse()); tatami_test::test_simple_row_access(out.get(), ref.get()); @@ -425,7 +476,10 @@ TEST_F(LoadMatrixFloatTypeTest, ArrayAutomatic) { write_array(writer); const auto& buffer = writer.output; - auto out = tatami_mtx::load_matrix_from_text_buffer(buffer.data(), buffer.size()); + tatami_mtx::Options opt; + opt.row = true; + + auto out = tatami_mtx::load_matrix_from_text_buffer(buffer.data(), buffer.size(), opt); EXPECT_TRUE(out->prefer_rows()); EXPECT_FALSE(out->sparse()); tatami_test::test_simple_row_access(out.get(), ref.get()); @@ -439,7 +493,10 @@ TEST_F(LoadMatrixFloatTypeTest, ArrayCustom) { write_array(writer); const auto& buffer = writer.output; - auto out = tatami_mtx::load_matrix_from_text_buffer(buffer.data(), buffer.size()); + tatami_mtx::Options opt; + opt.row = false; + + auto out = tatami_mtx::load_matrix_from_text_buffer(buffer.data(), buffer.size(), opt); EXPECT_FALSE(out->prefer_rows()); EXPECT_FALSE(out->sparse()); tatami_test::test_simple_row_access(out.get(), ref.get());