fold-methods {DelayedTensor} | R Documentation

## Tensor folding of 2D DelayedArray

### Description

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 `row_idx` and `col_idx`, then we can fold the resulting matrix back into the original Tensor using the same `row_idx` and `col_idx`.

### Usage

    fold(mat, row_idx = NULL, col_idx = NULL, modes = NULL)

    ## S4 method for signature 'DelayedArray'
    fold(mat, row_idx, col_idx, modes)

### Arguments

`mat` | DelayedArray object (only 2D)
`row_idx` | the indices of the modes that are mapped onto the row space
`col_idx` | the indices of the modes that are mapped onto the column space
`modes` | the modes of the output DelayedArray

### Details

This function is an extension of the `fold` by DelayedArray.

### Value

DelayedArray object with modes given by `modes`

### References

T. Kolda, B. Bader, "Tensor decomposition and applications". SIAM Applied Mathematics and Applications 2009.

### See Also

`unfold`, `k_fold`, `unmatvec`, `rs_fold`, `cs_fold`

### Examples

    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))

[Package DelayedTensor version 1.0.0 Index]