short introduction to rcpp - university of warwick · short introduction to rcpp. rcpp and c++...

32
Rcpp and C++ Simple example Inputs Inputs and outputs Matrices Lists Some advice Short introduction to Rcpp Sherman Ip University of Warwick 2nd March 2017 Sherman Ip University of Warwick Short introduction to Rcpp

Upload: others

Post on 25-Jun-2020

24 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Short introduction to Rcpp - University of Warwick · Short introduction to Rcpp. Rcpp and C++ Simple exampleInputsInputs and outputsMatricesListsSome advice Some advice C+11 and

Rcpp and C++ Simple example Inputs Inputs and outputs Matrices Lists Some advice

Short introduction to Rcpp

Sherman Ip

University of Warwick

2nd March 2017

Sherman Ip University of Warwick

Short introduction to Rcpp

Page 2: Short introduction to Rcpp - University of Warwick · Short introduction to Rcpp. Rcpp and C++ Simple exampleInputsInputs and outputsMatricesListsSome advice Some advice C+11 and

Rcpp and C++ Simple example Inputs Inputs and outputs Matrices Lists Some advice

Table of Contents

1 Rcpp and C++

2 Simple example

3 Inputs

4 Inputs and outputs

5 Matrices

6 Lists

7 Some advice

Sherman Ip University of Warwick

Short introduction to Rcpp

Page 3: Short introduction to Rcpp - University of Warwick · Short introduction to Rcpp. Rcpp and C++ Simple exampleInputsInputs and outputsMatricesListsSome advice Some advice C+11 and

Rcpp and C++ Simple example Inputs Inputs and outputs Matrices Lists Some advice

1 Rcpp and C++

2 Simple example

3 Inputs

4 Inputs and outputs

5 Matrices

6 Lists

7 Some advice

Sherman Ip University of Warwick

Short introduction to Rcpp

Page 4: Short introduction to Rcpp - University of Warwick · Short introduction to Rcpp. Rcpp and C++ Simple exampleInputsInputs and outputsMatricesListsSome advice Some advice C+11 and

Rcpp and C++ Simple example Inputs Inputs and outputs Matrices Lists Some advice

Rcpp

Rcpp is an R package which allows you to compile and runC++ code in R.

Eddelbuettel et al. (2011)

Sherman Ip University of Warwick

Short introduction to Rcpp

Page 5: Short introduction to Rcpp - University of Warwick · Short introduction to Rcpp. Rcpp and C++ Simple exampleInputsInputs and outputsMatricesListsSome advice Some advice C+11 and

Rcpp and C++ Simple example Inputs Inputs and outputs Matrices Lists Some advice

C++

Some key words:

Strongly typed

Memory allocation

Pointers

Memory leaks

Object oriented

Sherman Ip University of Warwick

Short introduction to Rcpp

Page 6: Short introduction to Rcpp - University of Warwick · Short introduction to Rcpp. Rcpp and C++ Simple exampleInputsInputs and outputsMatricesListsSome advice Some advice C+11 and

Rcpp and C++ Simple example Inputs Inputs and outputs Matrices Lists Some advice

C++

Some key words:

Strongly typed

Memory allocation

Pointers

Memory leaks

Object oriented

Sherman Ip University of Warwick

Short introduction to Rcpp

Page 7: Short introduction to Rcpp - University of Warwick · Short introduction to Rcpp. Rcpp and C++ Simple exampleInputsInputs and outputsMatricesListsSome advice Some advice C+11 and

Rcpp and C++ Simple example Inputs Inputs and outputs Matrices Lists Some advice

C++

Some key words:

Strongly typed

Memory allocation

Pointers

Memory leaks

Object oriented

Sherman Ip University of Warwick

Short introduction to Rcpp

Page 8: Short introduction to Rcpp - University of Warwick · Short introduction to Rcpp. Rcpp and C++ Simple exampleInputsInputs and outputsMatricesListsSome advice Some advice C+11 and

Rcpp and C++ Simple example Inputs Inputs and outputs Matrices Lists Some advice

C++

Some key words:

Strongly typed

Memory allocation

Pointers

Memory leaks

Object oriented

Sherman Ip University of Warwick

Short introduction to Rcpp

Page 9: Short introduction to Rcpp - University of Warwick · Short introduction to Rcpp. Rcpp and C++ Simple exampleInputsInputs and outputsMatricesListsSome advice Some advice C+11 and

Rcpp and C++ Simple example Inputs Inputs and outputs Matrices Lists Some advice

C++

Some key words:

Strongly typed

Memory allocation

Pointers

Memory leaks

Object oriented

Sherman Ip University of Warwick

Short introduction to Rcpp

Page 10: Short introduction to Rcpp - University of Warwick · Short introduction to Rcpp. Rcpp and C++ Simple exampleInputsInputs and outputsMatricesListsSome advice Some advice C+11 and

Rcpp and C++ Simple example Inputs Inputs and outputs Matrices Lists Some advice

C++

Some key words:

Strongly typed

Memory allocation

