# Set ncores = 2 to comply to CRAN policy. Please don't run this line
ravetools_threads(n_threads = 2L)
x <- matrix(rnorm(400), nrow = 100)
# Call `cov(x)` to compare
fast_cov(x)
# Calculate covariance of subsets
fast_cov(x, col_x = 1, col_y = 1:2)
# \donttest{
# Speed comparison, better to use multiple cores (4, 8, or more)
# to show the differences.
ravetools_threads(n_threads = -1)
x <- matrix(rnorm(100000), nrow = 1000)
microbenchmark::microbenchmark(
fast_cov = {
fast_cov(x, col_x = 1:50, col_y = 51:100)
},
cov = {
cov(x[,1:50], x[,51:100])
},
unit = 'ms', times = 10
)
# }
Run the code above in your browser using DataLab