unpack {Matrix} | R Documentation

## Representation of Packed and Unpacked (Dense) Matrices

### Description

“Packed” matrix storage here applies to dense matrices (`denseMatrix`) only, and there is available only for symmetric (`symmetricMatrix`) or triangular (`triangularMatrix`) matrices, where only one triangle of the matrix needs to be stored.

`unpack()` unpacks “packed” matrices, where
`pack()` produces “packed” matrices.

### Usage

    pack(x, ...)
    ## S4 method for signature 'matrix'
    pack(x, symmetric = NA, upperTri = NA, ...)

    unpack(x, ...)

### Arguments

`x`

for `unpack()`:

  a matrix stored in packed form, e.g., of class `"d?pMatrix"` where "?" is "t" for triangular or "s" for symmetric.

for `pack()`:

  a (symmetric or triangular) matrix stored in full storage.

`symmetric` | logical (including `NA`) for optionally specifying if `x` is symmetric (or rather triangular).
`upperTri` | (for the triangular case only) logical (incl. `NA`) indicating if `x` is upper (or lower) triangular.
`...` | further arguments passed to or from other methods.

### Details

These are generic functions with special methods for different types of packed (or non-packed) symmetric or triangular dense matrices. Use `showMethods("unpack")` to list the methods for `unpack()`, and similarly for `pack()`.

### Value

for `unpack()`:

  A `Matrix` object containing the full-storage representation of `x`.

for `pack()`:

  A packed `Matrix` (i.e. of class `"..pMatrix"`) representation of `x`.

### Examples

    showMethods("unpack")
    (cp4 <- chol(Hilbert(4))) # is triangular
    tp4 <- as(cp4,"dtpMatrix")# [t]riangular [p]acked
    str(tp4)
    (unpack(tp4))
    stopifnot(identical(tp4, pack(unpack(tp4))))

    (s <- crossprod(matrix(sample(15), 5,3))) # traditional symmetric matrix
    (sp <- pack(s))
    mt <- as.matrix(tt <- tril(s))
    (pt <- pack(mt))
    stopifnot(identical(pt, pack(tt)),
    	  dim(s ) == dim(sp), all(s  == sp),
    	  dim(mt) == dim(pt), all(mt == pt), all(mt == tt))
    showMethods("pack")

[Package Matrix version 1.2-7.1 Index]