Pointers

Memory leaks

Object oriented

Sherman Ip University of Warwick

Short introduction to Rcpp

Page 11: Short introduction to Rcpp - University of Warwick · Short introduction to Rcpp. Rcpp and C++ Simple exampleInputsInputs and outputsMatricesListsSome advice Some advice C+11 and

Rcpp and C++ Simple example Inputs Inputs and outputs Matrices Lists Some advice

1 Rcpp and C++

2 Simple example

3 Inputs

4 Inputs and outputs

5 Matrices

6 Lists

7 Some advice

Sherman Ip University of Warwick

Short introduction to Rcpp

Page 12: Short introduction to Rcpp - University of Warwick · Short introduction to Rcpp. Rcpp and C++ Simple exampleInputsInputs and outputsMatricesListsSome advice Some advice C+11 and

Rcpp and C++ Simple example Inputs Inputs and outputs Matrices Lists Some advice

Simple example

Sherman Ip University of Warwick

Short introduction to Rcpp

Page 13: Short introduction to Rcpp - University of Warwick · Short introduction to Rcpp. Rcpp and C++ Simple exampleInputsInputs and outputsMatricesListsSome advice Some advice C+11 and

Rcpp and C++ Simple example Inputs Inputs and outputs Matrices Lists Some advice

Simple example

Sherman Ip University of Warwick

Short introduction to Rcpp

Page 14: Short introduction to Rcpp - University of Warwick · Short introduction to Rcpp. Rcpp and C++ Simple exampleInputsInputs and outputsMatricesListsSome advice Some advice C+11 and

Rcpp and C++ Simple example Inputs Inputs and outputs Matrices Lists Some advice

Simple example

Sherman Ip University of Warwick

Short introduction to Rcpp

Page 15: Short introduction to Rcpp - University of Warwick · Short introduction to Rcpp. Rcpp and C++ Simple exampleInputsInputs and outputsMatricesListsSome advice Some advice C+11 and

Rcpp and C++ Simple example Inputs Inputs and outputs Matrices Lists Some advice

1 Rcpp and C++

2 Simple example

3 Inputs

4 Inputs and outputs

5 Matrices

6 Lists

7 Some advice

Sherman Ip University of Warwick

Short introduction to Rcpp

Page 16: Short introduction to Rcpp - University of Warwick · Short introduction to Rcpp. Rcpp and C++ Simple exampleInputsInputs and outputsMatricesListsSome advice Some advice C+11 and

Rcpp and C++ Simple example Inputs Inputs and outputs Matrices Lists Some advice

Inputs

Sherman Ip University of Warwick

Short introduction to Rcpp

Page 17: Short introduction to Rcpp - University of Warwick · Short introduction to Rcpp. Rcpp and C++ Simple exampleInputsInputs and outputsMatricesListsSome advice Some advice C+11 and

Rcpp and C++ Simple example Inputs Inputs and outputs Matrices Lists Some advice

Inputs

Sherman Ip University of Warwick

Short introduction to Rcpp

Page 18: Short introduction to Rcpp - University of Warwick · Short introduction to Rcpp. Rcpp and C++ Simple exampleInputsInputs and outputsMatricesListsSome advice Some advice C+11 and

Rcpp and C++ Simple example Inputs Inputs and outputs Matrices Lists Some advice

1 Rcpp and C++

2 Simple example

3 Inputs

4 Inputs and outputs

5 Matrices

6 Lists

7 Some advice

Sherman Ip University of Warwick

Short introduction to Rcpp

Page 19: Short introduction to Rcpp - University of Warwick · Short introduction to Rcpp. Rcpp and C++ Simple exampleInputsInputs and outputsMatricesListsSome advice Some advice C+11 and

Rcpp and C++ Simple example Inputs Inputs and outputs Matrices Lists Some advice

Inputs and outputs

Sherman Ip University of Warwick

Short introduction to Rcpp

Page 20: Short introduction to Rcpp - University of Warwick · Short introduction to Rcpp. Rcpp and C++ Simple exampleInputsInputs and outputsMatricesListsSome advice Some advice C+11 and

Rcpp and C++ Simple example Inputs Inputs and outputs Matrices Lists Some advice

Inputs and outputs

Sherman Ip University of Warwick

Short introduction to Rcpp

Page 21: Short introduction to Rcpp - University of Warwick · Short introduction to Rcpp. Rcpp and C++ Simple exampleInputsInputs and outputsMatricesListsSome advice Some advice C+11 and

Rcpp and C++ Simple example Inputs Inputs and outputs Matrices Lists Some advice

1 Rcpp and C++

2 Simple example

3 Inputs

4 Inputs and outputs

5 Matrices

6 Lists

7 Some advice

Sherman Ip University of Warwick

Short introduction to Rcpp

Page 22: Short introduction to Rcpp - University of Warwick · Short introduction to Rcpp. Rcpp and C++ Simple exampleInputsInputs and outputsMatricesListsSome advice Some advice C+11 and

Rcpp and C++ Simple example Inputs Inputs and outputs Matrices Lists Some advice

