Improved handling of 0-dim on repmat

This commit is contained in:
Waldir Leoncio 2021-02-15 09:03:44 +01:00
parent 4bb450c6c1
commit 1b5d97a041

View file

@ -15,6 +15,12 @@ repmat <- function (mx, n) {
if (length(n) > 3) warning("Extra dimensions of n ignored")
if (!is(mx, "matrix")) mx <- t(as.matrix(mx))
if (length(n) == 1) n <- rep(n, 2)
if (any(n == 0)) {
n_zero <- which(n == 0)
out_dim <- dim(mx)
out_dim[n_zero] <- 0
return(array(dim=out_dim))
}
# Replicating cols
out <- mx_col <- matrix(rep(mx, n[2]), nrow(mx))