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"
51 namespace AbstractLinAlgPack {
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 )
71 namespace rcp = MemMngPack;
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
85 perm.get() == NULL && inv_perm.get() == NULL, std::invalid_argument
86 ,
"PermutationSerial::initialize(...) : Error!" );
87 if( perm.get() != NULL && inv_perm.get() != NULL ) {
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 ) {
101 DenseLinAlgPack::inv_perm( *inv_perm_, _perm.
get() );
104 if( allocate_missing_perm && inv_perm_.get() == NULL ) {
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(
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());
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());
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(
204 y == NULL, std::invalid_argument
205 ,
"PermutationSerial::permute(P_trans,y) : Error!" );
209 this->permute(P_trans,*t,y);
virtual vec_mut_ptr_t clone() const
Create a clone of this vector objet.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Teuchos::RCP< VectorMutable > vec_mut_ptr_t