Skip to content

writeTileDBArray() fails for dense 3D arrays ("Subarray should have num_dims * 2 values") #30

Description

@kokitsuyuzaki

Hi,

I'm the developer of the DelayedTensor package, which performs tensor arithmetic on DelayedArray objects. I'm exploring using TileDBArray as a backend (instead of HDF5Array) to take advantage of TileDB's native sparse storage.

I found that writeTileDBArray() works correctly for 2D arrays and sparse 3D arrays, but fails for dense 3D arrays with the error:

Error: Subarray should have num_dims * 2 values: (low, high) for each dimension.

Minimal reproducible example

library(TileDBArray)

# 2D dense: OK
mat <- matrix(runif(100), nrow=10, ncol=10)
writeTileDBArray(mat)
#> 10 x 10 TileDBMatrix

# 3D sparse: OK
sparse3d <- SparseArray::randomSparseArray(c(10, 10, 10), density=0.01)
writeTileDBArray(sparse3d)
#> 10 x 10 x 10 TileDBArray

# 3D dense: FAIL
arr3d <- array(runif(1000), dim=c(10, 10, 10))
writeTileDBArray(arr3d)
#> Error: Subarray should have num_dims * 2 values: (low, high) for each
dimension.

# TileDBRealizationSink creation succeeds for 3D
sink <- TileDBRealizationSink(dim=c(10L, 10L, 10L))
#> OK

# But write_block to that sink fails
grid <- RegularArrayGrid(refdim=c(10L, 10L, 10L), spacings=c(10L, 10L, 10L))
block <- array(runif(1000), dim=c(10, 10, 10))
write_block(sink, grid[[1L, 1L, 1L]], block)
#> Error: Subarray should have num_dims * 2 values: (low, high) for each
dimension.

The error seems to come from the dense path of write_block() in TileDBRealizationSink.R (around line 240), where do.call("[<-", args) calls into the tiledb package's subarray write functionality. The sparse path uses a data.frame-based write and works fine.

It's possible this is actually a tiledb R package issue rather than TileDBArray, but I'm reporting here since the sparse path works. Could the dense path perhaps use selected_ranges() as recommended in TileDB-Inc/TileDB-R#259?

Use case

DelayedTensor needs 3D+ array support for tensor decomposition and arithmetic operations. Being able to use TileDBArray as a backend would be very beneficial for sparse tensor workloads, since HDF5 stores everything as dense internally.

Session info

R version 4.5.3 (2026-03-11)
Platform: x86_64-conda-linux-gnu

TileDBArray 1.20.0
tiledb      0.34.0
DelayedArray 0.36.0
SparseArray  1.10.8
S4Arrays     1.10.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions