General folding of a 2D DelayedArray into a higher-order DelayedArray(Tensor).
This is designed to be the inverse function to
unfold, with the same ordering of the indices.
This amounts to following: if we were to unfold a Tensor using a set of
col_idx, then we can fold the resulting matrix
back into the original Tensor using the same
fold(mat, row_idx = NULL, col_idx = NULL, modes = NULL) ## S4 method for signature 'DelayedArray' fold(mat, row_idx, col_idx, modes)
DelayedArray object (only 2D)
the indices of the modes that are mapped onto the row space
the indices of the modes that are mapped onto the column space
the modes of the output DelayedArray
This function is an extension of the
DelayedArray object with modes given by
T. Kolda, B. Bader, "Tensor decomposition and applications". SIAM Applied Mathematics and Applications 2009.
library("DelayedRandomArray") darr <- RandomUnifArray(c(2,3,4)) matT3 <- DelayedTensor::unfold(darr, row_idx=2, col_idx=c(3,1)) identical( as.array(DelayedTensor::fold(matT3, row_idx=2,col_idx=c(3,1), modes=c(2,3,4))), as.array(darr))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.