colprods-package: colprods: Calculate column products of numeric matrices

Description Functions Author(s) See Also Examples

Description

A lightweight package containing various functions for calculating the column products of numeric matrices. Each function performs essentially the same task but each uses a different implementation under the hood. The main purpose of this package is to provide a simple example to remind myself how to incorporate Rcpp and RcppArmadillo functions within a package.

Functions

colprods_arma
colprods_rcpp
colprods_rcpp_rowwise
colprods_apply
colprods_sapply
colprods_for_loop

Author(s)

Maintainer: Darren Kidney darrenkidney@yahoo.co.uk

See Also

Useful links:

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
## Not run: 

library(colprods)

# simple example -----

x = matrix(1:9, 3)
colprods_for_loop(x)
colprods_sapply(x)
colprods_apply(x)
colprods_rcpp(x)
colprods_rcpp_rowwise(x)
colprods_arma(x)
as.numeric(colprods_arma(x))

# benchmarking -----

library(microbenchmark)

# tall
nr = 1000
nc = 100
x = matrix(rnorm(nr * nc), nr, nc)
microbenchmark(
    colprods_for_loop(x),
    colprods_sapply(x),
    colprods_apply(x),
    colprods_rcpp(x),
    colprods_rcpp_rowwise(x),
    colprods_arma(x),
    as.numeric(colprods_arma(x))
)

# wide
nr = 100
nc = 1000
x = matrix(rnorm(nr * nc), nr, nc)
microbenchmark(
    colprods_for_loop(x),
    colprods_apply(x),
    colprods_sapply(x),
    colprods_rcpp(x),
    colprods_rcpp_rowwise(x),
    colprods_arma(x),
    as.numeric(colprods_arma(x))
)

## End(Not run)

dkidney/colprods documentation built on May 13, 2019, 10:27 a.m.