Skip to contents

NOTE: This man page is about DelayedArray internals and is provided for developers and advanced users only.

The DelayedSubset class provides a formal representation of a delayed multi-dimensional single bracket subsetting operation. It is a concrete subclass of the DelayedUnaryOp virtual class, which itself is a subclass of the DelayedOp virtual class:


                          DelayedOp
                              ^
                              |
                        DelayedUnaryOp
                              ^
                              |
                        DelayedSubset
  

DelayedSubset objects are used inside a DelayedArray object to represent the delayed multi-dimensional single bracket subsetting operations carried by the object. They're never exposed to the end user and are not intended to be manipulated directly.

Usage

# S4 method for class 'DelayedSubset'
is_noop(x)

# S4 method for class 'DelayedSubset'
summary(object, ...)

## ~ ~ ~ Seed contract ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~

# S4 method for class 'DelayedSubset'
dim(x)

# S4 method for class 'DelayedSubset'
dimnames(x)

# S4 method for class 'DelayedSubset'
extract_array(x, index)

## ~ ~ ~ Propagation of sparsity ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~

# S4 method for class 'DelayedSubset'
is_sparse(x)

# S4 method for class 'DelayedSubset'
extract_sparse_array(x, index)

Arguments

x, object

A DelayedSubset object.

index

See ?extract_array in the S4Arrays package for a description of the index argument.

...

Not used.

See also

Examples

## DelayedSubset extends DelayedUnaryOp which extends DelayedOp:
extends("DelayedSubset")
#> [1] "DelayedSubset"  "DelayedUnaryOp" "DelayedOp"      "Array"         

## ---------------------------------------------------------------------
## BASIC EXAMPLE
## ---------------------------------------------------------------------
a0 <- array(1:60, dim=5:3)
A0 <- DelayedArray(a0)
showtree(A0)
#> 5x4x3 integer: DelayedArray object
#> └─ 5x4x3 integer: [seed] array object

A <- A0[2:1, -4, 3, drop=FALSE]
showtree(A)
#> 2x3x1 integer: DelayedArray object
#> └─ 2x3x1 integer: Subset
#>    └─ 5x4x3 integer: [seed] array object
class(A@seed)        # a DelayedSubset object
#> [1] "DelayedSubset"
#> attr(,"package")
#> [1] "DelayedArray"

## ---------------------------------------------------------------------
## PROPAGATION OF SPARSITY
## ---------------------------------------------------------------------
sm0 <- sparseMatrix(i=c(1, 4), j=c(1, 3), x=c(11, 43), dims=4:3)
SM0 <- DelayedArray(sm0)
showtree(SM0)
#> 4x3 double, sparse: DelayedMatrix object
#> └─ 4x3 double, sparse: [seed] dgCMatrix object
is_sparse(SM0)       # TRUE
#> [1] TRUE

SM1 <- SM0[-1, 3:2, drop=FALSE]
showtree(SM1)
#> 3x2 double, sparse: DelayedMatrix object
#> └─ 3x2 double, sparse: Subset
#>    └─ 4x3 double, sparse: [seed] dgCMatrix object
class(SM1@seed)      # a DelayedSubset object
#> [1] "DelayedSubset"
#> attr(,"package")
#> [1] "DelayedArray"
is_sparse(SM1@seed)  # TRUE
#> [1] TRUE

## Duplicated indices break structural sparsity.
M2 <- SM0[-1, c(3:2, 2), drop=FALSE]
showtree(M2)
#> 3x3 double: DelayedMatrix object
#> └─ 3x3 double: Subset
#>    └─ 4x3 double, sparse: [seed] dgCMatrix object
class(M2@seed)       # a DelayedSubset object
#> [1] "DelayedSubset"
#> attr(,"package")
#> [1] "DelayedArray"
is_sparse(M2@seed)   # FALSE
#> [1] FALSE

## ---------------------------------------------------------------------
## SANITY CHECKS
## ---------------------------------------------------------------------
stopifnot(class(A@seed) == "DelayedSubset")
stopifnot(class(SM1@seed) == "DelayedSubset")
stopifnot(is_sparse(SM1@seed))
stopifnot(class(M2@seed) == "DelayedSubset")
stopifnot(!is_sparse(M2@seed))