Skip to content

Commit

Permalink
Merge pull request #771 from nlmixr2/771-lotri-nearPD
Browse files Browse the repository at this point in the history
Use lotri's nearPD
  • Loading branch information
mattfidler authored Aug 15, 2024
2 parents 6296051 + 82db8ad commit 05c75ff
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 20 deletions.
5 changes: 0 additions & 5 deletions R/nearpd.R

This file was deleted.

6 changes: 4 additions & 2 deletions src/cvPost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@
#include "../inst/include/rxode2_as.h"
#include <lotri.h>

extern "C" {
iniLotri;
}

extern "C" SEXP chin(SEXP a, SEXP b);

// place links here
iniLotri;

List etTrans(List inData, const RObject &mv, bool addCmt,
bool dropUnits, bool allTimeVar,
Expand Down
17 changes: 8 additions & 9 deletions src/nearPD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,26 @@
#define STRICT_R_HEADER
#include <RcppArmadillo.h>
#include "nearPD.h"
#include <lotri.h>

lotriNearPDarmaSetup

using namespace arma;
using namespace Rcpp;

Function getRxFn(std::string name);

bool rxNearPD(arma::mat &ret, const arma::mat in) {
Function mnearpd = getRxFn(".nearPD");
RObject retRO = mnearpd(in);
if (Rf_isMatrix(retRO)) {
ret = as<arma::mat>(retRO);
if (lotriNearPDarma(ret, in)) {
return true;
} else {
ret = in;
return false;
}
ret = in;
return false;
return false; // nocov
}

unsigned int rxNearPdChol(Rcpp::NumericMatrix &ret, Rcpp::NumericMatrix x, bool isChol) {
arma::mat tmpM = as<arma::mat>(x);
arma::mat reta;

if (!x.hasAttribute("dimnames")) {
return rxNearPdChol_not_named;
} else if (isChol) {
Expand Down
4 changes: 0 additions & 4 deletions tests/testthat/test-nearpd.R
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,3 @@ rxTest({
NA)
})
})

test_that(".nearPD expected null for matrix that cannot become positive definite", {
expect_null(.nearPD(matrix(Inf)))
})

0 comments on commit 05c75ff

Please sign in to comment.