Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

  • 9f75b2a
  • /
  • Rcpp-tests.R
Raw File Download

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • content
  • directory
content badge
swh:1:cnt:ce9a122e7202635a77dfefd3eb33b1329c824d64
directory badge
swh:1:dir:9f75b2a0b81b3df42aafc88986a69c92f0923bb6

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • content
  • directory
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Rcpp-tests.R
require(Rcpp)
require(RcppArmadillo)
require(inline)

src <- '
#include <RcppArmadillo.h>
// [[Rcpp::depends(RcppArmadillo)]]
using namespace Rcpp;
using namespace arma;
// [[Rcpp::export]]
SEXP testRcpp(NumericVector x_) {
 vec x(x_);
 uvec index = find(x);
 return wrap(x);
}
'
sourceCpp(code=src)

testRcpp(map0)

time0 <- c(0,10,0,20)
ind0 <- time0>0
map0 <- vector("integer",)
map0[ind0] <- as.integer(1:sum(ind0))
map0[!ind0] <- NaN
## which0 <- which(ind0)
which0 <- 1:length(time0)
which0[!ind0] <- NaN


##    uvec find0() { return map0(find(ind0)); }
##    uvec find0(uvec index) { return (map0(index))(find(ind0(index))); }

src <- '
#include <RcppArmadillo.h>
// [[Rcpp::depends(RcppArmadillo)]]
using namespace Rcpp;
using namespace arma;
    uvec removeNaN(vec x) {
      vec newx = x;
      uvec index = find(newx == newx); // NaN != NaN
      newx = newx(index);
      return conv_to<uvec>::from(newx);
    }
// [[Rcpp::export]]
uvec testRcpp(NumericVector x_) {
  vec x = as<vec>(x_);
  uvec index = find(x==x);
  return index;
}
'
sourceCpp(code=src)

testRcpp(map0)
testRcpp(which0)



testRcpp(1:10)

src <- '
#include <RcppArmadillo.h>
// [[Rcpp::depends(RcppArmadillo)]]
using namespace Rcpp;
using namespace arma;
// [[Rcpp::export]]
double testRcpp(double x) {
 return R::lgammafn(x);
}
'
sourceCpp(code=src)
testRcpp(3.0) - log(gamma(3.0))

back to top

Software Heritage — Copyright (C) 2015–2025, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Content policy— Contact— JavaScript license information— Web API