Skip to content

Instantly share code, notes, and snippets.

@abikoushi
Created October 10, 2024 05:35
Show Gist options
  • Select an option

  • Save abikoushi/3b6b7d05749b93cb9fd11cb6916f9c7c to your computer and use it in GitHub Desktop.

Select an option

Save abikoushi/3b6b7d05749b93cb9fd11cb6916f9c7c to your computer and use it in GitHub Desktop.
Sum of the all of the outer product (for Rcpp)
#include "RcppArmadillo.h"
// [[Rcpp::depends(RcppArmadillo)]]
using namespace Rcpp;
using namespace arma;
// [[Rcpp::export]]
double sumouterprod(const arma::field<arma::vec> & V){
int K = V.n_rows;
arma::vec tout = V(0);
for(int j=1; j<K; j++){
arma::vec V1 = V(j);
tout = vectorise(tout * V1.t());
}
return sum(tout);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment