sumsquared: Fast Calculation of Sum-squared for Large Matrices/Vectors

Description Arguments Value Examples

View source: R/RcppExports.R

Description

Calculate sum(x^2), but faster when the number of elements exceeds 1000.

Arguments

x

double, integer, or logical vector/matrix

Value

A numerical scalar

Examples

1
2
3
4
5
6
7
8
x <- rnorm(10000)
sumsquared(x)

# Compare speed
microbenchmark::microbenchmark(
  cpp = {sumsquared(x)},
  r = {sum(x^2)}
)

dipsaus documentation built on Sept. 6, 2021, 5:08 p.m.