From 38ba1c437fffd31c161c8fda87266c3f0dd6f9ae Mon Sep 17 00:00:00 2001 From: John Kerl Date: Fri, 13 Dec 2024 17:48:25 -0500 Subject: [PATCH] [c++] Match zero-basing for old/new sparse-array shapes --- libtiledbsoma/src/soma/soma_array.cc | 24 +++++++++++++----------- libtiledbsoma/src/soma/soma_array.h | 8 ++++---- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/libtiledbsoma/src/soma/soma_array.cc b/libtiledbsoma/src/soma/soma_array.cc index 51e6646fe5..f6e4b2b27e 100644 --- a/libtiledbsoma/src/soma/soma_array.cc +++ b/libtiledbsoma/src/soma/soma_array.cc @@ -726,12 +726,13 @@ std::vector SOMAArray::shape() { // * Even after the new-shape feature is fully released, there will be old // arrays on disk that were created before this feature existed. // So this is long-term code. - return _get_current_domain().is_empty() ? _tiledb_domain() : - _tiledb_current_domain(); + return _get_current_domain().is_empty() ? + _shape_via_tiledb_domain() : + _shape_via_tiledb_current_domain(); } std::vector SOMAArray::maxshape() { - return _tiledb_domain(); + return _shape_via_tiledb_domain(); } // This is a helper for can_upgrade_shape and can_resize, which have @@ -1532,7 +1533,7 @@ void SOMAArray::_set_domain_helper( schema_evolution.array_evolve(uri_); } -std::vector SOMAArray::_tiledb_current_domain() { +std::vector SOMAArray::_shape_via_tiledb_current_domain() { // Variant-indexed dataframes must use a separate path _check_dims_are_int64(); @@ -1557,12 +1558,12 @@ std::vector SOMAArray::_tiledb_current_domain() { for (auto dimension_name : dimension_names()) { auto range = ndrect.range(dimension_name); - result.push_back(range[1] + 1); + result.push_back(range[1] - range[0] + 1); } return result; } -std::vector SOMAArray::_tiledb_domain() { +std::vector SOMAArray::_shape_via_tiledb_domain() { // Variant-indexed dataframes must use a separate path _check_dims_are_int64(); @@ -1579,15 +1580,16 @@ std::vector SOMAArray::_tiledb_domain() { std::optional SOMAArray::_maybe_soma_joinid_shape() { return _get_current_domain().is_empty() ? - _maybe_soma_joinid_tiledb_domain() : - _maybe_soma_joinid_tiledb_current_domain(); + _maybe_soma_joinid_shape_via_tiledb_domain() : + _maybe_soma_joinid_shape_via_tiledb_current_domain(); } std::optional SOMAArray::_maybe_soma_joinid_maxshape() { - return _maybe_soma_joinid_tiledb_domain(); + return _maybe_soma_joinid_shape_via_tiledb_domain(); } -std::optional SOMAArray::_maybe_soma_joinid_tiledb_current_domain() { +std::optional +SOMAArray::_maybe_soma_joinid_shape_via_tiledb_current_domain() { const std::string dim_name = "soma_joinid"; auto dom = schema_->domain(); @@ -1621,7 +1623,7 @@ std::optional SOMAArray::_maybe_soma_joinid_tiledb_current_domain() { return std::optional(max); } -std::optional SOMAArray::_maybe_soma_joinid_tiledb_domain() { +std::optional SOMAArray::_maybe_soma_joinid_shape_via_tiledb_domain() { const std::string dim_name = "soma_joinid"; auto dom = schema_->domain(); diff --git a/libtiledbsoma/src/soma/soma_array.h b/libtiledbsoma/src/soma/soma_array.h index 021c4fa477..296200c873 100644 --- a/libtiledbsoma/src/soma/soma_array.h +++ b/libtiledbsoma/src/soma/soma_array.h @@ -1528,10 +1528,10 @@ class SOMAArray : public SOMAObject { * * Here we distinguish between user-side API, and core-side implementation. */ - std::vector _tiledb_domain(); - std::vector _tiledb_current_domain(); - std::optional _maybe_soma_joinid_tiledb_current_domain(); - std::optional _maybe_soma_joinid_tiledb_domain(); + std::vector _shape_via_tiledb_domain(); + std::vector _shape_via_tiledb_current_domain(); + std::optional _maybe_soma_joinid_shape_via_tiledb_current_domain(); + std::optional _maybe_soma_joinid_shape_via_tiledb_domain(); void fill_metadata_cache(std::optional timestamp);