42 #include "AbstractLinAlgPack_MatrixComposite.hpp"
43 #include "AbstractLinAlgPack_SpVectorClass.hpp"
44 #include "AbstractLinAlgPack_VectorStdOps.hpp"
45 #include "AbstractLinAlgPack_VectorMutableBlocked.hpp"
46 #include "AbstractLinAlgPack_AssertOp.hpp"
48 #include "Teuchos_Workspace.hpp"
49 #include "Teuchos_Assert.hpp"
50 #include "ProfileHackPack_profile_hack.hpp"
57 AbstractLinAlgPack::value_type
64 AbstractLinAlgPack::value_type
69 return ele != NULL ? ele->
value() : 0.0;
78 ,AbstractLinAlgPack::index_type l
79 ,AbstractLinAlgPack::index_type u
89 ,AbstractLinAlgPack::index_type l
90 ,AbstractLinAlgPack::index_type u
101 ,AbstractLinAlgPack::size_type M_rows, AbstractLinAlgPack::size_type M_cols
105 ,
const V& x, AbstractLinAlgPack::value_type b
118 if( vec_list.size() ) {
119 for( vec_list_t::const_iterator itr = vec_list.begin(); itr != vec_list.end(); ++itr ) {
121 op_v_trans = ( M_trans == itr->v_trans_ ?
no_trans :
trans );
122 const AbstractLinAlgPack::index_type
123 r = ( M_trans ==
no_trans ? itr->r_l_ : itr->c_l_ ),
124 c = ( M_trans ==
no_trans ? itr->c_l_ : itr->r_l_ );
125 if( itr->rng_G_.full_range() ) {
159 if( mat_list.size() ) {
160 for( mat_list_t::const_iterator itr = mat_list.begin(); itr != mat_list.end(); ++itr ) {
161 const AbstractLinAlgPack::index_type
162 rl =
rows(itr->r_l_,itr->c_l_,M_trans),
163 ru =
rows(itr->r_u_,itr->c_u_,M_trans),
164 cl =
cols(itr->r_l_,itr->c_l_,M_trans),
165 cu =
cols(itr->r_u_,itr->c_u_,M_trans);
167 op_P_trans = ( M_trans == itr->P_trans_ ?
no_trans :
trans ),
168 op_A_trans = ( M_trans == itr->A_trans_ ?
no_trans :
trans ),
169 op_Q_trans = ( M_trans == itr->Q_trans_ ?
no_trans :
trans );
170 if( itr->rng_P_.full_range() && itr->rng_Q_.full_range() ) {
184 if( itr->A_ == NULL ) {
210 if( !itr->rng_P_.full_range() && !itr->rng_Q_.full_range() ) {
214 itr->A_trans_==
no_trans ? itr->rng_P_ : itr->rng_Q_
215 ,itr->A_trans_==
no_trans ? itr->rng_Q_ : itr->rng_P_ )
234 enum EByRowCol { BY_ROW, BY_COL };
235 CompSubEntry(
enum EByRowCol by_row_col)
236 : by_row_col_(by_row_col)
238 bool operator()(
const T& e1,
const T& e2 )
241 ( by_row_col_ == BY_ROW
247 EByRowCol by_row_col_;
254 namespace AbstractLinAlgPack {
263 namespace rcp = MemMngPack;
265 fully_constructed_ =
true;
268 if(matrix_list_.size()) {
269 matrix_list_.erase(matrix_list_.begin(),matrix_list_.end());
271 if(vector_list_.size()) {
272 vector_list_.erase(vector_list_.begin(),vector_list_.end());
274 space_rows_ = Teuchos::null;
275 space_cols_ = Teuchos::null;
280 ,size_type col_offset
290 fully_constructed_ =
false;
296 ,size_type col_offset
304 fully_constructed_ =
false;
310 ,size_type col_offset
317 namespace rcp = MemMngPack;
321 fully_constructed_ =
false;
331 vector_list_.push_back(
333 row_offset+1,col_offset+1,beta,
Range1D()
335 ,v,v_release,v_trans ) );
340 fully_constructed_ =
false;
341 vector_list_.erase(itr);
346 ,size_type col_offset
359 fully_constructed_ =
false;
365 ,size_type col_offset
376 fully_constructed_ =
false;
382 ,size_type col_offset
393 fully_constructed_ =
false;
399 ,size_type col_offset
408 namespace rcp = MemMngPack;
411 using RangePack::full_range;
414 alpha == 0.0, std::invalid_argument
415 ,
"MatrixComposite::add_matrix(...) : Error!" );
417 A == NULL, std::invalid_argument
418 ,
"MatrixComposite::add_matrix(...) : Error!" );
423 opA_rows =
rows(A_rows,A_cols,A_trans),
424 opA_cols =
cols(A_rows,A_cols,A_trans);
426 rng_P = full_range(rng_P_in,1,opA_rows),
427 rng_Q = full_range(rng_Q_in,1,opA_cols);
429 opPopAopQ_rows = rng_P.
size(),
430 opPopAopQ_cols = rng_Q.size();
433 row_offset + opPopAopQ_rows > rows_, std::invalid_argument
434 ,
"MatrixComposite::add_matrix(...) : Error!" );
436 col_offset + opPopAopQ_cols > cols_, std::invalid_argument
437 ,
"MatrixComposite::add_matrix(...) : Error!" );
439 fully_constructed_ =
false;
441 matrix_list_.push_back(
443 row_offset+1,row_offset+opPopAopQ_rows
444 ,col_offset+1,col_offset+opPopAopQ_cols
462 ,size_type col_offset
469 namespace rcp = MemMngPack;
474 alpha == 0.0, std::invalid_argument
475 ,
"MatrixComposite::add_matrix(...) : Error!" );
477 A == NULL, std::invalid_argument
478 ,
"MatrixComposite::add_matrix(...) : Error!" );
483 opA_rows =
rows(A_rows,A_cols,A_trans),
484 opA_cols =
cols(A_rows,A_cols,A_trans);
487 row_offset + opA_rows > rows_, std::invalid_argument
488 ,
"MatrixComposite::add_matrix(...) : Error!" );
490 col_offset + opA_cols > cols_, std::invalid_argument
491 ,
"MatrixComposite::add_matrix(...) : Error!" );
493 fully_constructed_ =
false;
495 matrix_list_.push_back(
497 row_offset+1,row_offset+opA_rows
498 ,col_offset+1,col_offset+opA_cols
511 ,size_type col_offset
518 namespace rcp = MemMngPack;
525 fully_constructed_ =
false;
530 opP_rows =
rows(P_rows,P_cols,P_trans),
531 opP_cols =
cols(P_rows,P_cols,P_trans);
536 matrix_list_.push_back(
538 row_offset+1,row_offset+opP_rows,col_offset+1,col_offset+opP_cols,alpha
550 fully_constructed_ =
false;
551 matrix_list_.erase(itr);
560 !space_cols.
get(), std::invalid_argument
561 ,
"MatrixComposite::finish_construction(...): Error, space_cols.get() can not be NULL" );
563 !space_rows.
get(), std::invalid_argument
564 ,
"MatrixComposite::finish_construction(...): Error, space_rows.get() can not be NULL" );
566 space_cols->dim() != rows_, std::invalid_argument
567 ,
"MatrixComposite::finish_construction(...): Error, space_colss->dim() = " << space_cols->dim()
568 <<
" != rows = " << rows_ <<
" where cols was passed to this->reinitialize(...)" );
570 space_rows->dim() != cols_, std::invalid_argument
571 ,
"MatrixComposite::finish_construction(...): Error, space_rows->dim() = " << space_rows->dim()
572 <<
" != cols = " << cols_ <<
" where cols was passed to this->reinitialize(...)" );
576 fully_constructed_ =
true;
583 return vector_list_.size();
586 MatrixComposite::vector_list_t::iterator
589 return vector_list_.begin();
592 MatrixComposite::vector_list_t::iterator
595 return vector_list_.end();
598 MatrixComposite::vector_list_t::const_iterator
601 return vector_list_.begin();
604 MatrixComposite::vector_list_t::const_iterator
607 return vector_list_.end();
612 return matrix_list_.size();
615 MatrixComposite::matrix_list_t::iterator
618 return matrix_list_.begin();
621 MatrixComposite::matrix_list_t::iterator
624 return matrix_list_.end();
627 MatrixComposite::matrix_list_t::const_iterator
630 return matrix_list_.begin();
633 MatrixComposite::matrix_list_t::const_iterator
636 return matrix_list_.end();
643 return fully_constructed_ ? rows_ : 0;
648 return fully_constructed_ ? cols_ : 0;
653 if(fully_constructed_) {
655 {
for(matrix_list_t::const_iterator itr = matrix_list_.begin(); itr != matrix_list_.end(); ++itr) {
656 if( itr->A_ != NULL )
659 nz += (*itr->P_).
nz();
661 {
for(vector_list_t::const_iterator itr = vector_list_.begin(); itr != vector_list_.end(); ++itr) {
674 assert_fully_constructed();
680 assert_fully_constructed();
687 assert_fully_constructed();
700 ,
const Vector& x, value_type b
703 #ifdef PROFILE_HACK_ENABLED
706 assert_fully_constructed();
708 Vp_StMtV_imp(y,a,rows_,cols_,matrix_list_,vector_list_,M_trans,x,b);
716 #ifdef PROFILE_HACK_ENABLED
719 assert_fully_constructed();
721 Vp_StMtV_imp(y,a,rows_,cols_,matrix_list_,vector_list_,M_trans,x,b);
728 ,
const Vector& x, value_type b
731 #ifdef PROFILE_HACK_ENABLED
734 assert_fully_constructed();
745 #ifdef PROFILE_HACK_ENABLED
748 assert_fully_constructed();
754 void MatrixComposite::assert_fully_constructed()
const
756 const bool fully_constructed = fully_constructed_;
758 !fully_constructed, std::logic_error
759 ,
"MatrixComposite::assert_fully_constructed() : Error, not fully constructed!");
element_type * lookup_element(size_type i)
void remove_vector(vector_list_t::iterator itr)
Remove a sub-vector.
virtual vec_ptr_t sub_view(const Range1D &rng) const
Create an abstract view of a vector object .
virtual vec_mut_ptr_t sub_view(const Range1D &rng)
Create a mutable abstract view of a vector object.
Matrix list entry for a sub-matrix.
std::deque< SubMatrixEntry > matrix_list_t
Warning! This could be changed to some other STL container!
Abstract interface for immutable, finite dimensional, coordinate vectors {abstract}.
matrix_list_t::iterator matrices_begin()
void Vt_S(VectorMutable *v_lhs, const value_type &alpha)
v_lhs *= alpha
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
void add_matrix(size_type row_offset, size_type col_offset, value_type alpha, const GenPermMatrixSlice *P, const release_resource_ptr_t &P_release, BLAS_Cpp::Transp P_trans, const MatrixOp *A, const release_resource_ptr_t &A_release, BLAS_Cpp::Transp A_trans, const GenPermMatrixSlice *Q, const release_resource_ptr_t &Q_release, BLAS_Cpp::Transp Q_trans)
Add a sub-matrix alpha*op(P)*op(A)*op(Q).
size_type rows(size_type rows, size_type cols, BLAS_Cpp::Transp _trans)
mat_ptr_t sub_view(const Range1D &row_rng, const Range1D &col_rng) const
vector_list_t::iterator vectors_begin()
virtual void finish_construction(const VectorSpace::space_ptr_t &space_cols, const VectorSpace::space_ptr_t &space_rows)
Call to finish the construction process.
std::deque< SubVectorEntry > vector_list_t
Warning! This could be changed to some other STL container!
virtual size_type cols() const
Return the number of columns in the matrix.
vector_list_t::iterator vectors_end()
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.
Vector list entry for a sub-vector.
matrix_list_t::iterator matrices_end()
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
const VectorSpace & space_cols() const
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)
Base class for all matrices that support basic matrix operations.
value_type dot(const Vector &v_rhs1, const Vector &v_rhs2)
result = v_rhs1' * v_rhs2
MatrixComposite(size_type rows=0, size_type cols=0)
Construct.
static const Range1D Invalid
void reinitialize(size_type rows=0, size_type cols=0)
Initialize a sized (on unsized) zero matrix to start with.
virtual index_type dim() const
Return the dimension of this vector.
virtual value_type get_ele(index_type i) const
Fetch an element in the vector.
Abstract interface for mutable coordinate vectors {abstract}.
Sparse storage element type.
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 size_type rows() const
Return the number of rows in the matrix.
void remove_matrix(matrix_list_t::iterator itr)
Remove a sub-matrix.
size_type cols(size_type rows, size_type cols, BLAS_Cpp::Transp _trans)
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)
void add_vector(size_type row_offset, size_type col_offset, value_type beta, const GenPermMatrixSlice *G, const release_resource_ptr_t &G_release, BLAS_Cpp::Transp G_trans, const Vector *v, const release_resource_ptr_t &v_release, BLAS_Cpp::Transp v_trans)
Add a sub-vector beta*op(op(G)*v).
const VectorSpace & space_rows() 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)
void Vp_StMtV(VectorMutable *vs_lhs, value_type alpha, BLAS_Cpp::Transp trans_rhs1, const Vector &v_rhs2, value_type beta) const