MOOCHO (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
AbstractLinAlgPack_MatrixNonsingSerial.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 // ToDo: 3/6/00: Provide default implementations for these
43 // operations.
44 
45 #include <assert.h>
46 
59 
60 namespace LinAlgOpPack {
64 }
65 
66 namespace AbstractLinAlgPack {
67 
68 // Level-2 BLAS
69 
71  DVector* v_lhs, BLAS_Cpp::Transp trans_rhs1,const DVectorSlice& vs_rhs2
72  ) const
73 {
74  const size_type n = rows();
75  DenseLinAlgPack::MtV_assert_sizes( n, n, trans_rhs1, vs_rhs2.dim() );
76  v_lhs->resize(n);
77  this->V_InvMtV( &(*v_lhs)(), trans_rhs1, vs_rhs2 );
78 }
79 
81  DVector* v_lhs, BLAS_Cpp::Transp trans_rhs1, const SpVectorSlice& sv_rhs2
82  ) const
83 {
84  const size_type n = rows();
85  DenseLinAlgPack::MtV_assert_sizes( n, n, trans_rhs1, sv_rhs2.dim() );
86  v_lhs->resize(n);
87  DVector v_rhs2;
88  LinAlgOpPack::assign( &v_rhs2, sv_rhs2 );
89  this->V_InvMtV( &(*v_lhs)(), trans_rhs1, v_rhs2() );
90 }
91 
93  DVectorSlice* vs_lhs, BLAS_Cpp::Transp trans_rhs1, const SpVectorSlice& sv_rhs2
94  ) const
95 {
96  const size_type n = rows();
97  DenseLinAlgPack::Vp_MtV_assert_sizes( vs_lhs->dim(), n, n, trans_rhs1, sv_rhs2.dim() );
98  DVector v_rhs2;
99  LinAlgOpPack::assign( &v_rhs2, sv_rhs2 );
100  this->V_InvMtV( vs_lhs, trans_rhs1, v_rhs2() );
101 }
102 
104  const DVectorSlice& vs_rhs1, BLAS_Cpp::Transp trans_rhs2, const DVectorSlice& vs_rhs3
105  ) const
106 {
107  const size_type n = rows();
108  DenseLinAlgPack::Vp_MtV_assert_sizes( vs_rhs1.dim(), n, n, trans_rhs2, vs_rhs3.dim() );
109  DVector tmp;
110  this->V_InvMtV( &tmp, trans_rhs2, vs_rhs3 );
111  return DenseLinAlgPack::dot( vs_rhs1, tmp() );
112 }
113 
115  const SpVectorSlice& sv_rhs1, BLAS_Cpp::Transp trans_rhs2, const SpVectorSlice& sv_rhs3
116  ) const
117 {
118  const size_type n = rows();
119  DenseLinAlgPack::Vp_MtV_assert_sizes( sv_rhs1.dim(), n, n, trans_rhs2, sv_rhs3.dim() );
120  DVector tmp;
121  this->V_InvMtV( &tmp, trans_rhs2, sv_rhs3 );
122  return AbstractLinAlgPack::dot( sv_rhs1, tmp() );
123 }
124 
125 // Level-3 BLAS
126 
129  ,BLAS_Cpp::Transp A_trans
130  ,const DMatrixSlice& B, BLAS_Cpp::Transp B_trans
131  ) const
132 {
133  DenseLinAlgPack::MtM_assert_sizes( rows(), cols(), A_trans, B.rows(), B.cols(), B_trans );
134  C->resize(
135  BLAS_Cpp::rows( rows(), cols(), A_trans )
136  , BLAS_Cpp::cols( B.rows(), B.cols(), B_trans )
137  );
138  this->M_StInvMtM( &(*C)(), a, A_trans, B, B_trans );
139 }
140 
143  ,BLAS_Cpp::Transp A_trans
144  ,const DMatrixSlice& B, BLAS_Cpp::Transp B_trans
145  ) const
146 {
148  , rows(), cols(), A_trans, B.rows(), B.cols(), B_trans );
149  //
150  // C = a * inv(op(A)) * op(B)
151  //
152  // C.col(j) = a * inv(op(A)) * op(B).col(j)
153  //
154 
155  for( size_type j = 1; j <= C->cols(); ++j )
156  AbstractLinAlgPack::V_InvMtV( &C->col(j), *this, A_trans
157  , DenseLinAlgPack::col( B, B_trans, j ) );
158  if( a != 1.0 )
159  LinAlgOpPack::Mt_S( C, a );
160 }
161 
163  DMatrix* gm_lhs, value_type alpha
164  ,const DMatrixSlice& gms_rhs1, BLAS_Cpp::Transp trans_rhs1
165  ,BLAS_Cpp::Transp trans_rhs2
166  ) const
167 {
168  TEUCHOS_TEST_FOR_EXCEPT(true); // ToDo: Implement this!
169 }
170 
172  DMatrixSlice* gms_lhs, value_type alpha
173  ,const DMatrixSlice& gms_rhs1, BLAS_Cpp::Transp trans_rhs1
174  ,BLAS_Cpp::Transp trans_rhs2
175  ) const
176 {
177  TEUCHOS_TEST_FOR_EXCEPT(true); // ToDo: Implement this!
178 }
179 
182  ,BLAS_Cpp::Transp A_trans
183  ,const MatrixOpSerial& B, BLAS_Cpp::Transp B_trans
184  ) const
185 {
186  DenseLinAlgPack::MtM_assert_sizes( rows(), cols(), A_trans, B.rows(), B.cols(), B_trans );
187  C->resize(
188  BLAS_Cpp::rows( rows(), cols(), A_trans )
189  , BLAS_Cpp::cols( B.rows(), B.cols(), B_trans )
190  );
191  AbstractLinAlgPack::M_StInvMtM( &(*C)(), a, *this, A_trans, B, B_trans );
192 }
193 
196  ,BLAS_Cpp::Transp A_trans
197  ,const MatrixOpSerial& B, BLAS_Cpp::Transp B_trans
198  ) const
199 {
200  using LinAlgOpPack::assign;
202  , rows(), cols(), A_trans, B.rows(), B.cols(), B_trans );
203  DMatrix B_dense;
204  assign( &B_dense, B, BLAS_Cpp::no_trans );
205  AbstractLinAlgPack::M_StInvMtM( C, a, *this, A_trans, B_dense(), B_trans );
206 }
207 
209  DMatrix* gm_lhs, value_type alpha
210  ,const MatrixOpSerial& mwo_rhs1, BLAS_Cpp::Transp trans_rhs1
211  ,BLAS_Cpp::Transp trans_rhs2
212  ) const
213 {
214  TEUCHOS_TEST_FOR_EXCEPT(true); // ToDo: Implement this!
215 }
216 
218  DMatrixSlice* gms_lhs, value_type alpha
219  ,const MatrixOpSerial& mwo_rhs1, BLAS_Cpp::Transp trans_rhs1
220  ,BLAS_Cpp::Transp trans_rhs2
221  ) const
222 {
223  TEUCHOS_TEST_FOR_EXCEPT(true); // ToDo: Implement this!
224 }
225 
226 // Overridden from MatrixNonsing
227 
229  VectorMutable* v_lhs, BLAS_Cpp::Transp trans_rhs1
230  ,const Vector& v_rhs2) const
231 {
232  VectorDenseMutableEncap vs_lhs(*v_lhs);
233  VectorDenseEncap vs_rhs2(v_rhs2);
234  this->V_InvMtV( &vs_lhs(), trans_rhs1, vs_rhs2() );
235 }
236 
238  VectorMutable* v_lhs, BLAS_Cpp::Transp trans_rhs1
239  ,const SpVectorSlice& sv_rhs2) const
240 {
241  this->V_InvMtV( &VectorDenseMutableEncap(*v_lhs)(), trans_rhs1, sv_rhs2 );
242 }
243 
245  const Vector& v_rhs1
246  ,BLAS_Cpp::Transp trans_rhs2, const Vector& v_rhs3) const
247 {
248  VectorDenseEncap vs_rhs1(v_rhs1);
249  VectorDenseEncap vs_rhs3(v_rhs3);
250  return this->transVtInvMtV(vs_rhs1(),trans_rhs2,vs_rhs3());
251 }
252 
254  MatrixOp* m_lhs, value_type alpha
255  ,BLAS_Cpp::Transp trans_rhs1
256  ,const MatrixOp& mwo_rhs2,BLAS_Cpp::Transp trans_rhs2
257  ) const
258 {
259  using Teuchos::dyn_cast;
261  gms_lhs(m_lhs); // Warning! This may throw an exception!
262  if(const MatrixOpGetGMS* mwo_gms_rhs2 = dynamic_cast<const MatrixOpGetGMS*>(&mwo_rhs2)) {
263  this->M_StInvMtM(&gms_lhs(),alpha,trans_rhs1,MatrixDenseEncap(*mwo_gms_rhs2)(),trans_rhs2);
264  return;
265  }
266  this->M_StInvMtM(&gms_lhs(),alpha,trans_rhs1,dyn_cast<const MatrixOpSerial>(mwo_rhs2),trans_rhs2);
267 }
268 
270  MatrixOp* m_lhs, value_type alpha
271  ,const MatrixOp& mwo_rhs1, BLAS_Cpp::Transp trans_rhs1
272  ,BLAS_Cpp::Transp trans_rhs2
273  ) const
274 {
275  using Teuchos::dyn_cast;
277  gms_lhs(m_lhs); // Warning! This may throw an exception!
278  if(const MatrixOpGetGMS* mwo_gms_rhs1 = dynamic_cast<const MatrixOpGetGMS*>(&mwo_rhs1)) {
279  this->M_StMtInvM(&gms_lhs(),alpha,MatrixDenseEncap(*mwo_gms_rhs1)(),trans_rhs1,trans_rhs2);
280  return;
281  }
282  this->M_StMtInvM(&gms_lhs(),alpha,dyn_cast<const MatrixOpSerial>(mwo_rhs1),trans_rhs1,trans_rhs2);
283 }
284 
285 } // end namespace AbstractLinAlgPack
Abstract interface for immutable, finite dimensional, coordinate vectors {abstract}.
size_type dim() const
Returns the number of elements of the VectorSliceTmpl.
size_type dim() const
Return the number of elements in the full vector.
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)
size_type cols() const
Return the number of columns.
void Vp_StV(VectorMutable *v_lhs, const value_type &alpha, const Vector &v_rhs)
v_lhs = alpha * v_rhs + v_lhs
size_type rows(size_type rows, size_type cols, BLAS_Cpp::Transp _trans)
Return rows of a possible transposed matrix.
void assign(VectorMutable *v_lhs, const V &V_rhs)
v_lhs = V_rhs.
void resize(size_type n, value_type val=value_type())
void Mp_MtM_assert_sizes(size_type m_lhs_rows, size_type m_lhs_cols, BLAS_Cpp::Transp trans_lhs, 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) * op(m_rhs2)
Base class for all matrices implemented in a shared memory address space.
Not transposed.
virtual void M_StInvMtM(DMatrix *gm_lhs, value_type alpha, BLAS_Cpp::Transp trans_rhs1, const DMatrixSlice &gms_rhs2, BLAS_Cpp::Transp trans_rhs2) const
gm_lhs = alpha * inv(op(M_rhs1)) * op(gms_rhs2) (right)
virtual size_type cols() const
Return the number of columns in the matrix.
T_To & dyn_cast(T_From &from)
Extract a constant DenseLinAlgPack::DVectorSlice view of a Vector object.
void V_InvMtV(VectorMutable *v_lhs, const MatrixNonsing &M_rhs1, BLAS_Cpp::Transp trans_rhs1, const Vector &v_rhs2)
v_lhs = inv(op(M_rhs1)) * v_rhs2
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)
DVectorSlice col(DMatrixSlice &gms, BLAS_Cpp::Transp trans, size_type j)
virtual void V_InvMtV(DVector *v_lhs, BLAS_Cpp::Transp trans_rhs1, const DVectorSlice &vs_rhs2) const
v_lhs = inv(op(M_rhs1)) * vs_rhs2
void resize(size_type rows, size_type cols, value_type val=value_type())
Resize matrix to a (rows x cols) matrix and initializes any added elements by val.
Abstract interface that allows the extraction of a const DMatrixSlice view of an abstract matrix...
Helper class type that simplifies the usage of the MatrixOpGetGMS interface for clients.
Base class for all matrices that support basic matrix operations.
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
void assign(DMatrix &gm_lhs, const T_Matrix &gm_rhs, BLAS_Cpp::Transp trans_rhs)
gm_lhs = T_M (templated matrix type T_M)
size_type rows() const
Return the number of rows.
virtual value_type transVtInvMtV(const DVectorSlice &vs_rhs1, BLAS_Cpp::Transp trans_rhs2, const DVectorSlice &vs_rhs3) const
result = vs_rhs1' * inv(op(M_rhs2)) * vs_rhs3
Abstract interface for mutable coordinate vectors {abstract}.
virtual void M_StMtInvM(DMatrix *gm_lhs, value_type alpha, const DMatrixSlice &gms_rhs1, BLAS_Cpp::Transp trans_rhs1, BLAS_Cpp::Transp trans_rhs2) const
gm_lhs = alpha * op(gms_rhs1) * inv(op(M_rhs2)) (left)
void Vp_MtV_assert_sizes(size_type v_lhs_size, size_type m_rhs1_rows, size_type m_rhs1_cols, BLAS_Cpp::Transp trans_rhs1, size_type v_rhs2_size)
v_lhs += op(m_rhs1) * v_rhs2
Extract a non-const DenseLinAlgPack::DVectorSlice view of a VectorMutable object. ...
void M_StInvMtM(MatrixOp *m_lhs, value_type alpha, const MatrixNonsing &M_rhs1, BLAS_Cpp::Transp trans_rhs1, const MatrixOp &mwo_rhs2, BLAS_Cpp::Transp trans_rhs2)
m_lhs = alpha * inv(op(mwo_rhs1)) * op(mwo_rhs2) (right)
virtual size_type rows() const
Return the number of rows in the matrix.
void MtV_assert_sizes(size_type m_rhs1_rows, size_type m_rhs1_cols, BLAS_Cpp::Transp trans_rhs1, size_type v_rhs2_size)
op(m_rhs1) * v_rhs2
DVectorSlice col(size_type j)
Return DVectorSlice object representing the jth column (1-based; 1,2,..,#this->cols()#, or throw std::out_of_range)
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)
value_type dot(const DVectorSlice &vs_rhs1, const DVectorSlice &vs_rhs2)
result = vs_rhs1' * vs_rhs2 (BLAS xDOT)
Helper class type that simplifies the usage of the MatrixOpGetGMSMutable interface for clients...