Skip to content

Commit

Permalink
Doco (#81)
Browse files Browse the repository at this point in the history
  • Loading branch information
dblodgett-usgs committed May 21, 2024
1 parent c74a9c3 commit 572ff32
Show file tree
Hide file tree
Showing 37 changed files with 1,601 additions and 179 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Imports:
Encoding: UTF-8
LazyData: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.3
RoxygenNote: 7.3.1
Suggests:
testthat,
knitr,
Expand Down
33 changes: 31 additions & 2 deletions R/attributes.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#' @export
Attributes <- R6::R6Class("Attributes",
private = list(
#' @field cached_aslist The attributes cached as a list.

cached_aslist = NULL,

get_nosync = function() {
Expand Down Expand Up @@ -55,6 +55,10 @@ Attributes <- R6::R6Class("Attributes",
#' @description
#' Create a new Attributes instance.
#' @param store Attributes store, already initialized.
#' @param key description key to use for attributes (.attrs is default)
#' @param read_only logical
#' @param cache logical
#' @param synchronizer object
#' @return An `Attributes` instance.
initialize = function(store, key = NA, read_only = FALSE, cache = TRUE, synchronizer = NA) {
if(is_na(key)) {
Expand All @@ -67,6 +71,9 @@ Attributes <- R6::R6Class("Attributes",
private$cached_aslist <- NA
self$synchronizer <- synchronizer
},
#' @description
#' convert attributes to list
#' @return list
to_list = function() {
if(self$cache && !is_na(private$cached_aslist)) {
return(private$cached_aslist)
Expand All @@ -77,21 +84,43 @@ Attributes <- R6::R6Class("Attributes",
}
return(d)
},
#' @description
#' refresh attributes
#' @return None
refresh = function() {
if(self$cache) {
private$cached_aslist <- private$get_nosync()
new_val <- private$get_nosync()

private$cached_aslist <- new_val
}
},
#' @description
#' check if object contains item
#' @param x object
#' @return logical
contains = function(x) {
return(x %in% names(self$to_list()))
},
#' @description
#' get attribute
#' @param item character
#' @return item as list
get_item = function(item) {
return(self$to_list()[[item]])
},
#' @description
#' set attribute
#' @param item character
#' @param value value to add or update
#' @return none
set_item = function(item, value) {
# TODO: support synchronizer
private$set_item_nosync(item, value)
},
#' @description
#' delete attribute
#' @param item character
#' @return none
del_item = function(item) {
# TODO: support synchronizer
private$del_item_nosync(item)
Expand Down
8 changes: 7 additions & 1 deletion R/dtypes.R
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ get_dtype_asrtype <- function(dtype) {
#' @title Dtype Class
#' @docType class
#' @description
#'
#' TODO
#' @rdname Dtype
#' @export
Dtype <- R6::R6Class("Dtype",
Expand Down Expand Up @@ -182,12 +182,18 @@ Dtype <- R6::R6Class("Dtype",

self$object_codec <- object_codec
},
#' @description
#' Get as R type
get_asrtype = function() {
return(get_dtype_asrtype(self$dtype))
},
#' @description
#' basic type R type
get_rtype = function() {
return(get_dtype_rtype(self$basic_type))
},
#' @description
#' get typed array
get_typed_array_ctr = function() {
rtype <- self$get_rtype()
return(function(dim) array(data = rtype, dim = dim))
Expand Down
54 changes: 42 additions & 12 deletions R/indexing.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@
#' @title OIndex Class
#' @docType class
#' @description
#'
#' TODO
#' @rdname OIndex
#' @keywords internal
OIndex <- R6::R6Class("OIndex",
public = list(
#' @field array
#' @field array array
#' @keywords internal
array = NULL,
#' @description
#' Create a new OIndex instance.
#' @param array array
#' @return An `OIndex` instance.
initialize = function(array) {
self$array <- array
Expand All @@ -27,16 +28,17 @@ OIndex <- R6::R6Class("OIndex",
#' @title VIndex Class
#' @docType class
#' @description
#'
#' TODO
#' @rdname VIndex
#' @keywords internal
VIndex <- R6::R6Class("VIndex",
public = list(
#' @field array
#' @field array array
#' @keywords internal
array = NULL,
#' @description
#' Create a new VIndex instance.
#' @param array array
#' @return A `VIndex` instance.
initialize = function(array) {
self$array <- array
Expand All @@ -50,23 +52,26 @@ VIndex <- R6::R6Class("VIndex",
#' @title IntDimIndexer Class
#' @docType class
#' @description
#'
#' TODO
#' @rdname IntDimIndexer
#' @keywords internal
IntDimIndexer <- R6::R6Class("IntDimIndexer",
inherit = DimIndexer,
public = list(
#' @field dim_sel
#' @field dim_sel TODO
#' @keywords internal
dim_sel = NULL,
#' @field dim_len
#' @field dim_len TODO
#' @keywords internal
dim_len = NULL,
#' @field dim_chunk_len
#' @field dim_chunk_len TODO
#' @keywords internal
dim_chunk_len = NULL,
#' @description
#' Create a new IntDimIndexer instance.
#' @param dim_sel integer dimention selection
#' @param dim_len integer dimension length
#' @param dim_chunk_len integer dimension chunk length
#' @return A `IntDimIndexer` instance.
initialize = function(dim_sel, dim_len, dim_chunk_len) {
# Normalize
Expand All @@ -77,6 +82,9 @@ IntDimIndexer <- R6::R6Class("IntDimIndexer",
self$dim_chunk_len <- dim_chunk_len
self$num_items <- 1
},
#' @description
#' TODO
#' @return a `ChunkDimProjection` instance
iter = function() {
# TODO: use generator/yield features from async package
dim_chunk_index <- floor(self$dim_sel / self$dim_chunk_len)
Expand All @@ -100,21 +108,35 @@ IntDimIndexer <- R6::R6Class("IntDimIndexer",
#' @title SliceDimIndexer Class
#' @docType class
#' @description
#'
#' TODO
#' @rdname SliceDimIndexer
#' @keywords internal
SliceDimIndexer <- R6::R6Class("SliceDimIndexer",
inherit = DimIndexer,
public = list(
#' @field dim_len dimension length
#' @keywords internal
dim_len = NULL,
#' @field dim_chunk_len dimension chunk length
#' @keywords internal
dim_chunk_len = NULL,
#' @field num_chunks number of chunks
#' @keywords internal
num_chunks = NULL,
#' @field start start
#' @keywords internal
start = NULL,
#' @field stop stop
#' @keywords internal
stop = NULL,
#' @field step step
#' @keywords internal
step = NULL,

#' @description
#' Create a new SliceDimIndexer instance.
#' @param dim_sel integer dimention selection
#' @param dim_len integer dimension length
#' @param dim_chunk_len integer dimension chunk length
#' @return A `SliceDimIndexer` instance.
initialize = function(dim_sel, dim_len, dim_chunk_len) {
# Reference: https://github.com/gzuidhof/zarr.js/blob/292804/src/core/indexing.ts#L311
Expand All @@ -130,6 +152,9 @@ SliceDimIndexer <- R6::R6Class("SliceDimIndexer",
self$num_items <- max(0, ceiling((self$stop - self$start) / self$step))
self$num_chunks <- ceiling(self$dim_len / self$dim_chunk_len)
},
#' @description
#' TODO
#' @return TODO
iter = function() {
# TODO: use generator/yield features from async package
dim_chunk_index_from <- floor(self$start / self$dim_chunk_len)
Expand Down Expand Up @@ -201,17 +226,19 @@ SliceDimIndexer <- R6::R6Class("SliceDimIndexer",
#' @title BasicIndexer Class
#' @docType class
#' @description
#'
#' TODO
#' @rdname BasicIndexer
#' @keywords internal
BasicIndexer <- R6::R6Class("BasicIndexer",
inherit = Indexer,
public = list(
#' @field dim_indexers
#' @field dim_indexers TODO
#' @keywords internal
dim_indexers = NULL,
#' @description
#' Create a new VIndex instance.
#' @param selection selection TODO
#' @param array array TODO
#' @return A `VIndex` instance.
initialize = function(selection, array) {
shape <- array$get_shape()
Expand Down Expand Up @@ -249,6 +276,9 @@ BasicIndexer <- R6::R6Class("BasicIndexer",

self$dim_indexers <- dim_indexers
},
#' @description
#' TODO
#' @return TODO
iter = function() {
# TODO: use generator/yield features from async package
result <- list()
Expand Down
Loading

0 comments on commit 572ff32

Please sign in to comment.