Skip to content

Commit

Permalink
Shift the uncached analysis to a separate test suite.
Browse files Browse the repository at this point in the history
  • Loading branch information
LTLA committed Sep 24, 2024
1 parent 563e44a commit 1c43ef3
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 46 deletions.
69 changes: 47 additions & 22 deletions tests/src/DenseMatrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,16 @@ class DenseMatrixTestCore {
public:
static constexpr size_t NR = 200, NC = 100;

typedef std::tuple<std::pair<int, int>, double> SimulationParameters;
typedef std::pair<int, int> SimulationParameters;

inline static SimulationParameters last_params;

public:
static auto create_combinations() {
return ::testing::Combine(
::testing::Values(
std::pair<int, int>(NR, 1),
std::pair<int, int>(1, NC),
std::make_pair(7, 7) // using tile sizes that are a little odd to check for off-by-one errors.
),
::testing::Values(0, 0.1) // cache fraction multiplier
return ::testing::Values(
std::pair<int, int>(NR, 1),
std::pair<int, int>(1, NC),
std::make_pair(7, 7) // using tile sizes that are a little odd to check for off-by-one errors.
);
}

Expand All @@ -35,9 +32,6 @@ class DenseMatrixTestCore {
}
last_params = params;

auto tile_sizes = std::get<0>(params);
auto cache_fraction = std::get<1>(params);

fpath = tatami_test::temp_file_path("tatami-dense-test");
tatami_test::remove_file_path(fpath);
name = "stuff";
Expand All @@ -47,8 +41,8 @@ class DenseMatrixTestCore {

// Adding some non-trivial offsets so that life remains a bit interesting.
tiledb::Domain domain(ctx);
domain.add_dimension(tiledb::Dimension::create<int>(ctx, "rows", {{10, NR + 10 - 1}}, tile_sizes.first));
domain.add_dimension(tiledb::Dimension::create<int>(ctx, "cols", {{5, NC + 5 - 1}}, tile_sizes.second));
domain.add_dimension(tiledb::Dimension::create<int>(ctx, "rows", {{10, NR + 10 - 1}}, params.first));
domain.add_dimension(tiledb::Dimension::create<int>(ctx, "cols", {{5, NC + 5 - 1}}, params.second));

tiledb::ArraySchema schema(ctx, TILEDB_DENSE);
schema.set_domain(domain);
Expand All @@ -68,8 +62,8 @@ class DenseMatrixTestCore {
// Don't construct a static tiledb matrix here, as the destructor doesn't get called when GoogleTest exits via _exit
// (see https://stackoverflow.com/questions/12728535/will-global-static-variables-be-destroyed-at-program-end)
// resulting in errors due to unjoined threads in the undestructed TileDB Context.
opt.maximum_cache_size = static_cast<double>(NR * NC) * cache_fraction * static_cast<double>(sizeof(double));
opt.require_minimum_cache = (cache_fraction > 0);
opt.maximum_cache_size = static_cast<double>(NR * NC) * 0.1 * static_cast<double>(sizeof(double));
opt.require_minimum_cache = true;

ref.reset(new tatami::DenseRowMatrix<double, int>(NR, NC, std::move(values)));

Expand All @@ -84,7 +78,7 @@ class DenseMatrixTestCore {
class DenseUtilsTest : public ::testing::Test, public DenseMatrixTestCore {};

TEST_F(DenseUtilsTest, Basic) {
assemble(std::make_pair(std::make_pair<int, int>(10, 10), 0));
assemble({ 10, 10 });
std::shared_ptr<tatami::Matrix<double, int> > mat(new tatami_tiledb::DenseMatrix<double, int>(fpath, name, opt));

EXPECT_EQ(mat->nrow(), NR);
Expand All @@ -96,14 +90,14 @@ TEST_F(DenseUtilsTest, Basic) {

{
// First dimension is compromised, switching to the second dimension.
assemble(std::make_pair(std::make_pair<int, int>(NR, 1), 0));
assemble({ NR, 1 });
std::shared_ptr<tatami::Matrix<double, int> > mat(new tatami_tiledb::DenseMatrix<double, int>(fpath, name, opt));
EXPECT_FALSE(mat->prefer_rows());
}

{
// Second dimension is compromised, but we just use the first anyway.
assemble(std::make_pair(std::make_pair<int, int>(1, NC), 0));
assemble({ 1, NC });
std::shared_ptr<tatami::Matrix<double, int> > mat(new tatami_tiledb::DenseMatrix<double, int>(fpath, name, opt));
EXPECT_TRUE(mat->prefer_rows());
}
Expand Down Expand Up @@ -240,13 +234,47 @@ INSTANTIATE_TEST_SUITE_P(
)
);

/*************************************
*************************************/

class DenseUncachedTest :
public ::testing::TestWithParam<tatami_test::StandardTestAccessParameters>,
public DenseMatrixTestCore {
protected:
void SetUp() {
assemble({ 10, 10 });
}
};

TEST_P(DenseUncachedTest, Basic) {
tatami_tiledb::DenseMatrixOptions opt2;
opt2.maximum_cache_size = 0;
opt2.require_minimum_cache = false;
std::shared_ptr<tatami::Matrix<double, int> > mat(new tatami_tiledb::DenseMatrix<double, int>(fpath, name, opt2));

auto params = tatami_test::convert_access_parameters(GetParam());
tatami_test::test_full_access(params, mat.get(), ref.get());

auto len = params.use_row ? ref->ncol() : ref->nrow();
size_t FIRST = len * 0.25, LAST = len * 0.75;
tatami_test::test_block_access(params, mat.get(), ref.get(), FIRST, LAST);

tatami_test::test_indexed_access(params, mat.get(), ref.get(), FIRST, 4);
}

INSTANTIATE_TEST_SUITE_P(
DenseMatrix,
DenseUncachedTest,
tatami_test::standard_test_access_parameter_combinations()
);

/*************************************
*************************************/

class DenseMatrixCachedTypeTest : public ::testing::Test, public DenseMatrixTestCore {
protected:
void SetUp() {
assemble({ { 10, 10 }, 0 });
assemble({ 10, 10 });
}
};

Expand Down Expand Up @@ -285,9 +313,6 @@ class DenseMatrixParallelTest : public ::testing::TestWithParam<std::tuple<Dense
size_t otherdim = (row ? refmat->ncol() : refmat->nrow());
std::vector<double> computed(dim), expected(dim);




tatami::parallelize([&](size_t, int start, int len) -> void {
auto ext = [&]() {
if constexpr(oracle_) {
Expand Down
74 changes: 50 additions & 24 deletions tests/src/SparseMatrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,16 @@ class SparseMatrixTestCore {
public:
static constexpr size_t NR = 200, NC = 100;

typedef std::tuple<std::pair<int, int>, double> SimulationParameters;
typedef std::pair<int, int> SimulationParameters;

inline static SimulationParameters last_params;

public:
static auto create_combinations() {
return ::testing::Combine(
::testing::Values(
std::pair<int, int>(NR, 1),
std::pair<int, int>(1, NC),
std::make_pair(7, 7) // using tile sizes that are a little odd to check for off-by-one errors.
),
::testing::Values(0, 0.1) // cache fraction multiplier
return ::testing::Values(
std::pair<int, int>(NR, 1),
std::pair<int, int>(1, NC),
std::make_pair(7, 7) // using tile sizes that are a little odd to check for off-by-one errors.
);
}

Expand All @@ -35,9 +32,6 @@ class SparseMatrixTestCore {
}
last_params = params;

auto tile_sizes = std::get<0>(params);
auto cache_fraction = std::get<1>(params);

fpath = tatami_test::temp_file_path("tatami-sparse-test");
tatami_test::remove_file_path(fpath);
name = "stuff";
Expand All @@ -49,9 +43,8 @@ class SparseMatrixTestCore {
// Adding some non-trivial offsets so that life remains a bit interesting.
int row_offset = 10;
int col_offset = 5;
domain
.add_dimension(tiledb::Dimension::create<int>(ctx, "rows", {{ row_offset, static_cast<int>(NR) + row_offset - 1 }}, tile_sizes.first))
.add_dimension(tiledb::Dimension::create<int>(ctx, "cols", {{ col_offset, static_cast<int>(NC) + col_offset - 1 }}, tile_sizes.second));
domain.add_dimension(tiledb::Dimension::create<int>(ctx, "rows", {{ row_offset, static_cast<int>(NR) + row_offset - 1 }}, params.first));
domain.add_dimension(tiledb::Dimension::create<int>(ctx, "cols", {{ col_offset, static_cast<int>(NC) + col_offset - 1 }}, params.second));

tiledb::ArraySchema schema(ctx, TILEDB_SPARSE);
schema.set_domain(domain);
Expand All @@ -74,10 +67,9 @@ class SparseMatrixTestCore {
x += col_offset; // see above for the offset on the columns.
}

query
.set_data_buffer(name, contents.value)
.set_data_buffer("rows", coords)
.set_data_buffer("cols", copy);
query.set_data_buffer(name, contents.value);
query.set_data_buffer("rows", coords);
query.set_data_buffer("cols", copy);

query.submit();
query.finalize();
Expand All @@ -86,8 +78,8 @@ class SparseMatrixTestCore {
// Don't construct a static tiledb matrix here, as the destructor doesn't get called when GoogleTest exits via _exit
// (see https://stackoverflow.com/questions/12728535/will-global-static-variables-be-destroyed-at-program-end)
// resulting in errors due to unjoined threads in the undestructed TileDB Context.
opt.maximum_cache_size = static_cast<double>(NR * NC) * cache_fraction * static_cast<double>(sizeof(double));
opt.require_minimum_cache = (cache_fraction > 0);
opt.maximum_cache_size = static_cast<double>(NR * NC) * 0.1 * static_cast<double>(sizeof(double));
opt.require_minimum_cache = true;

ref.reset(new tatami::CompressedSparseRowMatrix<double, int>(NR, NC, contents.value, contents.index, contents.ptr));

Expand All @@ -102,7 +94,7 @@ class SparseMatrixTestCore {
class SparseUtilsTest : public ::testing::Test, public SparseMatrixTestCore {};

TEST_F(SparseUtilsTest, Basic) {
assemble(std::make_pair(std::make_pair<int, int>(10, 10), 0));
assemble({ 10, 10 });
std::unique_ptr<tatami::Matrix<double, int> > mat(new tatami_tiledb::SparseMatrix<double, int>(fpath, name, opt));

EXPECT_EQ(mat->nrow(), NR);
Expand All @@ -114,14 +106,14 @@ TEST_F(SparseUtilsTest, Basic) {

{
// First dimension is compromised, switching to the second dimension.
assemble(std::make_pair(std::make_pair<int, int>(NR, 1), 0));
assemble({ NR, 1 });
std::unique_ptr<tatami::Matrix<double, int> > mat(new tatami_tiledb::SparseMatrix<double, int>(fpath, name, opt));
EXPECT_FALSE(mat->prefer_rows());
}

{
// Second dimension is compromised, but we just use the first anyway.
assemble(std::make_pair(std::make_pair<int, int>(1, NC), 0));
assemble({ 1, NC });
std::unique_ptr<tatami::Matrix<double, int> > mat(new tatami_tiledb::SparseMatrix<double, int>(fpath, name, opt));
EXPECT_TRUE(mat->prefer_rows());
}
Expand Down Expand Up @@ -258,13 +250,47 @@ INSTANTIATE_TEST_SUITE_P(
)
);

/*************************************
*************************************/

class SparseUncachedTest :
public ::testing::TestWithParam<tatami_test::StandardTestAccessParameters>,
public SparseMatrixTestCore {
protected:
void SetUp() {
assemble({ 10, 10 });
}
};

TEST_P(SparseUncachedTest, Basic) {
tatami_tiledb::SparseMatrixOptions opt2;
opt2.maximum_cache_size = 0;
opt2.require_minimum_cache = false;
std::shared_ptr<tatami::Matrix<double, int> > mat(new tatami_tiledb::SparseMatrix<double, int>(fpath, name, opt2));

auto params = tatami_test::convert_access_parameters(GetParam());
tatami_test::test_full_access(params, mat.get(), ref.get());

auto len = params.use_row ? ref->ncol() : ref->nrow();
size_t FIRST = len * 0.25, LAST = len * 0.75;
tatami_test::test_block_access(params, mat.get(), ref.get(), FIRST, LAST);

tatami_test::test_indexed_access(params, mat.get(), ref.get(), FIRST, 4);
}

INSTANTIATE_TEST_SUITE_P(
SparseMatrix,
SparseUncachedTest,
tatami_test::standard_test_access_parameter_combinations()
);

/*************************************
*************************************/

class SparseMatrixCachedTypeTest : public ::testing::Test, public SparseMatrixTestCore {
protected:
void SetUp() {
assemble({ { 10, 10 }, 0});
assemble({ 10, 10 });
}
};

Expand Down

0 comments on commit 1c43ef3

Please sign in to comment.