R/tINVdst.R

Defines functions tINVdst

Documented in tINVdst

tINVdst <- function(tnsr)
{
  # Performs inverse of 3-mode tensor using the
  # discrete sine transform.

  # Input: tnsr, a 3D tensor
  # Output: The inverse of tnsr, a 3D tensor

  if (tnsr@num_modes != 3)
    stop("tINVdst only implemented for 3d so far")
  modes <- tnsr@modes
  n1 <- modes[1]
  n2 <- modes[2]
  n3 <- modes[3]
  if (n1 !=n2)
    stop("The inverse is only defined for square lateral faces")
  dstz <- aperm(apply(tnsr@data, MARGIN = 1:2, dst), c(2,3,1))
  T_inv <- array(0, dim = c(n1, n2, n3))
  for (j in 1:n3) {
    T_inv[, , j] <- solve(dstz[, , j])
  }
  T_inv <- as.tensor(aperm(apply(T_inv, MARGIN = 1:2, idst), c(2,3,1)))
  return(T_inv)
}

Try the rTensor2 package in your browser

Any scripts or data that you put into this service are public.

rTensor2 documentation built on May 29, 2024, 8:34 a.m.