Skip to content

Commit

Permalink
support third dimension in A[i,j,k] indexing
Browse files Browse the repository at this point in the history
  • Loading branch information
eddelbuettel committed Feb 2, 2022
1 parent e218ccc commit ec0a192
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions R/TileDBArray.R
Expand Up @@ -470,6 +470,16 @@ setMethod("[", "tiledb_array",
## add defaults
if (missing(i)) i <- NULL
if (missing(j)) j <- NULL
k <- NULL

## deal with possible n-dim indexing
ndlist <- nd_index_from_syscall(sys.call(), parent.frame())
if (length(ndlist) >= 0) {
if (length(ndlist) >= 1 && !is.null(ndlist[[1]])) i <- ndlist[[1]]
if (length(ndlist) >= 2 && !is.null(ndlist[[2]])) j <- ndlist[[2]]
if (length(ndlist) >= 3 && !is.null(ndlist[[3]])) k <- ndlist[[3]]
if (length(ndlist) >= 4) message("Indices beyond the third dimension not supported in [i,j,k] form. Use selected_ranges().")
}

ctx <- x@ctx
uri <- x@uri
Expand Down Expand Up @@ -609,6 +619,15 @@ setMethod("[", "tiledb_array",
x@selected_ranges[[2]] <- j
}

if (!is.null(k)) {
if (!is.null(x@selected_ranges[[3]])) {
stop("Cannot set both 'k' and second element of 'selected_ranges'.", call. = FALSE)
}
x@selected_ranges[[3]] <- k
}
## (i,j,k) are now done and transferred to x@select_ranges


## if ranges selected, use those
for (k in seq_len(length(x@selected_ranges))) {
if (is.null(x@selected_ranges[[k]])) {
Expand Down

3 comments on commit ec0a192

@aaronwolen
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eddelbuettel
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And even little variants works :)

    print(A[2,2,2])

    print(A[2,2:3,2])

Would we need a 4th or even 5th dim? "To infinity and beyond" ?

@eddelbuettel
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I am not policing user input here. If someone does 1 : 1e9 R will in fact expand this and there is little I can do besides quietly mumbling please please please use selected_ranges() instead ....

Please sign in to comment.