Matrices

armadillo is a C++ library for matrix operations. Sandersonet al. (2016)

RcppArmadillo is an R package wich allows you to compileand run C++ code, which uses arma, in R. Eddelbuettel etal. (2014)

Sherman Ip University of Warwick

Short introduction to Rcpp

Page 23: Short introduction to Rcpp - University of Warwick · Short introduction to Rcpp. Rcpp and C++ Simple exampleInputsInputs and outputsMatricesListsSome advice Some advice C+11 and

Rcpp and C++ Simple example Inputs Inputs and outputs Matrices Lists Some advice

Matrices

armadillo is a C++ library for matrix operations. Sandersonet al. (2016)

RcppArmadillo is an R package wich allows you to compileand run C++ code, which uses arma, in R. Eddelbuettel etal. (2014)

Sherman Ip University of Warwick

Short introduction to Rcpp

Page 24: Short introduction to Rcpp - University of Warwick · Short introduction to Rcpp. Rcpp and C++ Simple exampleInputsInputs and outputsMatricesListsSome advice Some advice C+11 and

Rcpp and C++ Simple example Inputs Inputs and outputs Matrices Lists Some advice

Matrices

Sherman Ip University of Warwick

Short introduction to Rcpp

Page 25: Short introduction to Rcpp - University of Warwick · Short introduction to Rcpp. Rcpp and C++ Simple exampleInputsInputs and outputsMatricesListsSome advice Some advice C+11 and

Rcpp and C++ Simple example Inputs Inputs and outputs Matrices Lists Some advice

Matrices

Sherman Ip University of Warwick

Short introduction to Rcpp

Page 26: Short introduction to Rcpp - University of Warwick · Short introduction to Rcpp. Rcpp and C++ Simple exampleInputsInputs and outputsMatricesListsSome advice Some advice C+11 and

Rcpp and C++ Simple example Inputs Inputs and outputs Matrices Lists Some advice

1 Rcpp and C++

2 Simple example

3 Inputs

4 Inputs and outputs

5 Matrices

6 Lists

7 Some advice

Sherman Ip University of Warwick

Short introduction to Rcpp

Page 27: Short introduction to Rcpp - University of Warwick · Short introduction to Rcpp. Rcpp and C++ Simple exampleInputsInputs and outputsMatricesListsSome advice Some advice C+11 and

Rcpp and C++ Simple example Inputs Inputs and outputs Matrices Lists Some advice

Lists

Sherman Ip University of Warwick

Short introduction to Rcpp

Page 28: Short introduction to Rcpp - University of Warwick · Short introduction to Rcpp. Rcpp and C++ Simple exampleInputsInputs and outputsMatricesListsSome advice Some advice C+11 and

Rcpp and C++ Simple example Inputs Inputs and outputs Matrices Lists Some advice

Lists

Sherman Ip University of Warwick

Short introduction to Rcpp

Page 29: Short introduction to Rcpp - University of Warwick · Short introduction to Rcpp. Rcpp and C++ Simple exampleInputsInputs and outputsMatricesListsSome advice Some advice C+11 and

Rcpp and C++ Simple example Inputs Inputs and outputs Matrices Lists Some advice

1 Rcpp and C++

2 Simple example

3 Inputs

4 Inputs and outputs

5 Matrices

6 Lists

7 Some advice

Sherman Ip University of Warwick

Short introduction to Rcpp

Page 30: Short introduction to Rcpp - University of Warwick · Short introduction to Rcpp. Rcpp and C++ Simple exampleInputsInputs and outputsMatricesListsSome advice Some advice C+11 and

Rcpp and C++ Simple example Inputs Inputs and outputs Matrices Lists Some advice

Some advice

C+11 and armadillo libraries are very useful and welldocumented.

Spilt your programe into pure C++ code and code involvingRcpp.

Learn C++ first before Rcpp.

Sherman Ip University of Warwick

Short introduction to Rcpp

Page 31: Short introduction to Rcpp - University of Warwick · Short introduction to Rcpp. Rcpp and C++ Simple exampleInputsInputs and outputsMatricesListsSome advice Some advice C+11 and

Rcpp and C++ Simple example Inputs Inputs and outputs Matrices Lists Some advice

Some advice

C+11 and armadillo libraries are very useful and welldocumented.

Spilt your programe into pure C++ code and code involvingRcpp.

Learn C++ first before Rcpp.

Sherman Ip University of Warwick

Short introduction to Rcpp

Page 32: Short introduction to Rcpp - University of Warwick · Short introduction to Rcpp. Rcpp and C++ Simple exampleInputsInputs and outputsMatricesListsSome advice Some advice C+11 and

Rcpp and C++ Simple example Inputs Inputs and outputs Matrices Lists Some advice

Some advice

C+11 and armadillo libraries are very useful and welldocumented.

Spilt your programe into pure C++ code and code involvingRcpp.

Learn C++ first before Rcpp.

Sherman Ip University of Warwick

Short introduction to Rcpp