- Packed storage matrix
Packed storage matrix, also known as packed matrix, is a term used in
programming for representing an matrix. It is a more compact way than an m-by-n rectangulararray by exploiting a special structure of the matrix.Typical examples of matrices that can take advantage of packed storage include:
* symmetric orhermitian matrix
*Triangular matrix
*Banded matrix These are most notably used inBLAS andLAPACK . Various storage schemes for sparse matrices can also be regarded as packed storage.For a symmetric, hermitian or triangular matrix, only the lower or upper triangle of the matrix needs to be stored. A banded matrix can be represented by storing the band only. Packed storage saves memory at the cost of more complicatedaccess to matrix elements. Because of this tradeoff, it is not always beneficial.
Code examples (Fortran)
Both of the following storage schemes are used extensively in BLAS and LAPACK.
An example of packed storage for hermitian matrix:
complex:: A(n,n) ! a hermitian matrixcomplex:: AP(n*(n+1)/2) ! packed storage for A! the lower triangle of A is stored column-by-column in AP.! unpacking the matrix AP to Ado j=1,n k = j*(j-1)/2 A(1:j,j) = AP(1+k:j+k) A(j,1:j-1) = conjg(AP(1+k:j-1+k))end doAn example of packed storage for banded matrix:
real:: A(m,n) ! a banded matrix with kl subdiagonals and ku superdiagonalsreal:: AP(-kl:ku,n) ! packed storage for A! the band of A is stored column-by-column in AP. Some elements of AP are unused.! unpacking the matrix AP to Ado j=1,n forall(i=max(1,j-kl):min(m,j+ku)) A(i,j) = AP(i-j,j)end doprint *,AP(0,:) ! the diagonal
Wikimedia Foundation. 2010.