51 namespace AbstractLinAlgPack {
55 PermutationSerial::PermutationSerial(
size_type dim )
59 PermutationSerial::PermutationSerial(
60 const i_vector_ptr_t &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);
77 void PermutationSerial::initialize(
78 const i_vector_ptr_t &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 ) {
104 if( allocate_missing_perm && inv_perm_.get() == NULL ) {
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;
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;
197 void PermutationSerial::permute(
204 y == NULL, std::invalid_argument
205 ,
"PermutationSerial::permute(P_trans,y) : Error!" );
207 VectorSpace::vec_mut_ptr_t
209 this->permute(P_trans,*t,y);
AbstractLinAlgPack::size_type size_type
void inv_perm(const IVector &perm, IVector *inv_perm)
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
std::ostream & output(std::ostream &o, const COOMatrix &coom)
Output stream function for COOMatrix.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
RTOp_index_type size_type
void inv_perm_ele(const DVectorSlice &y, const IVector &perm, DVectorSlice *x)
Perform x = P'*y.
void perm_ele(const IVector &perm, DVectorSlice *vs)
Permute a DVectorSlice in place.