42 #include "AbstractLinAlgPack_MatrixPermAggr.hpp"
43 #include "AbstractLinAlgPack_LinAlgOpPack.hpp"
44 #include "AbstractLinAlgPack_MatrixOpOut.hpp"
45 #include "AbstractLinAlgPack_VectorStdOps.hpp"
46 #include "AbstractLinAlgPack_VectorSpace.hpp"
47 #include "AbstractLinAlgPack_Permutation.hpp"
48 #include "AbstractLinAlgPack_PermutationOut.hpp"
49 #include "Teuchos_Assert.hpp"
50 #include "Teuchos_dyn_cast.hpp"
52 namespace AbstractLinAlgPack {
60 const mat_ptr_t &mat_orig
63 ,
const mat_ptr_t &mat_perm
66 this->
initialize(mat_orig,row_perm,col_perm,mat_perm);
70 const mat_ptr_t &mat_orig
73 ,
const mat_ptr_t &mat_perm
78 mat_orig.get() == NULL, std::invalid_argument
79 ,
"MatrixPermAggr::initialize(...): Error!" );
81 #ifdef ABSTRACTLINALGPACK_ASSERT_COMPATIBILITY
82 bool is_compatible =
false;
84 is_compatible = mat_orig->space_cols().is_compatible(row_perm->space());
87 ,
"MatrixPermAggr::initialize(...): Error, "
88 "mat_orig->space_cols().is_compatible(row_perm->space()) == false" );
91 is_compatible = mat_orig->space_rows().is_compatible(col_perm->space());
94 ,
"MatrixPermAggr::initialize(...): Error, "
95 "mat_orig->space_rows().is_compatible(col_perm->space()) == false" );
106 namespace rcp = MemMngPack;
107 mat_orig_ = Teuchos::null;
108 row_perm_ = Teuchos::null;
109 col_perm_ = Teuchos::null;
110 mat_perm_ = Teuchos::null;
117 return mat_orig_.get() ? mat_orig_->rows() : 0;
122 return mat_orig_.get() ? mat_orig_->cols() : 0;
127 return mat_orig_.get() ? mat_orig_->nz() : 0;
134 return mat_orig_->space_cols();
139 return mat_orig_->space_rows();
146 return mat_perm_->sub_view(row_rng,col_rng);
147 if(!row_perm_.get() && !col_perm_.get())
148 return mat_orig_->sub_view(row_rng,col_rng);
160 mat_orig_ = Mp.mat_orig_;
161 row_perm_ = Mp.row_perm_;
162 col_perm_ = Mp.col_perm_;
163 mat_perm_ = Mp.mat_perm_;
169 out <<
"Matrix with permuted view:\n";
170 out <<
"mat_orig =\n" << *mat_orig_;
172 if( row_perm_.get() )
173 out <<
"\n" << *row_perm_;
177 if( col_perm_.get() )
178 out <<
"\n" << *col_perm_;
182 if( mat_perm_.get() )
183 out <<
"\n" << *mat_perm_;
194 if(!row_perm_.get() && !col_perm_.get()) {
208 if(!row_perm_.get() && !col_perm_.get()) {
222 if(!row_perm_.get() && !col_perm_.get()) {
237 if(!row_perm_.get() && !col_perm_.get()) {
247 ,
const Vector& x, value_type b
252 using LinAlgOpPack::V_MtV;
254 if(mat_perm_.get()) {
258 if(!row_perm_.get() && !col_perm_.get()) {
278 *P1 = ( M_trans ==
no_trans ? row_perm_.get() : col_perm_.get() ),
279 *P2 = ( M_trans ==
no_trans ? col_perm_.get() : row_perm_.get() );
282 if( P2 && !P2->is_identity() )
283 P2->permute(
trans, x, (ta = P2->space().create_member()).
get() );
285 *(tb = ( M_trans ==
no_trans ? mat_orig_->space_rows() : mat_orig_->space_cols() ).create_member() ) = x;
288 (tb = ( M_trans ==
no_trans ? mat_orig_->space_cols() : mat_orig_->space_rows() ).create_member() ).
get()
289 ,*mat_orig_, M_trans, *ta
305 if(mat_perm_.get()) {
309 if(!row_perm_.get() && !col_perm_.get()) {
320 ,
const Vector& v_rhs3, value_type beta
323 if(!row_perm_.get() && !col_perm_.get()) {
337 if(!row_perm_.get() && !col_perm_.get()) {
349 if(!row_perm_.get() && !col_perm_.get())
359 if(!row_perm_.get() && !col_perm_.get())
371 if(!row_perm_.get() && !col_perm_.get()) {
384 if(!row_perm_.get() && !col_perm_.get()) {
397 if(!row_perm_.get() && !col_perm_.get()) {
409 if(!row_perm_.get() && !col_perm_.get()) {
friend void syr2k(const MatrixOp &M, BLAS_Cpp::Transp M_trans, value_type alpha, const GenPermMatrixSlice &P1, BLAS_Cpp::Transp P1_trans, const GenPermMatrixSlice &P2, BLAS_Cpp::Transp P2_trans, value_type beta, MatrixSymOp *symwo_lhs)
MatrixOp & operator=(const MatrixOp &M)
Abstract interface for immutable, finite dimensional, coordinate vectors {abstract}.
const VectorSpace & space_cols() const
void Mp_StMtM(MatrixOp *mwo_lhs, value_type alpha, const MatrixOp &mwo_rhs1, BLAS_Cpp::Transp trans_rhs1, const MatrixOp &mwo_rhs2, BLAS_Cpp::Transp trans_rhs2, value_type beta=1.0)
mwo_lhs = alpha * op(mwo_rhs1) * op(mwo_rhs2) + beta * mwo_lhs (right) (xGEMM).
void Vt_S(VectorMutable *v_lhs, const value_type &alpha)
v_lhs *= alpha
value_type transVtMtV(const Vector &v_rhs1, BLAS_Cpp::Transp trans_rhs2, const Vector &v_rhs3) const
void Vp_StPtMtV(VectorMutable *v_lhs, value_type alpha, const GenPermMatrixSlice &P_rhs1, BLAS_Cpp::Transp P_rhs1_trans, const MatrixOp &M_rhs2, BLAS_Cpp::Transp M_rhs2_trans, const Vector &v_rhs3, value_type beta=1.0)
v_lhs = alpha * op(P_rhs1) * op(M_rhs2) * v_rhs3 + beta * v_rhs
bool syrk(BLAS_Cpp::Transp M_trans, value_type alpha, value_type beta, MatrixSymOp *sym_lhs) const
virtual mat_ptr_t sub_view(const Range1D &row_rng, const Range1D &col_rng) const
Create a transient constant sub-matrix view of this matrix (if supported).
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
void Vp_StV(VectorMutable *v_lhs, const value_type &alpha, const Vector &v_rhs)
v_lhs = alpha * v_rhs + v_lhs
Aggregate matrix class for a matrix and its permuted view.
T_To & dyn_cast(T_From &from)
const perm_ptr_t & row_perm() const
const VectorSpace & space_rows() const
friend value_type transVtMtV(const Vector &v_rhs1, const MatrixOp &M_rhs2, BLAS_Cpp::Transp trans_rhs2, const Vector &v_rhs3)
void Vp_StMtV(VectorMutable *vs_lhs, value_type alpha, BLAS_Cpp::Transp trans_rhs1, const Vector &v_rhs2, value_type beta) const
virtual const VectorSpace & space() const =0
Return a reference to a vector space object that this permutation is compatible with.
value_type transVtMtV(const Vector &v_rhs1, const MatrixOp &M_rhs2, BLAS_Cpp::Transp trans_rhs2, const Vector &v_rhs3)
result = v_rhs1' * op(M_rhs2) * v_rhs3
Interface adding operations specific for a symmetric matrix {abstract}.
const mat_ptr_t & mat_orig() const
void syr2k(const MatrixOp &M, BLAS_Cpp::Transp M_trans, value_type alpha, const GenPermMatrixSlice &P1, BLAS_Cpp::Transp P1_trans, const GenPermMatrixSlice &P2, BLAS_Cpp::Transp P2_trans, value_type beta, MatrixSymOp *symwo_lhs)
symwo_lhs += alpha*op(P1')*op(M)*op(P2) + alpha*op(P2')*op(M')*op(P1) + beta*symwo_lhs ...
void Mp_StPtMtP(MatrixOp *mwo_lhs, value_type alpha, const GenPermMatrixSlice &P_rhs1, BLAS_Cpp::Transp P_rhs1_trans, const MatrixOp &M_rhs, BLAS_Cpp::Transp trans_rhs, const GenPermMatrixSlice &P_rhs2, BLAS_Cpp::Transp P_rhs2_trans)
mwo_lhs += alpha * op(P_rhs1) * op(M_rhs) * op(P_rhs2).
void initialize(const mat_ptr_t &mat_orig, const perm_ptr_t &row_perm, const perm_ptr_t &col_perm, const mat_ptr_t &mat_perm)
Initialize.
MatrixPermAggr()
Construct to uninitialized.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
virtual void permute(BLAS_Cpp::Transp P_trans, const Vector &x, VectorMutable *y) const =0
Permute a vector op(P)*x -> y
Abstract interface for objects that represent a space for mutable coordinate vectors.
friend void Mp_StMtM(MatrixOp *mwo_lhs, value_type alpha, const MatrixOp &mwo_rhs1, BLAS_Cpp::Transp trans_rhs1, const MatrixOp &mwo_rhs2, BLAS_Cpp::Transp trans_rhs2, value_type beta)
void syrk(const MatrixOp &mwo_rhs, BLAS_Cpp::Transp M_trans, value_type alpha, value_type beta, MatrixSymOp *sym_lhs)
Perform a rank-k update of a symmetric matrix of the form:
const mat_ptr_t & mat_perm() const
void Mp_StMtP(MatrixOp *mwo_lhs, value_type alpha, const MatrixOp &M_rhs, BLAS_Cpp::Transp M_trans, const GenPermMatrixSlice &P_rhs, BLAS_Cpp::Transp P_rhs_trans)
mwo_lhs += alpha * op(M_rhs) * op(P_rhs).
MatrixOp::mat_ptr_t sub_view(const Range1D &row_rng, const Range1D &col_rng) const
void Mp_StPtM(MatrixOp *mwo_lhs, value_type alpha, const GenPermMatrixSlice &P_rhs, BLAS_Cpp::Transp P_rhs_trans, const MatrixOp &M_rhs, BLAS_Cpp::Transp M_trans)
mwo_lhs += alpha * op(P) * op(M_rhs).
void Mp_StM(MatrixOp *mwo_lhs, value_type alpha, const MatrixOp &M_rhs, BLAS_Cpp::Transp trans_rhs)
void Vp_StMtV(VectorMutable *v_lhs, value_type alpha, const MatrixOp &M_rhs1, BLAS_Cpp::Transp trans_rhs1, const Vector &v_rhs2, value_type beta=1.0)
v_lhs = alpha * op(M_rhs1) * v_rhs2 + beta * v_lhs (BLAS xGEMV)
bool Mp_StPtM(MatrixOp *mwo_lhs, value_type alpha, const GenPermMatrixSlice &P_rhs, BLAS_Cpp::Transp P_rhs_trans, BLAS_Cpp::Transp M_trans) const
bool Mp_StPtMtP(MatrixOp *mwo_lhs, value_type alpha, const GenPermMatrixSlice &P_rhs1, BLAS_Cpp::Transp P_rhs1_trans, BLAS_Cpp::Transp M_trans, const GenPermMatrixSlice &P_rhs2, BLAS_Cpp::Transp P_rhs2_trans) const
Base class for all matrices that support basic matrix operations.
bool Mp_StMtM(MatrixOp *mwo_lhs, value_type alpha, BLAS_Cpp::Transp trans_rhs1, const MatrixOp &mwo_rhs2, BLAS_Cpp::Transp trans_rhs2, value_type beta) const
virtual bool is_identity() const =0
Returns true if this is the identity permutation I.
const perm_ptr_t & col_perm() const
Abstract interface to permutation matrices.
void set_uninitialized()
Set uninitialized.
void Vp_StPtMtV(VectorMutable *vs_lhs, value_type alpha, const GenPermMatrixSlice &P_rhs1, BLAS_Cpp::Transp P_rhs1_trans, BLAS_Cpp::Transp M_rhs2_trans, const Vector &v_rhs3, value_type beta) const
bool Mp_StMtP(MatrixOp *mwo_lhs, value_type alpha, BLAS_Cpp::Transp M_trans, const GenPermMatrixSlice &P_rhs, BLAS_Cpp::Transp P_rhs_trans) const
Abstract interface for mutable coordinate vectors {abstract}.
Thrown if vector spaces are incompatible.
std::ostream & output(std::ostream &out) const
virtual vec_mut_ptr_t create_member() const =0
Create a vector member from the vector space.
friend void syrk(const MatrixOp &mwo_rhs, BLAS_Cpp::Transp M_trans, value_type alpha, value_type beta, MatrixSymOp *sym_lhs)
bool Mp_StM(MatrixOp *mwo_lhs, value_type alpha, BLAS_Cpp::Transp trans_rhs) const
friend void Vp_StMtV(VectorMutable *v_lhs, value_type alpha, const MatrixOp &M_rhs1, BLAS_Cpp::Transp trans_rhs1, const Vector &v_rhs2, value_type beta)
void syr2k(BLAS_Cpp::Transp M_trans, value_type alpha, const GenPermMatrixSlice &P1, BLAS_Cpp::Transp P1_trans, const GenPermMatrixSlice &P2, BLAS_Cpp::Transp P2_trans, value_type beta, MatrixSymOp *symwo_lhs) const
Concrete matrix type to represent general permutation (mapping) matrices.
friend void Vp_StPtMtV(VectorMutable *v_lhs, value_type alpha, const GenPermMatrixSlice &P_rhs1, BLAS_Cpp::Transp P_rhs1_trans, const MatrixOp &M_rhs2, BLAS_Cpp::Transp M_rhs2_trans, const Vector &v_rhs3, value_type beta)