42 #include "DenseLinAlgPack_PermVecMat.hpp"
43 #include "DenseLinAlgPack_DMatrixClass.hpp"
44 #include "DenseLinAlgPack_IVector.hpp"
46 #ifdef TEUCHOS_DEBUG // Debug only!
47 bool DenseLinAlgPack::PermVecMat_print =
false;
49 #include "DenseLinAlgPack_PermOut.hpp"
50 #include "DenseLinAlgPack_DVectorOut.hpp"
55 inline void i_assert_perm_size(
size_t size1,
size_t size2)
57 #ifdef LINALGPACK_CHECK_RHS_SIZES
59 throw std::length_error(
"The size of the permutation vector is not correct");
65 void DenseLinAlgPack::identity_perm(IVector* perm) {
67 throw std::length_error(
"DenseLinAlgPack::identity_perm(): perm must be sized");
68 IVector::iterator itr_perm = perm->begin();
69 for(
size_type i = 1; i <= perm->size(); ++i)
73 void DenseLinAlgPack::inv_perm(
const IVector& perm, IVector* inv_perm) {
74 inv_perm->resize(perm.size());
75 for(
size_type i = 1; i <= perm.size(); ++i)
76 (*inv_perm)(perm(i)) = i;
79 void DenseLinAlgPack::perm_ele(
const IVector& perm, DVectorSlice* vs)
81 i_assert_perm_size(vs->dim(),perm.size());
82 DVector tmp_v(vs->dim());
83 DVector::iterator v_itr = tmp_v.begin(),
84 v_itr_end = tmp_v.end();
85 IVector::const_iterator perm_itr = perm.begin();
87 for(; v_itr != v_itr_end; ++v_itr, ++perm_itr)
88 *v_itr = (*vs)(*perm_itr);
94 void DenseLinAlgPack::perm_ele(
const DVectorSlice& x,
const IVector& perm, DVectorSlice* y)
96 i_assert_perm_size(x.dim(),perm.size());
97 i_assert_perm_size(y->dim(),perm.size());
99 IVector::const_iterator
100 perm_itr = perm.begin();
101 DVectorSlice::iterator
104 while(y_itr != y_end)
105 *y_itr++ = x(*perm_itr++);
108 void DenseLinAlgPack::inv_perm_ele(
const DVectorSlice& y,
const IVector& perm, DVectorSlice* x)
110 i_assert_perm_size(y.dim(),perm.size());
111 i_assert_perm_size(x->dim(),perm.size());
113 if( PermVecMat_print ) {
115 <<
"enter inv_perm_ele(y,perm,x):\n"
118 <<
"perm =\n" << perm
122 DVectorSlice::const_iterator
125 IVector::const_iterator
126 perm_itr = perm.begin();
127 while(y_itr != y_end)
128 (*x)(*perm_itr++) = *y_itr++;
130 if( PermVecMat_print ) {
132 <<
"inv_perm_ele(y,perm,x):\n"
135 <<
"exit inv_perm_ele(...) ...\n";
140 void DenseLinAlgPack::perm_rows(
const IVector& row_perm, DMatrixSlice* gms)
142 i_assert_perm_size(gms->rows(),row_perm.size());
143 DMatrix tmp_gm(gms->rows(),gms->cols());
146 for(i = 1; i <=
rows; ++i)
147 tmp_gm.row(i) = gms->row(row_perm(i));
152 void DenseLinAlgPack::perm_cols(
const IVector& col_perm, DMatrixSlice* gms)
154 i_assert_perm_size(gms->cols(),col_perm.size());
155 DMatrix tmp_gm(gms->rows(),gms->cols());
158 for(i = 1; i <=
cols; ++i)
159 tmp_gm.col(i) = gms->col(col_perm(i));
164 void DenseLinAlgPack::perm_rows_cols(
const IVector& row_perm,
const IVector& col_perm
167 i_assert_perm_size(gms->rows(),row_perm.size());
168 i_assert_perm_size(gms->cols(),col_perm.size());
169 DMatrix tmp_gm(gms->rows(),gms->cols());
172 for(i = 1; i <=
rows; ++i)
173 tmp_gm.row(i) = gms->row(row_perm(i));
175 for(i = 1; i <=
cols; ++i)
176 gms->col(i) = tmp_gm.col(col_perm(i));
size_type rows(size_type rows, size_type cols, BLAS_Cpp::Transp _trans)
size_type cols(size_type rows, size_type cols, BLAS_Cpp::Transp _trans)