Skip to contents

showtree can be used to visualize the tree of delayed operations carried by a DelayedArray object.

Use nseed, seed, or path to access the number of seeds, the seed, or the seed path of a DelayedArray object, respectively.

Use seedApply to apply a function to the seeds of a DelayedArray object.

Usage

showtree(x, show.node.dim=TRUE)

nseed(x)            # seed counter
seed(x)             # seed getter and setter
path(object, ...)   # path getter and setter

seedApply(x, FUN, ...)

Arguments

x, object

Typically a DelayedArray object but can also be a DelayedOp object or a list where each element is a DelayedArray or DelayedOp object.

show.node.dim

TRUE or FALSE. If TRUE (the default), the nodes dimensions and data type are displayed.

FUN

The function to be applied to each leaf in x.

...

Optional arguments to FUN for seedApply().

Additional arguments passed to methods for path().

Value

The number of seeds contained in x for nseed.

The seed contained in x for seed.

The path of the seed contained in object for path.

A list of length nseed(x) for seedApply.

See also

Examples

## ---------------------------------------------------------------------
## showtree(), nseed(), and seed()
## ---------------------------------------------------------------------
m1 <- matrix(runif(150), nrow=15, ncol=10)
M1 <- DelayedArray(m1)
showtree(M1)
#> 15x10 double: DelayedMatrix object
#> └─ 15x10 double: [seed] matrix object
seed(M1)
#>             [,1]       [,2]       [,3]        [,4]       [,5]       [,6]
#>  [1,] 0.20153719 0.81091811 0.45554721 0.646503825 0.84095686 0.11638252
#>  [2,] 0.34731787 0.58624158 0.50567616 0.091341729 0.61877679 0.83997249
#>  [3,] 0.70488124 0.87164081 0.07006891 0.098296557 0.24399636 0.19848995
#>  [4,] 0.81114947 0.72254326 0.95192459 0.951399897 0.95126327 0.42223078
#>  [5,] 0.62109239 0.82036285 0.53368441 0.609577638 0.95770196 0.78176532
#>  [6,] 0.15798317 0.14028301 0.16786086 0.721130232 0.12026505 0.10976710
#>  [7,] 0.60762507 0.39975979 0.30258720 0.079593516 0.68285693 0.29445972
#>  [8,] 0.18313928 0.08507452 0.72513271 0.175148558 0.98242925 0.13347101
#>  [9,] 0.53548415 0.52300687 0.93545565 0.001565577 0.61690977 0.97785016
#> [10,] 0.61268840 0.79242280 0.66579138 0.682832249 0.29552433 0.12861223
#> [11,] 0.02285269 0.75992600 0.29770314 0.669310338 0.37183356 0.09179647
#> [12,] 0.54661369 0.01285408 0.56208000 0.121469122 0.92278234 0.34540526
#> [13,] 0.11082417 0.70409820 0.46604256 0.333027097 0.07494696 0.77826994
#> [14,] 0.62141007 0.89720274 0.15137871 0.698055269 0.96939726 0.26709289
#> [15,] 0.21581641 0.57216303 0.30611998 0.198543525 0.20943814 0.66590597
#>             [,7]       [,8]       [,9]        [,10]
#>  [1,] 0.43440352 0.57650644 0.22733193 0.3649530248
#>  [2,] 0.31961944 0.03292251 0.35707223 0.6619656258
#>  [3,] 0.02224331 0.70423637 0.18750135 0.0239865310
#>  [4,] 0.79023252 0.23278560 0.73238780 0.1729770296
#>  [5,] 0.26488071 0.19731806 0.24182929 0.9892862563
#>  [6,] 0.48339381 0.98890387 0.54017299 0.5929328585
#>  [7,] 0.49138249 0.34346099 0.79259391 0.1901534691
#>  [8,] 0.13541597 0.86503774 0.04266444 0.7636789670
#>  [9,] 0.86276507 0.14080338 0.19631357 0.3842119260
#> [10,] 0.80015900 0.84150602 0.07044419 0.0007343881
#> [11,] 0.05155363 0.86386255 0.92814694 0.3528383242
#> [12,] 0.10291457 0.77807259 0.49302760 0.8683910659
#> [13,] 0.04587278 0.52598821 0.80729416 0.8719049015
#> [14,] 0.36086152 0.01247894 0.24302483 0.6396591999
#> [15,] 0.99827848 0.93412319 0.92121492 0.5341976450

M2 <- log(t(M1[5:1, c(TRUE, FALSE)] + 10))[-1, ]
showtree(M2)
#> 4x5 double: DelayedMatrix object
#> └─ 4x5 double: Stack of 2 unary iso op(s)
#>    └─ 4x5 double: Aperm (perm=c(2,1))
#>       └─ 5x4 double: Subset
#>          └─ 15x10 double: [seed] matrix object

