tensor_predictors/tensorPredictors/R/ttt.R

15 lines
419 B
R
Raw Normal View History

#' Tensor Times Tensor
#'
#' @examples
#' A <- array(rnorm(3 * 7 * 11 * 17), dim = c(3, 7, 11, 17))
#' B <- array(rnorm(17 * 2 * 11 * 5 * 7), dim = c(17, 2, 11, 5, 7))
#'
#' ttt(A, B, 2:4, c(5, 3, 1))
#'
#' @export
ttt <- function(A, B, modesA, modesB = modesA, dimsA = dim(A), dimsB = dim(B)) {
R <- crossprod(mat(A, modesA, dimsA), mat(B, modesB, dimsB))
dim(R) <- c(dim(A)[-modesA], dim(B)[-modesB])
R
}