Skip to contents

SparseArray derivatives support operations from the Compare group, with some restrictions. See ?S4groupGeneric in the methods package for more information about the Compare group generic.

IMPORTANT NOTE: Only SVT_SparseArray objects are supported at the moment. Support for COO_SparseArray objects might be added in the future.

Details

Two forms of 'Compare' operations are supported:

  1. Between an SVT_SparseArray object svt and a single value y:

        svt op y
        y op svt

    All operations from the Compare group support this form, with single value y either on the left or the right. However, there are some operation-dependent restrictions on the value of y.

  2. Between two SVT_SparseArray objects svt1 and svt2 of same dimensions (a.k.a. conformable arrays):

        svt1 op svt2

    The Compare operations that support this form are: !=, <, >.

Value

A SparseArray derivative of type() "logical" and same dimensions as the input object(s).

See also

Examples

svt1 <- SVT_SparseArray(dim=c(15, 6), type="double")
svt1[c(2, 6, 12:17, 22:33, 55, 59:62, 90)] <- runif(26)
svt1
#> <15 x 6 SparseMatrix> of type "double" [nzcount=26 (29%)]:
#>             [,1]       [,2]       [,3]       [,4]       [,5]       [,6]
#>  [1,] 0.00000000 0.01648519 0.91427766 0.00000000 0.10346918 0.00000000
#>  [2,] 0.91347572 0.28147595 0.51921186 0.00000000 0.55846562 0.00000000
#>  [3,] 0.00000000 0.00000000 0.24007467 0.00000000 0.00000000 0.00000000
#>  [4,] 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000
#>  [5,] 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000 0.00000000
#>   ...          .          .          .          .          .          .
#> [11,]  0.0000000  0.8335225  0.0000000  0.0000000  0.0000000  0.0000000
#> [12,]  0.7492544  0.2709065  0.0000000  0.0000000  0.0000000  0.0000000
#> [13,]  0.4031877  0.8099838  0.0000000  0.0000000  0.0000000  0.0000000
#> [14,]  0.1289116  0.8533268  0.0000000  0.1044345  0.0000000  0.0000000
#> [15,]  0.1260521  0.4640081  0.0000000  0.7468509  0.0000000  0.2328112

svt1 >= 0.2
#> <15 x 6 SparseMatrix> of type "logical" [nzcount=20 (22%)]:
#>        [,1]  [,2]  [,3]  [,4]  [,5]  [,6]
#>  [1,] FALSE FALSE  TRUE FALSE FALSE FALSE
#>  [2,]  TRUE  TRUE  TRUE FALSE  TRUE FALSE
#>  [3,] FALSE FALSE  TRUE FALSE FALSE FALSE
#>  [4,] FALSE FALSE FALSE FALSE FALSE FALSE
#>  [5,] FALSE FALSE FALSE FALSE FALSE FALSE
#>   ...     .     .     .     .     .     .
#> [11,] FALSE  TRUE FALSE FALSE FALSE FALSE
#> [12,]  TRUE  TRUE FALSE FALSE FALSE FALSE
#> [13,]  TRUE  TRUE FALSE FALSE FALSE FALSE
#> [14,] FALSE  TRUE FALSE FALSE FALSE FALSE
#> [15,] FALSE  TRUE FALSE  TRUE FALSE  TRUE
svt1 != 0
#> <15 x 6 SparseMatrix> of type "logical" [nzcount=26 (29%)]:
#>        [,1]  [,2]  [,3]  [,4]  [,5]  [,6]
#>  [1,] FALSE  TRUE  TRUE FALSE  TRUE FALSE
#>  [2,]  TRUE  TRUE  TRUE FALSE  TRUE FALSE
#>  [3,] FALSE FALSE  TRUE FALSE FALSE FALSE
#>  [4,] FALSE FALSE FALSE FALSE FALSE FALSE
#>  [5,] FALSE FALSE FALSE FALSE FALSE FALSE
#>   ...     .     .     .     .     .     .
#> [11,] FALSE  TRUE FALSE FALSE FALSE FALSE
#> [12,]  TRUE  TRUE FALSE FALSE FALSE FALSE
#> [13,]  TRUE  TRUE FALSE FALSE FALSE FALSE
#> [14,]  TRUE  TRUE FALSE  TRUE FALSE FALSE
#> [15,]  TRUE  TRUE FALSE  TRUE FALSE  TRUE

## Sanity checks:
m1 <- as.matrix(svt1)
stopifnot(
  identical(as.matrix(svt1 >= 0.2), m1 >= 0.2),
  identical(as.matrix(svt1 != 0), m1 != 0)
)