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

View source: R/RcppExports.R

sumsquaredR 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)}
)


dipsaus documentation built on June 27, 2024, 5:10 p.m.