Learn R Programming

spatstat.sparse (version 3.1-0)

Math.sparse3Darray: S3 Group Generic Methods for Sparse Three-Dimensional Arrays

Description

Group generic methods which make it possible to apply the familiar mathematical operators and functions to sparse three-dimensional arrays (objects of class "sparse3Darray"). See Details for a list of implemented functions.

Usage

## S3 methods for group generics have prototypes:
Math(x, ...)
Ops(e1, e2)
Complex(z)
Summary(..., na.rm=FALSE)



Value

The result of group "Math" functions is another three-dimensional array of the same dimensions as x, which is sparse if the function maps 0 to 0, and otherwise is a full three-dimensional array.

The result of group "Ops" operators is another three-dimensional array of the same dimensions as

e1 and e2, which is sparse if both e1 and

e2 are sparse.

The result of group "Complex" functions is another sparse three-dimensional array of the same dimensions as

z.

The result of group "Summary" functions is a logical value or a numeric value or a numeric vector of length 2.

Arguments

x, z, e1, e2

Sparse three-dimensional arrays (objects of class "sparse3Darray"). Alternatively e1 or e2 can be a single scalar, vector, sparse vector, matrix or sparse matrix.

...

further arguments passed to methods.

na.rm

Logical value specifying whether missing values should be removed.

Author

Adrian Baddeley Adrian.Baddeley@curtin.edu.au, Rolf Turner rolfturner@posteo.net and Ege Rubak rubak@math.aau.dk.

Details

These group generics make it possible to perform element-wise arithmetic and logical operations with sparse three-dimensional arrays, or apply mathematical functions element-wise, or compute standard summaries such as the mean and maximum.

Below is a list of mathematical functions and operators which are defined for sparse 3D arrays.

  1. Group "Math":

    • abs, sign, sqrt,
      floor, ceiling, trunc,
      round, signif

    • exp, log, expm1, log1p,
      cos, sin, tan,
      cospi, sinpi, tanpi,
      acos, asin, atan

      cosh, sinh, tanh,
      acosh, asinh, atanh

    • lgamma, gamma, digamma, trigamma

    • cumsum, cumprod, cummax, cummin

  2. Group "Ops":

    • "+", "-", "*", "/", "^", "%%", "%/%"

    • "&", "|", "!"

    • "==", "!=", "<", "<=", ">=", ">"

  3. Group "Summary":

    • all, any

    • sum, prod

    • min, max

    • range

  4. Group "Complex":

    • Arg, Conj, Im, Mod, Re

See Also

sparse3Darray, tensorSparse

Examples

Run this code
  M <- sparse3Darray(i=1:4, j=sample(1:4, replace=TRUE),
                     k=c(1,2,1,2), x=1:4, dims=c(5,5,2))
  negM <- -M
  twoM <- M + M
  Mplus <- M + 1 ## not sparse!
  posM <- (M > 0)
  range(M)
  sinM <- sin(M)
  cosM <- cos(M) ## not sparse!
  expM1 <- expm1(M)

Run the code above in your browser using DataLab