diff --git a/R/RcppExports.R b/R/RcppExports.R index 1b134bf..0b8bc74 100644 --- a/R/RcppExports.R +++ b/R/RcppExports.R @@ -1,10 +1,6 @@ # Generated by using Rcpp::compileAttributes() -> do not edit by hand # Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393 -matnrnd_cpp <- function(M, U, V) { - .Call(`_bsvarSIGNs_matnrnd_cpp`, M, U, V) -} - # Register entry points for exported C++ functions methods::setLoadAction(function(ns) { .Call(`_bsvarSIGNs_RcppExport_registerCCallable`) diff --git a/src/RcppExports.cpp b/src/RcppExports.cpp index 8866417..ca53f93 100644 --- a/src/RcppExports.cpp +++ b/src/RcppExports.cpp @@ -55,19 +55,6 @@ RcppExport SEXP _bsvarSIGNs_bsvar_sign_cpp(SEXP SSEXP, SEXP YSEXP, SEXP XSEXP, S UNPROTECT(1); return rcpp_result_gen; } -// matnrnd_cpp -arma::mat matnrnd_cpp(const arma::mat& M, const arma::mat& U, const arma::mat& V); -RcppExport SEXP _bsvarSIGNs_matnrnd_cpp(SEXP MSEXP, SEXP USEXP, SEXP VSEXP) { -BEGIN_RCPP - Rcpp::RObject rcpp_result_gen; - Rcpp::RNGScope rcpp_rngScope_gen; - Rcpp::traits::input_parameter< const arma::mat& >::type M(MSEXP); - Rcpp::traits::input_parameter< const arma::mat& >::type U(USEXP); - Rcpp::traits::input_parameter< const arma::mat& >::type V(VSEXP); - rcpp_result_gen = Rcpp::wrap(matnrnd_cpp(M, U, V)); - return rcpp_result_gen; -END_RCPP -} // validate (ensure exported C++ functions exist before calling them) static int _bsvarSIGNs_RcppExport_validate(const char* sig) { @@ -87,7 +74,6 @@ RcppExport SEXP _bsvarSIGNs_RcppExport_registerCCallable() { static const R_CallMethodDef CallEntries[] = { {"_bsvarSIGNs_bsvar_sign_cpp", (DL_FUNC) &_bsvarSIGNs_bsvar_sign_cpp, 8}, - {"_bsvarSIGNs_matnrnd_cpp", (DL_FUNC) &_bsvarSIGNs_matnrnd_cpp, 3}, {"_bsvarSIGNs_RcppExport_registerCCallable", (DL_FUNC) &_bsvarSIGNs_RcppExport_registerCCallable, 0}, {NULL, NULL, 0} }; diff --git a/src/bsvarSIGNs.so b/src/bsvarSIGNs.so index 7c8edff..f72fb8d 100755 Binary files a/src/bsvarSIGNs.so and b/src/bsvarSIGNs.so differ diff --git a/src/utils.cpp b/src/utils.cpp index ee4b029..aa1e9dc 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -2,47 +2,11 @@ using namespace arma; -// Random draw from matrix normal MN(M, U, V) -// [[Rcpp:interface(cpp)]] -// [[Rcpp::export]] -arma::mat matnrnd_cpp(const arma::mat& M, - const arma::mat& U, - const arma::mat& V) { - // vec(A*B*C) = kron(A,C')*vec(B) - // a = chol(A) => a'*a = A, i.e. a' is lower triangular - - mat X = mat(size(M), fill::randn); - return M + chol(U).t() * X * chol(V); -} - - -// [[Rcpp:interface(cpp)]] -arma::mat mvnrnd_inverse_cpp(const arma::mat& mu, const arma::mat& inv_Sigma) { - mat q = chol(inv_Sigma); - mat z = mat(size(mu), fill::randn); - return mu + inv(q) * z; -} - - // log determinant given Cholesky decomposition of some matrix double log_det_lower_cpp(const arma::mat& L) { return 2 * sum(log(diagvec(L))); } -arma::mat inv_chol_cpp(const arma::mat& L) { - return solve(trimatu(L.t()), solve(trimatl(L), eye(size(L)))); -} - -double log_mvnpdf_cpp(const arma::mat& x, - const arma::mat& mu, - const arma::mat& inv_Sigma, - const arma::mat& L) { - double log_det = log_det_lower_cpp(L); - double log_const = -0.5 * (x.n_rows * log(2 * datum::pi) + log_det); - mat z = x - mu; - return log_const - 0.5 * as_scalar(z.t() * inv_Sigma * z); -} - // QR decomposition, where the diagonal elements of R are positive // [[Rcpp:interface(cpp)]] arma::mat qr_sign_cpp(const arma::mat& A) { diff --git a/src/utils.h b/src/utils.h index bf711b2..1ee4c0f 100644 --- a/src/utils.h +++ b/src/utils.h @@ -3,21 +3,8 @@ #include -arma::mat matnrnd_cpp(const arma::mat& M, - const arma::mat& U, - const arma::mat& V); - -arma::mat mvnrnd_inverse_cpp(const arma::mat& mu, const arma::mat& inv_Sigma); - double log_det_lower_cpp(const arma::mat& L); -arma::mat inv_chol_cpp(const arma::mat& L); - -double log_mvnpdf_cpp(const arma::mat& x, - const arma::mat& mu, - const arma::mat& inv_Sigma, - const arma::mat& L); - arma::mat qr_sign_cpp(const arma::mat& A); #endif // _UTILS_H_