#' Column wise kronecker product
#'
#' This is a special case of the "Khatri-Rao Product".
#'
#' @seealso \code{\link{rowKronecker}}
#'
#' @export
colKronecker <- function(A, B) {
    sapply(seq_len(ncol(A)), function(i) kronecker(A[, i], B[, i]))
}

#' Row wise kronecker product
#'
#' Also known as the "Face-splitting product". This is a special case of the
#' "Khatri-Rao Product".
#'
#' @seealso \code{\link{colKronecker}}
#'
#' @export
rowKronecker <- function(A, B) {
    C <- vapply(seq_len(ncol(A)), function(i) A[, i] * B, B)
    dim(C) <- c(nrow(A), ncol(A) * ncol(B))
    C
}
