48 #include "AbstractLinAlgPack_MatrixSymOp.hpp"
49 #include "AbstractLinAlgPack_MatrixOpSubView.hpp"
50 #include "AbstractLinAlgPack_MatrixPermAggr.hpp"
51 #include "AbstractLinAlgPack_MultiVectorMutable.hpp"
52 #include "AbstractLinAlgPack_VectorSpace.hpp"
53 #include "AbstractLinAlgPack_VectorMutable.hpp"
54 #include "AbstractLinAlgPack_Permutation.hpp"
55 #include "AbstractLinAlgPack_SpVectorClass.hpp"
56 #include "AbstractLinAlgPack_SpVectorView.hpp"
57 #include "AbstractLinAlgPack_EtaVector.hpp"
58 #include "AbstractLinAlgPack_LinAlgOpPack.hpp"
59 #include "Teuchos_Assert.hpp"
60 #include "Teuchos_FancyOStream.hpp"
62 namespace AbstractLinAlgPack {
67 true, std::logic_error,
"MatrixOp::zero_out(): "
68 "Error, this method as not been defined by the subclass \'"
75 true, std::logic_error,
"MatrixOp::Mt_S(): "
76 "Error, this method as not been defined by the subclass \'"
82 const bool assign_to_self =
dynamic_cast<const void*
>(
this) == dynamic_cast<const void*>(&M);
84 !assign_to_self, std::logic_error
85 ,
"MatrixOp::operator=(M) : Error, this is not assignment "
86 "to self and this method is not overridden for the subclass \'"
95 const size_type m = this->
rows(), n = this->
cols();
98 *out << m <<
" " << n << std::endl;
99 for( size_type i = 1; i <= m; ++i ) {
101 row_vec->output(*out,
false,
true);
108 MatrixOp::mat_mut_ptr_t
111 return Teuchos::null;
117 return Teuchos::null;
125 ,
bool allow_replacement
130 using LinAlgOpPack::V_MtV;
135 num_rows = space_cols.
dim(),
139 ,
"MatrixOp::calc_norm(...): Error, This default implemenation can only "
140 "compute the one norm or the infinity norm!"
152 w = (!do_trans ? space_cols :
space_rows).create_member(),
153 zeta = (!do_trans ? space_cols :
space_rows).create_member(),
154 z = (!do_trans ? space_rows :
space_cols).create_member();
155 const index_type max_iter = 5;
156 value_type w_nrm = 0.0;
157 for( index_type k = 0; k <= max_iter; ++k ) {
159 sign( *w, zeta.get() );
161 value_type z_j = 0.0;
164 const value_type zTx =
dot(*z,*x);
166 if( ::fabs(z_j) <= zTx ) {
174 return MatNorm(w_nrm,requested_norm_type);
182 namespace rcp = MemMngPack;
197 ,row_rng,col_rng ) );
205 ,
const index_type row_part[]
208 ,
const index_type col_part[]
212 namespace rcp = MemMngPack;
225 ,
const index_type row_part[]
228 ,
const index_type col_part[]
230 ,
const mat_ptr_t &perm_view
234 P_row,row_part,num_row_part
235 ,P_col,col_part,num_col_part );
322 v_rhs2->set_sub_vector(sub_vec_view(sv_rhs2));
323 this->
Vp_StMtV(v_lhs,alpha,trans_rhs1,*v_rhs2,beta);
334 ,
const Vector& x, value_type b
341 LinAlgOpPack::V_MtV( t.
get(), *
this, M_trans, x );
356 LinAlgOpPack::V_MtV( t.
get(), *
this, M_trans, x );
362 ,
const Vector& vs_rhs3)
const
442 else if( alpha != 1.0 )
454 if(M_rhs.
Mp_StM(mwo_lhs,alpha,trans_rhs))
458 if(mwo_lhs->
Mp_StM(alpha,M_rhs,trans_rhs))
465 !m_mut_lhs || !(m_mut_lhs->
access_by() & MultiVector::COL_ACCESS)
467 ,
"MatrixOp::Mp_StM(...) : Error, mwo_lhs of type \'"
468 <<
typeName(*mwo_lhs) <<
"\' could not implement the operation "
469 "and does not support the "
470 "\'MultiVectorMutable\' interface. Furthermore, "
471 "the rhs matix argument of type \'" <<
typeName(*mwo_lhs)
472 <<
"\' could not implement the operation!" );
481 ,
"MatrixOp::Mp_StM(mwo_lhs,...): Error, mwo_lhs of type \'"<<
typeName(*mwo_lhs)<<
"\' "
482 <<
"is not compatible with M_rhs of type \'"<<
typeName(M_rhs)<<
"\'" );
488 for( size_type j = 1; j <=
cols; ++j )
501 if(M_rhs.
Mp_StMtP(mwo_lhs,alpha,M_trans,P_rhs,P_rhs_trans))
505 if(mwo_lhs->
Mp_StMtP(alpha,M_rhs,M_trans,P_rhs,P_rhs_trans))
513 ,
"MatrixOp::Mp_StMtP(...) : Error, mwo_lhs of type \'"
514 <<
typeName(*mwo_lhs) <<
"\' does not support the "
515 "\'MultiVectorMutable\' interface!" );
528 if(M_rhs.
Mp_StPtM(mwo_lhs,alpha,P_rhs,P_rhs_trans,M_trans))
532 if(mwo_lhs->
Mp_StPtM(alpha,P_rhs,P_rhs_trans,M_rhs,M_trans))
540 ,
"MatrixOp::Mp_StPtM(...) : Error, mwo_lhs of type \'"
541 <<
typeName(*mwo_lhs) <<
"\' does not support the "
542 "\'MultiVectorMutable\' interface!" );
557 if(M_rhs.
Mp_StPtMtP(mwo_lhs,alpha,P_rhs1,P_rhs1_trans,trans_rhs,P_rhs2,P_rhs2_trans))
561 if(mwo_lhs->
Mp_StPtMtP(alpha,P_rhs1,P_rhs1_trans,M_rhs,trans_rhs,P_rhs2,P_rhs2_trans))
569 ,
"MatrixOp::Mp_StPtMtP(...) : Error, mwo_lhs of type \'"
570 <<
typeName(*mwo_lhs) <<
"\' does not support the "
571 "\'MultiVectorMutable\' interface!" );
588 if(A.
Mp_StMtM(C,a,A_trans,B,B_trans,b))
591 if(B.
Mp_StMtM(C,a,A,A_trans,B_trans,b))
594 if(C->
Mp_StMtM(a,A,A_trans,B,B_trans,b))
612 !Cmv || !(Cmv->
access_by() & MultiVector::COL_ACCESS)
614 ,
"AbstractLinAlgPack::Mp_StMtM(...) : Error, mwo_lhs of type \'"
615 <<
typeName(*C) <<
"\' does not support the "
616 "\'MultiVectorMutable\' interface or does not support column access!" );
621 C_rows = Cmv->
rows(),
622 C_cols = Cmv->
cols();
623 for( index_type j = 1; j <= C_cols; ++j ) {
625 LinAlgOpPack::V_MtV( t.get(), B, B_trans,
EtaVector(j,C_cols) );
640 if(A.
syrk(A_trans,a,b,B))
643 if(B->
syrk(A,A_trans,a,b))
648 ,
"AbstractLinAlgPack::syrk(...) : Error, neither the right-hand-side matrix "
649 "argument mwo_rhs of type \'" <<
typeName(A) <<
" nore the left-hand-side matrix "
650 "argument sym_lhs of type \'" <<
typeName(*B) <<
"\' could implement this operation!"
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)
virtual const VectorSpace & space_rows() const =0
Vector space for vectors that are compatible with the rows of the matrix.
Thrown if matrices are not compatible.
Abstract interface for immutable, finite dimensional, coordinate vectors {abstract}.
void sign(const Vector &v, VectorMutable *z)
Compute the sign of each element in an input vector.
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
virtual access_by_t access_by() const =0
Return a bit field for the types of access that are the most convenient.
Sparse Vector Slice class template.
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)
virtual mat_mut_ptr_t clone()
Clone the non-const matrix object (if supported).
friend void Mt_S(MatrixOp *mwo_lhs, value_type alpha)
Aggregate matrix class for a matrix and its permuted view.
size_type rows(size_type rows, size_type cols, BLAS_Cpp::Transp _trans)
The induced infinity norm ||M||inf, i.e. max abs row sum.
virtual MatrixOp & operator=(const MatrixOp &mwo_rhs)
M_lhs = mwo_rhs : Virtual assignment operator.
virtual mat_ptr_t perm_view(const Permutation *P_row, const index_type row_part[], int num_row_part, const Permutation *P_col, const index_type col_part[], int num_col_part) const
Create a permuted view: M_perm = P_row' * M * P_col.
friend value_type transVtMtV(const Vector &v_rhs1, const MatrixOp &M_rhs2, BLAS_Cpp::Transp trans_rhs2, const Vector &v_rhs3)
friend 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)
Interface adding operations specific for a symmetric matrix {abstract}.
virtual void zero_out()
M_lhs = 0 : Zero out the matrix.
virtual std::ostream & output(std::ostream &out) const
Virtual output function.
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).
virtual size_type cols() const
Return the number of columns in the matrix.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
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)
Standard subclass for representing a sub, possibly transposed, view of a matrix.
Returned form calc_norm().
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:
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).
void Mp_MtM_assert_compatibility(MatrixOp *m_lhs, BLAS_Cpp::Transp trans_lhs, const MatrixOp &m_rhs1, BLAS_Cpp::Transp trans_rhs1, const MatrixOp &m_rhs2, BLAS_Cpp::Transp trans_rhs2)
op(m_lhs) += op(m_rhs1) * op(m_rhs2)
Thrown if a method is not implemented.
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).
Create an eta vector (scaled by alpha = default 1).
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)
virtual bool is_compatible(const VectorSpace &vec_spc) const =0
Compare the compatibility of two vector spaces.
friend void Mp_StM(MatrixOp *mwo_lhs, value_type alpha, const MatrixOp &M_rhs, BLAS_Cpp::Transp trans_rhs)
virtual mat_ptr_t perm_view_update(const Permutation *P_row, const index_type row_part[], int num_row_part, const Permutation *P_col, const index_type col_part[], int num_col_part, const mat_ptr_t &perm_view) const
Reinitialize a permuted view: M_perm = P_row' * M * P_col.
Base class for all matrices that support basic matrix operations.
const MatNorm calc_norm(EMatNormType requested_norm_type=MAT_NORM_1, bool allow_replacement=false) const
Compute a norm of this matrix.
void Mt_S(MatrixOp *mwo_lhs, value_type alpha)
value_type dot(const Vector &v_rhs1, const Vector &v_rhs2)
result = v_rhs1' * v_rhs2
virtual index_type dim() const =0
Return the dimmension of the vector space.
The induced one norm ||M||1, i.e. max abs col sum.
Interface for a collection of mutable vectors (multi-vector, matrix).
Abstract interface to permutation matrices.
EMatNormType
Type of matrix norm.
friend 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)
virtual const VectorSpace & space_cols() const =0
Vector space for vectors that are compatible with the columns of the matrix.
Abstract interface for mutable coordinate vectors {abstract}.
void max_abs_ele(const Vector &v, value_type *max_v_j, index_type *max_j)
Compute the maximum element in a vector.
void Vp_MtV_assert_compatibility(VectorMutable *v_lhs, const MatrixOp &m_rhs1, BLAS_Cpp::Transp trans_rhs1, const Vector &v_rhs2)
v_lhs += op(m_rhs1) * v_rhs2
virtual vec_mut_ptr_t create_member() const =0
Create a vector member from the vector space.
virtual size_type rows() const
Return the number of rows in the matrix.
virtual vec_mut_ptr_t col(index_type j)=0
Get a mutable column vector.
virtual bool syrk(BLAS_Cpp::Transp M_trans, value_type alpha, value_type beta, MatrixSymOp *sym_lhs) const
Perform a rank-k update of a symmetric matrix of the form:
friend void syrk(const MatrixOp &mwo_rhs, BLAS_Cpp::Transp M_trans, value_type alpha, value_type beta, MatrixSymOp *sym_lhs)
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)
size_type cols(size_type rows, size_type cols, BLAS_Cpp::Transp _trans)
size_type nz() const
Return the number of non-zero elements.
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)
Concrete matrix type to represent general permutation (mapping) matrices.
std::string typeName(const T &t)
friend 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)
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)