'Math' and 'Math2' methods for SparseArray objects
SparseArray-Math-methods.Rd
SparseArray derivatives support a subset of operations
from the Math
and Math2
groups.
See ?S4groupGeneric
in the methods package
for more information about the Math
and Math2
group generics.
IMPORTANT NOTES:
Only operations from these groups that preserve sparsity are supported. For example,
sqrt()
,trunc()
,log1p()
, andsin()
are supported, butcumsum()
,log()
,cos()
, orgamma()
are not.Only SVT_SparseArray objects are supported at the moment. Support for COO_SparseArray objects might be added in the future.
Math
andMath2
operations only support SVT_SparseArray objects oftype()
"double"
at the moment.
Value
A SparseArray derivative of the same dimensions as the input object.
See also
S4groupGeneric
in the methods package.SparseArray objects.
Ordinary array objects in base R.
Examples
m <- matrix(0, nrow=15, ncol=6)
m[c(2, 6, 12:17, 22:33, 55, 59:62, 90)] <-
c(runif(22)*1e4, Inf, -Inf, NA, NaN)
svt <- SparseArray(m)
svt2 <- trunc(sqrt(svt))
#> Warning: NaNs produced
svt2
#> <15 x 6 SparseMatrix> of type "double" [nzcount=26 (29%)]:
#> [,1] [,2] [,3] [,4] [,5] [,6]
#> [1,] 0 82 55 0 NaN 0
#> [2,] 70 76 83 0 NA 0
#> [3,] 0 0 97 0 0 0
#> [4,] 0 0 0 0 0 0
#> [5,] 0 0 0 0 0 0
#> ... . . . . . .
#> [11,] 0 12 0 0 0 0
#> [12,] 87 58 0 0 0 0
#> [13,] 92 58 0 0 0 0
#> [14,] 63 97 0 54 0 0
#> [15,] 89 5 0 Inf 0 NaN
## Sanity check:
m2 <- suppressWarnings(trunc(sqrt(m)))
stopifnot(identical(as.matrix(svt2), m2))