## In the above example, the tree is linear i.e. all the operations
## are represented by unary nodes. The simplest way to know if a
## tree is linear is by counting its leaves with nseed():
nseed(M2)  # only 1 leaf means the tree is linear
#> [1] 1
seed(M2)
#>             [,1]       [,2]       [,3]        [,4]       [,5]       [,6]
#>  [1,] 0.20153719 0.81091811 0.45554721 0.646503825 0.84095686 0.11638252
#>  [2,] 0.34731787 0.58624158 0.50567616 0.091341729 0.61877679 0.83997249
#>  [3,] 0.70488124 0.87164081 0.07006891 0.098296557 0.24399636 0.19848995
#>  [4,] 0.81114947 0.72254326 0.95192459 0.951399897 0.95126327 0.42223078
#>  [5,] 0.62109239 0.82036285 0.53368441 0.609577638 0.95770196 0.78176532
#>  [6,] 0.15798317 0.14028301 0.16786086 0.721130232 0.12026505 0.10976710
#>  [7,] 0.60762507 0.39975979 0.30258720 0.079593516 0.68285693 0.29445972
#>  [8,] 0.18313928 0.08507452 0.72513271 0.175148558 0.98242925 0.13347101
#>  [9,] 0.53548415 0.52300687 0.93545565 0.001565577 0.61690977 0.97785016
#> [10,] 0.61268840 0.79242280 0.66579138 0.682832249 0.29552433 0.12861223
#> [11,] 0.02285269 0.75992600 0.29770314 0.669310338 0.37183356 0.09179647
#> [12,] 0.54661369 0.01285408 0.56208000 0.121469122 0.92278234 0.34540526
#> [13,] 0.11082417 0.70409820 0.46604256 0.333027097 0.07494696 0.77826994
#> [14,] 0.62141007 0.89720274 0.15137871 0.698055269 0.96939726 0.26709289
#> [15,] 0.21581641 0.57216303 0.30611998 0.198543525 0.20943814 0.66590597
#>             [,7]       [,8]       [,9]        [,10]
#>  [1,] 0.43440352 0.57650644 0.22733193 0.3649530248
#>  [2,] 0.31961944 0.03292251 0.35707223 0.6619656258
#>  [3,] 0.02224331 0.70423637 0.18750135 0.0239865310
#>  [4,] 0.79023252 0.23278560 0.73238780 0.1729770296
#>  [5,] 0.26488071 0.19731806 0.24182929 0.9892862563
#>  [6,] 0.48339381 0.98890387 0.54017299 0.5929328585
#>  [7,] 0.49138249 0.34346099 0.79259391 0.1901534691
#>  [8,] 0.13541597 0.86503774 0.04266444 0.7636789670
#>  [9,] 0.86276507 0.14080338 0.19631357 0.3842119260
#> [10,] 0.80015900 0.84150602 0.07044419 0.0007343881
#> [11,] 0.05155363 0.86386255 0.92814694 0.3528383242
#> [12,] 0.10291457 0.77807259 0.49302760 0.8683910659
#> [13,] 0.04587278 0.52598821 0.80729416 0.8719049015
#> [14,] 0.36086152 0.01247894 0.24302483 0.6396591999
#> [15,] 0.99827848 0.93412319 0.92121492 0.5341976450

dimnames(M1) <- list(letters[1:15], LETTERS[1:10])
showtree(M1)
#> 15x10 double: DelayedMatrix object
#> └─ 15x10 double: Set dimnames
#>    └─ 15x10 double: [seed] matrix object

m2 <- matrix(1:20, nrow=10)
Y <- cbind(t(M1[ , 10:1]), DelayedArray(m2), M1[6:15, "A", drop=FALSE])
showtree(Y)
#> 10x18 double: DelayedMatrix object
#> └─ 10x18 double: Abind (along=2)
#>    ├─ 10x15 double: Set dimnames
#>    │  └─ 10x15 double: Aperm (perm=c(2,1))
#>    │     └─ 15x10 double: Subset
#>    │        └─ 15x10 double: [seed] matrix object
#>    ├─ 10x2 integer: [seed] matrix object
#>    └─ 10x1 double: Set dimnames
#>       └─ 10x1 double: Subset
#>          └─ 15x10 double: [seed] matrix object
showtree(Y, show.node.dim=FALSE)
#> DelayedMatrix object
#> └─ Abind (along=2)
#>    ├─ Set dimnames
#>    │  └─ Aperm (perm=c(2,1))
#>    │     └─ Subset
#>    │        └─ [seed] matrix object
#>    ├─ [seed] matrix object
#>    └─ Set dimnames
#>       └─ Subset
#>          └─ [seed] matrix object
nseed(Y)  # the tree is not linear
#> [1] 3

Z <- t(Y[10:1, ])[1:15, ] + 0.4 * M1
showtree(Z)
#> 15x10 double: DelayedMatrix object
#> └─ 15x10 double: N-ary iso op
#>    ├─ 15x10 double: Aperm (perm=c(2,1))
#>    │  └─ 10x15 double: Subset
#>    │     └─ 10x18 double: Abind (along=2)
#>    │        ├─ 10x15 double: Set dimnames
#>    │        │  └─ 10x15 double: Aperm (perm=c(2,1))
#>    │        │     └─ 15x10 double: Subset
#>    │        │        └─ 15x10 double: [seed] matrix object
#>    │        ├─ 10x2 integer: [seed] matrix object
#>    │        └─ 10x1 double: Set dimnames
#>    │           └─ 10x1 double: Subset
#>    │              └─ 15x10 double: [seed] matrix object
#>    └─ 15x10 double: Set dimnames
#>       └─ 15x10 double: Stack of 1 unary iso op(s)
#>          └─ 15x10 double: [seed] matrix object
nseed(Z)  # the tree is not linear
#> [1] 4

## ---------------------------------------------------------------------
## seedApply()
## ---------------------------------------------------------------------
seedApply(Y, class)
#> [[1]]
#> [1] "matrix" "array" 
#> 
#> [[2]]
#> [1] "matrix" "array" 
#> 
#> [[3]]
#> [1] "matrix" "array" 
#> 
seedApply(Y, dim)
#> [[1]]
#> [1] 15 10
#> 
#> [[2]]
#> [1] 10  2
#> 
#> [[3]]
#> [1] 15 10
#>