Created
October 10, 2024 05:35
-
-
Save abikoushi/3b6b7d05749b93cb9fd11cb6916f9c7c to your computer and use it in GitHub Desktop.
Sum of the all of the outer product (for Rcpp)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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