R/utils.R

Defines functions is_pd_fast

Documented in is_pd_fast

#' Fast Positive Definiteness Check
#'
#' @description
#' Efficiently checks if a matrix is positive definite using Cholesky decomposition.
#'
#' @param M Matrix. The matrix to verify.
#'
#' @return Logical. \code{TRUE} if positive definite, \code{FALSE} otherwise.
#' @export
is_pd_fast <- function(M) {
  if (is.null(M) || any(is.na(M))) return(FALSE)
  !inherits(try(chol(M), silent = TRUE), "try-error")
}

Try the optimflex package in your browser

Any scripts or data that you put into this service are public.

optimflex documentation built on April 11, 2026, 5:06 p.m.