44 #include "AbstractLinAlgPack_PermutationSerial.hpp" 45 #include "AbstractLinAlgPack_VectorDenseEncap.hpp" 46 #include "DenseLinAlgPack_IVector.hpp" 47 #include "DenseLinAlgPack_PermVecMat.hpp" 48 #include "DenseLinAlgPack_PermOut.hpp" 49 #include "Teuchos_Assert.hpp" 55 PermutationSerial::PermutationSerial(
size_type dim )
59 PermutationSerial::PermutationSerial(
60 const i_vector_ptr_t &perm
61 ,
const i_vector_ptr_t &inv_perm
62 ,
bool allocate_missing_perm
66 this->initialize(perm,inv_perm,allocate_missing_perm,check_inv_perm);
69 void PermutationSerial::initialize_identity(
size_type dim )
72 space_.initialize(dim);
73 perm_ = Teuchos::null;
74 inv_perm_ = Teuchos::null;
77 void PermutationSerial::initialize(
78 const i_vector_ptr_t &perm
79 ,
const i_vector_ptr_t &inv_perm
80 ,
bool allocate_missing_perm
84 TEUCHOS_TEST_FOR_EXCEPTION(
85 perm.get() == NULL && inv_perm.get() == NULL, std::invalid_argument
86 ,
"PermutationSerial::initialize(...) : Error!" );
87 if( perm.get() != NULL && inv_perm.get() != NULL ) {
88 TEUCHOS_TEST_FOR_EXCEPTION(
89 perm->size() != inv_perm->size(), std::invalid_argument
90 ,
"PermutationSerial::initialize(...) : Error!" );
95 space_.initialize( perm.get() ? perm->size() : inv_perm->size() );
98 if( allocate_missing_perm && perm_.get() == NULL ) {
100 _perm = Teuchos::rcp(
new IVector(inv_perm_->size()));
101 DenseLinAlgPack::inv_perm( *inv_perm_, _perm.get() );
104 if( allocate_missing_perm && inv_perm_.get() == NULL ) {
105 Teuchos::RCP<IVector>
106 _inv_perm = Teuchos::rcp(
new IVector(perm_->size()));
107 DenseLinAlgPack::inv_perm( *perm_, _inv_perm.get() );
108 inv_perm_ = _inv_perm;
114 const VectorSpace& PermutationSerial::space()
const 124 bool PermutationSerial::is_identity()
const 126 return perm_.get() == NULL && inv_perm_.get() == NULL;
129 std::ostream& PermutationSerial::output(std::ostream& out)
const 132 out <<
"Serial " << dim <<
" x " << dim <<
" permtutation matrix:\n";
135 out <<
"\n" << *perm_;
139 if( inv_perm_.get() )
140 out <<
"\n" << *inv_perm_;
146 void PermutationSerial::permute(
153 TEUCHOS_TEST_FOR_EXCEPTION(
154 y == NULL, std::invalid_argument
155 ,
"PermutationSerial::permute(P_trans,x,y) : Error!" );
157 #ifdef ABSTRACTLINALGPACK_ASSERT_COMPATIBILITY 159 is_compatible = space_.is_compatible(x.space());
160 TEUCHOS_TEST_FOR_EXCEPTION(
161 !is_compatible, std::invalid_argument
162 ,
"PermutationSerial::permute(P_trans,x,y) : Error, " 163 "this->space().is_compatible(x.space()) returned false!" );
164 is_compatible = space_.is_compatible(y->space());
165 TEUCHOS_TEST_FOR_EXCEPTION(
166 !is_compatible, std::invalid_argument
167 ,
"PermutationSerial::permute(P_trans,x,y) : Error, " 168 "this->space().is_compatible(y->space()) returned false!" );
170 VectorDenseMutableEncap y_d(*y);
171 VectorDenseEncap x_d(x);
172 const IVector *p = NULL;
173 bool call_inv_perm =
false;
174 if( ( p = perm_.get() ) != NULL ) {
176 call_inv_perm =
false;
178 call_inv_perm =
true;
180 else if( ( p = inv_perm_.get() ) != NULL ) {
182 call_inv_perm =
true;
184 call_inv_perm =
false;
188 DenseLinAlgPack::inv_perm_ele( x_d(), *p, &y_d() );
190 DenseLinAlgPack::perm_ele( x_d(), *p, &y_d() );
197 void PermutationSerial::permute(
203 TEUCHOS_TEST_FOR_EXCEPTION(
204 y == NULL, std::invalid_argument
205 ,
"PermutationSerial::permute(P_trans,y) : Error!" );
virtual size_type dim() const =0
Return the dimension of the permutation.
virtual void permute(BLAS_Cpp::Transp P_trans, const Vector &x, VectorMutable *y) const =0
Permute a vector op(P)*x -> y
Teuchos::RCP< VectorMutable > vec_mut_ptr_t