Symmetric matrices are similar to banded matrices in that there
is only access to a particular band of the matrix. The difference
is that in an MTL symmetric matrix, A(i,j) and
A(j,i) refer to the same element. The following is an
example of a symmetric matrix:
the full symmetric matrix
[ 1 2 3 4 5 ]
[ 2 6 7 8 9 ]
[ 3 7 10 11 12 ]
[ 4 8 11 13 14 ]
[ 5 9 12 14 15 ]
the symmetric matrix in packed storage
[ 1 ]
[ 2 6 ]
[ 3 7 10 ]
[ 4 8 11 13 ]
[ 5 9 12 14 15 ]
Similar to the triangle shape, the user must provide an
Uplo argument which specifies which part of the matrix is
actually stored. The valid choices are upper and
lower for symmetric matrices.
typedef matrix < double,
symmetric,
packed<>,
row_major >::type SymmMatrix;
|
In symm_packed_vec_prod.cc:
double da[16];
typedef matrix< double,
symmetric<lower>,
packed<external>,
column_major >::type Matrix;
const Matrix::size_type matrix_size = 5;
Matrix A(da, matrix_size, matrix_size);
typedef dense1D<double> Vec;
Vec y(matrix_size,1),x(matrix_size), Ax(matrix_size);
double alpha=1, beta=0;
// 1 2 3 4 5 1 1000
// 2 6 7 8 9 2 2000
// A = 3 7 10 11 12 x = 3 y = 3000
// 4 8 11 13 14 4 4000
// 5 9 12 14 15 5 5000
//make A
for (i = 0; i < 15; ++i)
da[i] = i + 1;
//make x y
for ( i = 0; i < matrix_size; ++i){
y[i]=1000*(i+1);
x[i]=i+1;
}
mult(A, scaled(x,alpha), scaled(y,beta), y);
More examples can be found in symm_banded_vec_prod.cc
|