Skip to contents

Sum operation for vector/matrix/array or LazyTensor, or sum reduction for LazyTensor.

Usage

sum(x, ...)

Arguments

x

input for sum.default() or sum.LazyTensor().

...

optional arguments for sum.default() or sum.LazyTensor().

Value

Sum of input.

Details

If x is a LazyTensor, see sum.LazyTensor(), else see sum.default().

Author

Chloe Serre-Combe, Amelie Vernay

Examples

if (FALSE) {
# R base operation
sum(1:10)
sum(c(NA, 1, 2), na.rm = TRUE)
# LazyTensor operation
x <- matrix(runif(150 * 3), 150, 3) # arbitrary R matrix, 150 rows, 3 columns
x_i <- LazyTensor(x, index = 'i')   # creating LazyTensor from matrix x, 
                                    # indexed by 'i'

sum_x <- sum(x_i)                   # LazyTensor object
sum_red_x <- sum(x_i, "i")          # sum reduction indexed by 'i'
}