Packed storage matrix

From testwiki
Revision as of 23:43, 27 December 2024 by 213.93.115.13 (talk) (Triangular packed matrices)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Template:Short description Template:More sources needed

A packed storage matrix, also known as packed matrix, is a term used in programming for representing an m×n matrix. It is a more compact way than an m-by-n rectangular array by exploiting a special structure of the matrix.

Typical examples of matrices that can take advantage of packed storage include:

Triangular packed matrices

The packed storage matrix allows a matrix to be converted to an array, shrinking the matrix significantly. In doing so, a square n×n matrix is converted to an array of length Template:Math.[1]

Consider the following upper matrix:

𝐔=(a11a12a13a14a22a23a24a33a34a44)

which can be packed into the one array:

𝐔𝐏=(a11 a12 a22 a13 a23 a33 a14, a24 a34 a44)[2]


Similarly the lower matrix:

𝐋=(a11a21a22a31a32a33a41a42a43a44).

can be packed into the following one dimensional array:

LP=(a11 a21 a31 a41 a22 a32 a42 a33 a43 a44)[2]

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 matrix
complex :: 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 A
do 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 do

An example of packed storage for banded matrix:

real :: A(m,n) ! a banded matrix with kl subdiagonals and ku superdiagonals
real :: 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 A
do j = 1, n
  forall(i=max(1,j-kl):min(m,j+ku)) A(i,j) = AP(i-j,j)
end do
print *,AP(0,:) ! the diagonal


See also

Further reading

References

Template:Reflist

Template:Matrix-stub