R/z_matrixes.R

Defines functions m2v v2m AddByRow MulByRow

Documented in AddByRow m2v MulByRow v2m

# COMMON #######################################################################

# =============================================================================.
#' ** RESERVED FOR INTERNAL USE **
# -----------------------------------------------------------------------------.
#' @keywords internal
#' @export
m2v <- function(i, j, nrow) {
  (j - 1) * nrow + i
}

# =============================================================================.
#' ** RESERVED FOR INTERNAL USE **
# -----------------------------------------------------------------------------.
#' @keywords internal
#' @export
v2m <- function(x, nrow) {
  j <- (x - 1) %/% nrow + 1
  i <- (x - 1) %% nrow + 1
  x <- cbind(i, j)
  attributes(x) <- attributes(x)[1] # remove auto-generated dimnames
  x
}


# =============================================================================.
#' ** RESERVED FOR INTERNAL USE **
# -----------------------------------------------------------------------------.
#' @keywords internal
#' @export
AddByRow <- function(m, v) {
  m + rep(v, rep(dim(m)[1], dim(m)[2]))
}

# =============================================================================.
#' ** RESERVED FOR INTERNAL USE **
# -----------------------------------------------------------------------------.
#' @keywords internal
#' @export
MulByRow <- function(m, v) {
  m * rep(v, rep(dim(m)[1], dim(m)[2]))
}
benja0x40/Tightrope documentation built on May 24, 2019, 1:35 a.m.