MOOCHO (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AbstractLinAlgPack_MatrixSymOpSerial.cpp
Go to the documentation of this file.
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Moocho: Multi-functional Object-Oriented arCHitecture for Optimization
5 // Copyright (2003) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov)
38 //
39 // ***********************************************************************
40 // @HEADER
41 
42 #include <assert.h>
43 
52 #include "Teuchos_dyn_cast.hpp"
53 
54 namespace AbstractLinAlgPack {
55 
59  ,const GenPermMatrixSlice& P, BLAS_Cpp::Transp P_trans
60  ,value_type b
61  ) const
62 {
63  using BLAS_Cpp::no_trans;
64  using BLAS_Cpp::trans;
65  using BLAS_Cpp::trans_not;
66  using BLAS_Cpp::cols;
67  //
68  // S = b*S
69  //
70  // S += a*op(P')*M*op(P)
71  //
72  // We will perform this operation for each column in op(P) as:
73  //
74  // op(P)(:,j(k)) = e(i(k)) <: R^n
75  //
76  // S += a*op(P')*M*[ ... e(i(1)) ... e(i(k)) ... e(i(nz)) ... ]
77  // j(k)
78  //
79  // We will perform this by column as:
80  //
81  // for k = 1...nz
82  // S(:,j(k)) += a*y_k
83  //
84  // where:
85  // y_k = op(P')*M*e(i(k))
86  //
87  // Above we only need to set the portion of S(:,j(k)) for the stored part
88  // of the symmetric matrix (i.e. upper part for upper and lower part for lower).
89  //
91  this->rows(), this->cols(), no_trans
92  , P.rows(), P.cols(), P_trans );
94  S->rows(), S->cols(), no_trans
95  , cols( P.rows(), P.cols(), P_trans )
96  , cols( P.rows(), P.cols(), P_trans )
97  , no_trans );
98  //
99  const size_type
100  n = this->rows(),
101  m = S->rows();
102  // S = b*S
103  if( b != 1.0 )
105  // Set the colums of S
106  DVector y_k_store(m);
107  DVectorSlice y_k = y_k_store();
108  for( GenPermMatrixSlice::const_iterator P_itr = P.begin(); P_itr != P.end(); ++P_itr )
109  {
110  const size_type
111  i_k = P_trans == no_trans ? P_itr->row_i() : P_itr->col_j(),
112  j_k = P_trans == no_trans ? P_itr->col_j() : P_itr->row_i();
113  // e(i(k))
114  EtaVector
115  e_i_k(i_k,n);
116  // y_k = op(P')*M*e(i(k))
117  AbstractLinAlgPack::Vp_StPtMtV( &y_k, 1.0, P, trans_not(P_trans), *this, no_trans, e_i_k(), 0.0 );
118  // S(:,j(k)) += a*y_k
119  if( S->uplo() == BLAS_Cpp::upper )
120  DenseLinAlgPack::Vp_StV( &S->gms().col(j_k)(1,j_k), a, y_k(1,j_k) );
121  else
122  DenseLinAlgPack::Vp_StV( &S->gms().col(j_k)(j_k,m), a, y_k(j_k,m) );
123  }
124 }
125 
127  DMatrixSliceSym* sym_lhs, value_type alpha
128  ,EMatRhsPlaceHolder dummy_place_holder
129  ,const MatrixOpSerial& mwo_rhs, BLAS_Cpp::Transp mwo_rhs_trans
130  ,value_type beta
131  ) const
132 {
133  TEUCHOS_TEST_FOR_EXCEPT(true); // ToDo: Give this some default implementation for
134  // this at some point in the future?
135 }
136 
137 // Overridden from MatrixSymOp
138 
140 {
142 }
143 
145  MatrixSymOp* symwo_lhs, value_type alpha
146  ,EMatRhsPlaceHolder dummy
147  ,const GenPermMatrixSlice& gpms_rhs, BLAS_Cpp::Transp gpms_rhs_trans
148  ,value_type beta
149  ) const
150 {
151  this->Mp_StPtMtP(
152  &MatrixDenseSymMutableEncap(symwo_lhs)(), alpha, dummy
153  ,gpms_rhs, gpms_rhs_trans
154  , beta );
155 }
156 
158  MatrixSymOp* symwo_lhs, value_type alpha
159  ,EMatRhsPlaceHolder dummy
160  ,const MatrixOp& mwo_rhs, BLAS_Cpp::Transp mwo_rhs_trans
161  ,value_type beta
162  ) const
163 {
164  using Teuchos::dyn_cast;
165  this->Mp_StMtMtM(
166  &MatrixDenseSymMutableEncap(symwo_lhs)(), alpha, dummy
167  ,dyn_cast<const MatrixOpSerial>(mwo_rhs), mwo_rhs_trans
168  ,beta );
169 }
170 
171 } // end namespace AbstractLinAlgPack
virtual void Mp_StPtMtP(DMatrixSliceSym *sym_lhs, value_type alpha, EMatRhsPlaceHolder dummy_place_holder, const GenPermMatrixSlice &gpms_rhs, BLAS_Cpp::Transp gpms_rhs_trans, value_type beta) const
sym_lhs = alpha * op(gpms_rhs') * M * op(gpms_rhs) + beta * sym_lhs.
void Vp_StV(DVectorSlice *vs_lhs, value_type alpha, const DVectorSlice &vs_rhs)
vs_lhs += alpha * vs_rhs (BLAS xAXPY)
void MtM_assert_sizes(size_type m_rhs1_rows, size_type m_rhs1_cols, BLAS_Cpp::Transp trans_rhs1, size_type m_rhs2_rows, size_type m_rhs2_cols, BLAS_Cpp::Transp trans_rhs2)
op(m_lhs) += op(m_rhs1)
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
const_iterator end() const
Return the end of this->const_iterator_begin().
void Mp_M_assert_sizes(size_type m_lhs_rows, size_type m_lhs_cols, BLAS_Cpp::Transp trans_lhs, size_type m_rhs_rows, size_type m_rhs_cols, BLAS_Cpp::Transp trans_rhs)
op(m_lhs) += op op(m_rhs)
Transposed.
Base class for all matrices implemented in a shared memory address space.
Interface adding operations specific for a symmetric matrix {abstract}.
Not transposed.
const VectorSpace & space_rows() const
Must be overridden to call MatrixOpSerial::space_rows()
This is a full random access iterator for accessing row and colunmn indices.
Abstract interface for objects that represent a space for mutable coordinate vectors.
T_To & dyn_cast(T_From &from)
const_iterator begin() const
Return a random access iterator for accessing which row and column that each nonzero 1...
Helper class type that simplifies the usage of the MatrixSymOpGetGMSSymMutable interface for clients...
void Mt_S(DMatrixSlice *gms_lhs, value_type alpha)
gms_lhs *= alpha (BLAS xSCAL)
Create an eta vector (scaled by alpha = default 1).
f_dbl_prec f_dbl_prec f_dbl_prec * S
DMatrixSliceTriEle nonconst_tri_ele(DMatrixSlice gms, BLAS_Cpp::Uplo uplo)
Return a triangular element-wise matrix.
Base class for all matrices that support basic matrix operations.
Transp trans_not(Transp _trans)
Return the opposite of the transpose argument.
size_type cols() const
Returns this->rows()
virtual size_type rows() const
Return the number of rows in the matrix.
DVectorSlice col(size_type j)
Return DVectorSlice object representing the jth column (1-based; 1,2,..,#this->cols()#, or throw std::out_of_range)
virtual void Mp_StMtMtM(DMatrixSliceSym *sym_lhs, value_type alpha, EMatRhsPlaceHolder dummy_place_holder, const MatrixOpSerial &mwo_rhs, BLAS_Cpp::Transp mwo_rhs_trans, value_type beta) const
sym_lhs = alpha * op(mwo_rhs') * M * op(mwo_rhs).
Transp
TRANS.
int n
size_type cols(size_type rows, size_type cols, BLAS_Cpp::Transp _trans)
Return columns of a possible transposed matrix.
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)
Concrete matrix type to represent general permutation (mapping) matrices.