![]() 'Cause what we will do is take this value of zero and successively add in each element of the vector X. And we will initialize it with a value of zero. This will be a double and we will call it result. ![]() The first thing we have to do is declare a variable to hold the result. We enclose the body of the function in curly braces just like in R. The one argument for this function will be a numeric vector named x. In reality, this probably won't be any faster than the base R sum function because that is written in either C or fortran and is already completely optimized. The name of the function will be fast sum since it should be fast since it's in C plus plus. In C plus plus we do that by returning a double. So we need to be able to handle a decimal result. When adding up a vector of numbers there could be integers there could be decimals. We're going to create a new function and to ensure it's available in R, we need to export it, so slash, slash and then double square brackets, Rcpp, colon, colon, export. ![]() So we are going to take a look at some of those ways to add up a vector of numbers. With C plus plus and even more so with Rcpp, there is more than one way to do things. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |