From 1f12b811d06098ade34712c65dbff983f1f1d7e8 Mon Sep 17 00:00:00 2001 From: gongyh Date: Thu, 1 Aug 2024 10:00:06 +0800 Subject: [PATCH] fix bugs in constraintUnimod --- R/constraints.R | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/R/constraints.R b/R/constraints.R index c02846a..310da3f 100644 --- a/R/constraints.R +++ b/R/constraints.R @@ -132,13 +132,18 @@ constraintUnimod <- function(x, d, tol = 0) { # process each component separately for (a in seq_len(ncol(x))) { - # flatten peaks to the left of maximum - left_part <- (peak.ind[a] - 1):1 - x[, a] <- f(x[, a], max = x[peak.ind[a], a], indseq = left_part, step = +1) + if (peak.ind[a] != 1) { + # flatten peaks to the left of maximum + left_part <- (peak.ind[a] - 1):1 + x[, a] <- f(x[, a], max = x[peak.ind[a], a], indseq = left_part, step = +1) + } + + if (peak.ind[a] != nvar) { + # flatten peaks to the right of maximum + right_part <- (peak.ind[a] + 1):nvar + x[, a] <- f(x[, a], max = x[peak.ind[a], a], indseq = right_part, step = -1) + } - # flatten peaks to the right of maximum - right_part <- (peak.ind[a] + 1):nvar - x[, a] <- f(x[, a], max = x[peak.ind[a], a], indseq = right_part, step = -1) } return(x)