Skip to content

Commit

Permalink
Add minimal testing for dimensions
Browse files Browse the repository at this point in the history
  • Loading branch information
XanthosXanthopoulos committed Nov 21, 2024
1 parent 1b83997 commit a0618f1
Show file tree
Hide file tree
Showing 6 changed files with 215 additions and 7 deletions.
6 changes: 6 additions & 0 deletions libtiledbsoma/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ add_library(TILEDB_SOMA_OBJECTS OBJECT
${CMAKE_CURRENT_SOURCE_DIR}/soma/soma_group.cc
${CMAKE_CURRENT_SOURCE_DIR}/soma/soma_object.cc
${CMAKE_CURRENT_SOURCE_DIR}/soma/soma_column.cc
${CMAKE_CURRENT_SOURCE_DIR}/soma/soma_attribute.cc
${CMAKE_CURRENT_SOURCE_DIR}/soma/soma_dimension.cc
${CMAKE_CURRENT_SOURCE_DIR}/soma/soma_geometry_column.cc
${CMAKE_CURRENT_SOURCE_DIR}/soma/soma_collection.cc
${CMAKE_CURRENT_SOURCE_DIR}/soma/soma_experiment.cc
${CMAKE_CURRENT_SOURCE_DIR}/soma/soma_measurement.cc
Expand Down Expand Up @@ -208,6 +211,9 @@ install(FILES
${CMAKE_CURRENT_SOURCE_DIR}/soma/soma_array.h
${CMAKE_CURRENT_SOURCE_DIR}/soma/soma_group.h
${CMAKE_CURRENT_SOURCE_DIR}/soma/soma_column.h
${CMAKE_CURRENT_SOURCE_DIR}/soma/soma_attribute.h
${CMAKE_CURRENT_SOURCE_DIR}/soma/soma_dimension.h
${CMAKE_CURRENT_SOURCE_DIR}/soma/soma_geometry_column.h
${CMAKE_CURRENT_SOURCE_DIR}/soma/soma_collection.h
${CMAKE_CURRENT_SOURCE_DIR}/soma/soma_dataframe.h
${CMAKE_CURRENT_SOURCE_DIR}/soma/soma_dense_ndarray.h
Expand Down
4 changes: 4 additions & 0 deletions libtiledbsoma/src/tiledbsoma/tiledbsoma
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@
#include "soma/column_buffer.h"
#include "soma/soma_array.h"
#include "soma/soma_collection.h"
#include "soma/soma_column.h"
#include "soma/soma_attribute.h"
#include "soma/soma_dimension.h"
#include "soma/soma_geometry_column.h"
#include "soma/soma_dataframe.h"
#include "soma/soma_group.h"
#include "soma/soma_experiment.h"
Expand Down
1 change: 1 addition & 0 deletions libtiledbsoma/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ add_executable(unit_soma
unit_soma_dense_ndarray.cc
unit_soma_sparse_ndarray.cc
unit_soma_collection.cc
unit_soma_column.cc
unit_soma_scene.cc
unit_soma_geometry_dataframe.cc
unit_soma_point_cloud_dataframe.cc
Expand Down
7 changes: 0 additions & 7 deletions libtiledbsoma/test/common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,6 @@

namespace helper {

// This non-obvious number is:
// * Something that fits into signed 32-bit integer for R-friendliness;
// * Is a comfortable tile-extent distance away from 2^31-1 for default
// core tile extent. (Using 2^31-1 exactly would result in a core
// array-creation error.)
const int CORE_DOMAIN_MAX = 2147483646;

static std::unique_ptr<ArrowArray> _create_index_cols_info_array(
const std::vector<DimInfo>& dim_infos);

Expand Down
7 changes: 7 additions & 0 deletions libtiledbsoma/test/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ static const std::string src_path = TILEDBSOMA_SOURCE_ROOT;

namespace helper {

// This non-obvious number is:
// * Something that fits into signed 32-bit integer for R-friendliness;
// * Is a comfortable tile-extent distance away from 2^31-1 for default
// core tile extent. (Using 2^31-1 exactly would result in a core
// array-creation error.)
const int CORE_DOMAIN_MAX = 2147483646;

// E.g. "d0" is of type TILEDB_INT64 with dim_max 1000 and current-domain
// feature enabled
struct DimInfo {
Expand Down
197 changes: 197 additions & 0 deletions libtiledbsoma/test/unit_soma_column.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
/**
* @file unit_soma_column.cc
*
* @section LICENSE
*
* The MIT License
*
* @copyright Copyright (c) 2024 TileDB, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @section DESCRIPTION
*
* This file manages unit tests for implementation of SOMAColumn class
*/

#include <tiledbsoma/tiledbsoma>
#include "common.h"

TEST_CASE("SOMAColumn: SOMADimension") {
auto use_current_domain = GENERATE(false, true);
auto ctx = std::make_shared<SOMAContext>();
PlatformConfig platform_config{};

SECTION(std::format("- use_current_domain={}", use_current_domain)) {
std::vector<helper::DimInfo> dim_infos(
{helper::DimInfo(
{.name = "dimension",
.tiledb_datatype = TILEDB_UINT32,
.dim_max = 100,
.string_lo = "N/A",
.string_hi = "N/A",
.use_current_domain = use_current_domain}),
helper::DimInfo(
{.name = "dimension",
.tiledb_datatype = TILEDB_FLOAT64,
.dim_max = 100,
.string_lo = "N/A",
.string_hi = "N/A",
.use_current_domain = use_current_domain}),
helper::DimInfo(
{.name = "dimension",
.tiledb_datatype = TILEDB_INT64,
.dim_max = 100,
.string_lo = "N/A",
.string_hi = "N/A",
.use_current_domain = use_current_domain}),
helper::DimInfo(
{.name = "dimension",
.tiledb_datatype = TILEDB_STRING_ASCII,
.dim_max = 100,
.string_lo = "N/A",
.string_hi = "N/A",
.use_current_domain = use_current_domain})});

std::vector<helper::DimInfo> geom_dim_infos({helper::DimInfo(
{.name = "dimension",
.tiledb_datatype = TILEDB_GEOM_WKB,
.dim_max = 100,
.string_lo = "N/A",
.string_hi = "N/A",
.use_current_domain = use_current_domain})});

std::vector<helper::DimInfo> spatial_dim_infos(
{helper::DimInfo(
{.name = "x",
.tiledb_datatype = TILEDB_FLOAT64,
.dim_max = 200,
.string_lo = "N/A",
.string_hi = "N/A",
.use_current_domain = use_current_domain}),
helper::DimInfo(
{.name = "y",
.tiledb_datatype = TILEDB_FLOAT64,
.dim_max = 100,
.string_lo = "N/A",
.string_hi = "N/A",
.use_current_domain = use_current_domain})});

auto index_columns = helper::create_column_index_info(dim_infos);

std::vector<std::shared_ptr<SOMAColumn>> columns;
bool has_current_domain = true;

for (int64_t i = 0; i < index_columns.second->n_children; ++i) {
columns.push_back(SOMADimension::create(
ctx->tiledb_ctx(),
index_columns.second->children[i],
index_columns.first->children[i],
"SOMAGeometryDataFrame",
"",
platform_config,
has_current_domain));

REQUIRE(has_current_domain == use_current_domain);
REQUIRE(
columns.back()->tiledb_dimensions().value()[0].type() ==
dim_infos[i].tiledb_datatype);
}

REQUIRE(
columns[1]->core_domain_slot<double_t>() ==
std::make_pair<double_t, double_t>(
0, use_current_domain ? helper::CORE_DOMAIN_MAX : 100));
REQUIRE(
columns[1]->core_domain_slot<double_t>() ==
std::make_pair<double_t, double_t>(
0, use_current_domain ? helper::CORE_DOMAIN_MAX : 100));
REQUIRE(
columns[2]->core_domain_slot<int64_t>() ==
std::make_pair<int64_t, int64_t>(
0, use_current_domain ? helper::CORE_DOMAIN_MAX : 100));
REQUIRE(
columns[3]->core_domain_slot<std::string>() ==
std::make_pair<std::string, std::string>("", ""));
}
}

TEST_CASE("SOMAColumn: SOMAGeometryDimension") {
auto use_current_domain = GENERATE(false, true);
auto ctx = std::make_shared<SOMAContext>();
PlatformConfig platform_config{};

SECTION(std::format("- use_current_domain={}", use_current_domain)) {
std::vector<helper::DimInfo> geom_dim_infos({helper::DimInfo(
{.name = "dimension",
.tiledb_datatype = TILEDB_GEOM_WKB,
.dim_max = 100,
.string_lo = "N/A",
.string_hi = "N/A",
.use_current_domain = use_current_domain})});

std::vector<helper::DimInfo> spatial_dim_infos(
{helper::DimInfo(
{.name = "x",
.tiledb_datatype = TILEDB_FLOAT64,
.dim_max = 200,
.string_lo = "N/A",
.string_hi = "N/A",
.use_current_domain = use_current_domain}),
helper::DimInfo(
{.name = "y",
.tiledb_datatype = TILEDB_FLOAT64,
.dim_max = 100,
.string_lo = "N/A",
.string_hi = "N/A",
.use_current_domain = use_current_domain})});

auto geom_columns = helper::create_column_index_info(geom_dim_infos);
auto spatial_columns = helper::create_column_index_info(
spatial_dim_infos);

bool has_current_domain = true;
auto geometry_column = SOMAGeometryColumn::create(
ctx->tiledb_ctx(),
geom_columns.second->children[0],
geom_columns.first->children[0],
spatial_columns.second.get(),
spatial_columns.first.get(),
"SOMAGeometryDataFrame",
"WKB",
platform_config,
has_current_domain);

REQUIRE(
geometry_column->tiledb_dimensions().value().size() ==
spatial_dim_infos.size() * 2);
REQUIRE(
geometry_column->tiledb_attributes().value()[0].type() ==
TILEDB_GEOM_WKB);

auto domain = geometry_column
->core_domain_slot<std::vector<double_t>>();
CHECK(domain.first == std::vector<double_t>({0, 0}));
CHECK(
domain.second ==
std::vector<double_t>(
{use_current_domain ? helper::CORE_DOMAIN_MAX : 200.0,
use_current_domain ? helper::CORE_DOMAIN_MAX : 100.0}));
}
}

0 comments on commit a0618f1

Please sign in to comment.