sumsquared {dipsaus} | R Documentation |
Fast Calculation of Sum-squared for Large Matrices/Vectors
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
x <- rnorm(10000)
sumsquared(x)
# Compare speed
microbenchmark::microbenchmark(
cpp = {sumsquared(x)},
r = {sum(x^2)}
)
[Package dipsaus version 0.2.9 Index]