Skip to content

Commit

Permalink
iterating on R dense
Browse files Browse the repository at this point in the history
  • Loading branch information
johnkerl committed Oct 28, 2024
1 parent e8edb16 commit 0e6493a
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 5 deletions.
11 changes: 10 additions & 1 deletion apis/python/src/tiledbsoma/_dense_nd_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,16 @@ def read(
timestamp=handle.timestamp and (0, handle.timestamp),
)

# XXX comment this, and make it conditional on core 2.27 or more, and, new-shape feature-flag enabled
# Scenario to avoid:
# * Query dense array with coords not provided
# * When coords not provided, core uses the core domain
# For old shape:
# * Core current domain did not exist
# * Core max domain may be small; .shape returns this
# For new shape (core 2.27 and tiledbsoma 1.15):
# * Core current domain exists and will be small; .shape returns this
# * Core max domain will be huge
# In either case, applying these coords is the right thing to do
if coords == ():
coords = tuple(slice(0, e - 1) for e in data_shape)

Expand Down
10 changes: 8 additions & 2 deletions apis/python/tests/test_dense_nd_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import pytest

import tiledbsoma as soma
import tiledbsoma.pytiledbsoma as clib
from tiledbsoma.options import SOMATileDBContext

from . import NDARRAY_ARROW_TYPES_NOT_SUPPORTED, NDARRAY_ARROW_TYPES_SUPPORTED
Expand Down Expand Up @@ -180,8 +181,13 @@ def test_dense_nd_array_requires_shape(tmp_path, shape_is_numeric):
with soma.DenseNDArray.open(uri) as dnda:
assert dnda.shape == (2, 3)
else:
with pytest.raises(ValueError):
soma.DenseNDArray.create(uri, type=pa.float32(), shape=(None, None)).close()
soma.DenseNDArray.create(uri, type=pa.float32(), shape=(None, None)).close()
with soma.DenseNDArray.open(uri) as dnda:
if (
soma._flags.NEW_SHAPE_FEATURE_FLAG_ENABLED
and clib.embedded_version_triple() >= (2, 27, 0)
):
assert dnda.shape == (1, 1)


def test_dense_nd_array_ned_write(tmp_path):
Expand Down
1 change: 1 addition & 0 deletions apis/r/R/SOMADataFrame.R
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ SOMADataFrame <- R6::R6Class(
uri = self$uri,
naap = naap,
nasp = nasp,
coords_list = list(), # only used for SOMADenseNDArray
ctxxp = private$.soma_context,
arraytype = "SOMADataFrame",
config = NULL,
Expand Down
2 changes: 1 addition & 1 deletion apis/r/R/SOMADenseNDArray.R
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,9 @@ SOMADenseNDArray <- R6::R6Class(
#arr[] <- values
writeArrayFromArrow(
uri = self$uri,
coords,
naap = naap,
nasp = nasp,
coords_list = coords,
ctxxp = private$.soma_context,
arraytype = "SOMADenseNDArray",
config = NULL,
Expand Down
1 change: 1 addition & 0 deletions apis/r/R/SOMASparseNDArray.R
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ SOMASparseNDArray <- R6::R6Class(
uri = self$uri,
naap = naap,
nasp = nasp,
coords_list = list(), # only used for SOMADenseNDArray
ctxxp = private$.soma_context,
arraytype = "SOMASparseNDArray",
config = NULL,
Expand Down
15 changes: 14 additions & 1 deletion apis/r/src/arrow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,20 @@ void writeArrayFromArrow(
int lo = *std::min_element(slot_values.begin(), slot_values.end());
int hi = *std::max_element(slot_values.begin(), slot_values.end());
spdl::debug(
"dense array write: dim {} set range lo {} hi {}", dim_name, lo, hi);
"dense array write: dim {} set 1-up range lo {} hi {}",
dim_name,
lo,
hi);
// These are 1-up indices from R. Convert to 0-up for C++.
if (lo < 1) {
Rcpp::stop(tfm::format(
"dense array write: expected lower bound %d >= 1 for dim "
"name %s",
lo,
dim_name));
}
lo--;
hi--;
std::pair<int64_t, int64_t> lo_hi(int64_t{lo}, int64_t{hi});
std::vector<std::pair<int64_t, int64_t>> range({lo_hi});
arrup.get()->set_dim_ranges(dim_name, range);
Expand Down

0 comments on commit 0e6493a

Please sign in to comment.