Skip to content

Fix dense [<- writes and support [i, j, k] and selected_ranges() - #896

Open
mojaveazure wants to merge 1 commit into
mainfrom
fix/dense-assign-nd
Open

mojaveazure wants to merge 1 commit into
mainfrom
fix/dense-assign-nd

Conversation

@mojaveazure

Copy link
Copy Markdown
Member

Fixes the dense [<- write bugs reported in #877, and makes dense writes work for 3D+ arrays.

Bugs fixed

ncol Before, [i, j] Before, selected_ranges() Now
1 silent no-op silent no-op written
2 written error: buffer sizes (writes full domain) written
3 error: "does not contain all required… columns" same error written
4 written written (only because it fills the domain) written
  • ncol = 1: the single-attribute flatten step required ncol > 1, but its outer if still matched, so the list case was skipped as well. The value kept the name V1, the name check failed, and the if had no else, so the method returned without writing. A name mismatch is now an error.
  • ncol = 3: the data.frame-of-dimensions-and-attributes check matched on column count alone (2 dims + 1 attr = 3). For dense arrays it now also requires a matching column name.
  • Subarray: was as.integer(c(range(i), range(j))), set only when both i and j were given and there was a single attribute. It was 2D and INT32 only, ignored selected_ranges(), and widened non-contiguous indices. Dense writes with multiple attributes never set a subarray.

New behavior

  • arr[i, j, k] <- value on dense arrays, capturing k the same way [ does (nd_index_from_syscall()). A 4th index is an error, not a message as on the read side, because ignoring it would write to the wrong cells. Sparse writes still use i and j only.
  • Dense writes honor selected_ranges(), named or unnamed, for any number of dimensions. Dimensions with no selection span their full domain.
  • The subarray is typed per dimension (libtiledb_subarray_add_range_with_type()), so INT64 and datetime dimensions work.
  • nd_index_from_syscall() no longer evaluates value a second time.

Behavior changes (in NEWS and ?"[<-,tiledb_array-method")

These are now errors:

  • dense indices that aren't contiguous and increasing (they used to be widened to their range);
  • an index for a dimension the array lacks, e.g. a third index on a 2D array, which used to be silently dropped;
  • more than one selected range for a dimension;
  • selected_points() on a write;
  • a value that doesn't match the array (used to be a silent no-op).

Also: selected_ranges() left on an array object from an earlier read now apply to writes through it.

Known limitation

A dimension with no index or selected range spans its full domain, not its current domain. This only matters for dense arrays that have a current domain set.

Testing

  • New inst/tinytest/test_densewrite.R (32 tests):

    • 2D with 1 to 4 columns, for both [i, j] and selected_ranges();
    • an offset block;
    • 3D [i, j, k] and [i, , k], and an array value;
    • named, out-of-order selected_ranges() on a 4D array;
    • 1D, INT64 dimensions, and multiple attributes;
    • every new error.

    It's a separate file because test_tiledbarray.R calls exit_file() partway through on macOS and r-universe.

  • Full suite: 1790 tests, 1 failure (test_config_profile.R, rest.token). The same failure occurs on main (1758 tests, 1 failure). This was run against the R changes loaded into an installed 0.34.0 build, not a fresh compile; CI will cover that.

Closes #877

🤖 Generated with Claude Code

Dense `[<-` silently wrote nothing for one-column right-hand sides,
rejected three-column ones as dimension/attribute columns, ignored
`selected_ranges()`, and built an INT32-only 2-d subarray from `range(i)`
and `range(j)`. Writes now build a typed subarray for any number of
dimensions from `[i, j, k]` or `selected_ranges()`, matching `[`.

Closes #877

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mojaveazure
mojaveazure requested a review from jp-dark October 6, 2026 19:52
@jp-dark
jp-dark requested review from jdblischak and removed request for jp-dark October 7, 2026 13:48

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Dense [<- write fails for 3D arrays ("Subarray should have num_dims * 2 values")

1 participant