Skip to content

Commit 3b6f89e

Browse files
committed
fix: validate partition sums correctly for matrix vs vector input
Avoid applying `sum()` to matrix inputs by checking `rowSums()` for matrices and `sum()` for vectors, preventing incorrect partition validation errors
1 parent b398229 commit 3b6f89e

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

R/Utility.R

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,16 @@ GetRankPart <- function(
124124
return(
125125
Map(function(obj) {
126126
if (!is.numeric(obj)) stop(msg_cls)
127-
if ((is.matrix(obj) && any(rowSums(obj) != target)) ||
128-
sum(obj) != target) stop(msg_part)
127+
128+
if (is.matrix(obj)) {
129+
if (any(rowSums(obj) != target)) stop(msg_part)
130+
} else {
131+
if (sum(obj) != target) stop(msg_part)
132+
}
133+
129134
idx <- match(if (is.matrix(obj)) t(obj) else obj, v)
130135
if (any(is.na(idx))) stop(msg_sub)
136+
131137
.Call(`_RcppAlgos_RankPartitionMain`, idx, v, repetition, freqs,
132138
if (is.matrix(obj)) ncol(obj) else length(obj),
133139
"==", target, NULL, IsComposition, weak,

0 commit comments

Comments
 (0)