MOOCHO (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RTOpPack_OldTypes.hpp
Go to the documentation of this file.
1 /*
2 // @HEADER
3 // ***********************************************************************
4 //
5 // Moocho: Multi-functional Object-Oriented arCHitecture for Optimization
6 // Copyright (2003) Sandia Corporation
7 //
8 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
9 // license for use of this work by or on behalf of the U.S. Government.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov)
39 //
40 // ***********************************************************************
41 // @HEADER
42 */
43 
44 #ifndef RTOPPACK_OLD_TYPES_HPP
45 #define RTOPPACK_OLD_TYPES_HPP
46 
47 #include "RTOpPack_Types.hpp"
48 #include "RTOpPack_SparseSubVectorT.hpp"
49 #include "RTOp.h"
50 
51 namespace RTOpPack {
52 
55 template<class Scalar>
56 class SubVectorT1B {
57 public:
59  SubVectorT1B() : globalOffset_(0), subDim_(0), values_(Teuchos::null), stride_(0) {}
62  :globalOffset_(globalOffset), subDim_(subDim), values_(values,0,subDim*stride,false), stride_(stride)
63  {}
67  {}
69  SubVectorT1B( const ConstSubVectorView<Scalar>& sv )
71  {}
73  operator ConstSubVectorView<Scalar>()
74  { return ConstSubVectorView<Scalar>(globalOffset(),subDim(),arcp_values(),stride()); }
77  { globalOffset_=globalOffset; subDim_=subDim; values_=Teuchos::arcp(values,0,subDim*stride,false); stride_=stride; }
86  Teuchos_Ordinal subDim() const { return subDim_; }
88  const Scalar* values() const { return values_.get(); }
92  ptrdiff_t stride() const { return stride_; }
94  const Scalar& operator[](Teuchos_Ordinal i) const
95  {
96 #ifdef TEUCHOS_DEBUG
98  !( 0 <= i && i < subDim_ ), std::logic_error
99  ,"Error, index i="<<i<<" does not fall in the range [0,"<<(subDim_-1)<<"]!"
100  );
101 #endif
102  return values_[ stride_*i ];
103  }
105  const Scalar& operator()(Teuchos_Ordinal i) const { return (*this)[i-1]; }
106 private:
110  ptrdiff_t stride_;
111 };
112 
115 template<class Scalar>
116 class MutableSubVectorT1B : public SubVectorT1B<Scalar> {
117 public:
122  :SubVectorT1B<Scalar>(globalOffset, subDim, values, stride)
123  {}
126  :SubVectorT1B<Scalar>(sv)
127  {}
129  MutableSubVectorT1B( const SubVectorView<Scalar>& sv )
130  :SubVectorT1B<Scalar>(ConstSubVectorView<Scalar>(sv))
131  {}
133  operator SubVectorView<Scalar>()
134  { return SubVectorView<Scalar>(this->globalOffset(),this->subDim(),this->arcp_values(),this->stride()); }
137  { SubVectorT1B<Scalar>::initialize(globalOffset, subDim, values, stride); }
142  Scalar* values() const { return const_cast<Scalar*>(SubVectorT1B<Scalar>::values()); }
144  const Teuchos::ArrayRCP<Scalar> arcp_values() const { return Teuchos::arcp_const_cast<Scalar>(SubVectorT1B<Scalar>::arcp_values()); }
146  Scalar& operator[](Teuchos_Ordinal i) const { return const_cast<Scalar&>(SubVectorT1B<Scalar>::operator[](i)); } // Is range changed in subclass!
148  Scalar& operator()(Teuchos_Ordinal i) const { return (*this)[i-1]; }
149 };
150 
151 template<class Scalar>
153 {
154 #ifdef TEUCHOS_DEBUG
155  TEUCHOS_TEST_FOR_EXCEPT(msv==NULL);
156  TEUCHOS_TEST_FOR_EXCEPT(msv->subDim() != sv.subDim());
157 #endif
158  for( int i = 1; i <= sv.subDim(); ++i ) {
159  (*msv)(i) = sv(i);
160  }
161 }
162 
165 template<class Scalar>
167 public:
171  ,values_(NULL), leadingDim_(0)
172  {}
177  ,const Scalar *values, Teuchos_Ordinal leadingDim
178  )
179  :globalOffset_(globalOffset), subDim_(subDim)
180  ,colOffset_(colOffset), numSubCols_(numSubCols)
181  ,values_(values), leadingDim_(leadingDim)
182  {}
185  :globalOffset_(smv.globalOffset()), subDim_(smv.subDim())
187  ,values_(smv.values()), leadingDim_(smv.leadingDim())
188  {}
189 /*
190  SubMultiVectorT1B( const ConstSubMultiVectorView<Scalar>& smv )
191  :globalOffset_(smv.globalOffset()), subDim_(smv.subDim())
192  ,colOffset_(smv.colOffset()), numSubCols_(smv.numSubCols())
193  ,values_(smv.values()), leadingDim_(smv.leadingDim())
194  {}
195  operator ConstSubMultiVectorView<Scalar>()
196  { return ConstSubMultiVectorView<Scalar>(globalOffset(),subDim(),colOffset(),numSubCols(),values(),leadingDim()); }
197 */
202  ,const Scalar *values, Teuchos_Ordinal leadingDim
203  )
214  Teuchos_Ordinal subDim() const { return subDim_; }
220  const Scalar* values() const { return values_; }
224  const Scalar& operator()(Teuchos_Ordinal i, Teuchos_Ordinal j) const
225  {
226 #ifdef TEUCHOS_DEBUG
228  !( 1 <= i && i < subDim_ ), std::logic_error
229  ,"Error, index i="<<i<<" does not fall in the range [1,"<<(subDim_-1)<<"]!"
230  );
232  !( 1 <= j && j <= numSubCols_ ), std::logic_error
233  ,"Error, index j="<<j<<" does not fall in the range [1,"<<(numSubCols_-1)<<"]!"
234  );
235 #endif
236  return values_[ (i-1) + leadingDim_*(j-1) ];
237  }
240  {
241 #ifdef TEUCHOS_DEBUG
243  !( 1 <= j && j <= numSubCols_ ), std::logic_error
244  ,"Error, index j="<<j<<" does not fall in the range [1,"<<(numSubCols_-1)<<"]!"
245  );
246 #endif
247  return SubVectorT1B<Scalar>(globalOffset(),subDim(),values()+(j-1)*leadingDim(),1);
248  }
249 private:
254  const Scalar *values_;
256 };
257 
260 template<class Scalar>
262 public:
269  ,const Scalar *values, Teuchos_Ordinal leadingDim
270  )
271  :SubMultiVectorT1B<Scalar>(globalOffset,subDim,colOffset,numSubCols,values,leadingDim)
272  {}
275  :SubMultiVectorT1B<Scalar>(smv)
276  {}
277 /*
278  MutableSubMultiVectorT1B( const SubMultiVectorView<Scalar>& smv )
279  :SubMultiVectorT1B<Scalar>(
280  MutableSubMultiVectorT1B<Scalar>(
281  smv.globalOffset(),smv.subDim(),smv.colOffset(),smv.numSubCols()
282  ,smv.values(),smv.leadingDim()
283  )
284  )
285  {}
286  operator SubMultiVectorView<Scalar>()
287  { return SubMultiVectorView<Scalar>(this->globalOffset(),this->subDim(),this->colOffset(),this->numSubCols(),this->values(),this->leadingDim()); }
288 */
293  ,const Scalar *values, Teuchos_Ordinal leadingDim
294  )
295  { SubMultiVectorT1B<Scalar>::initialize(globalOffset,subDim,colOffset,numSubCols,values,leadingDim); }
300  Scalar* values() const { return const_cast<Scalar*>(SubMultiVectorT1B<Scalar>::values()); }
303  { return const_cast<Scalar&>(SubMultiVectorT1B<Scalar>::operator()(i,j)); } // Is range checked in subclass
306  {
307 #ifdef TEUCHOS_DEBUG
309  !( 1 <= j && j <= this->numSubCols() ), std::logic_error
310  ,"Error, index j="<<j<<" does not fall in the range [1,"<<(this->numSubCols())<<"]!"
311  );
312 #endif
313  return MutableSubVectorT1B<Scalar>(this->globalOffset(),this->subDim(),values()+(j-1)*this->leadingDim(),1);
314  }
315 };
316 
317 template<class Scalar>
319 {
320 #ifdef TEUCHOS_DEBUG
321  TEUCHOS_TEST_FOR_EXCEPT(msmv==NULL);
322  TEUCHOS_TEST_FOR_EXCEPT(msmv->subDim() != smv.subDim());
324 #endif
325  for( Teuchos_Ordinal j = 1; j <= smv.numSubCols(); ++j ) {
326  for( Teuchos_Ordinal i = 1; i < smv.subDim(); ++i ) {
327  (*msmv)(i,j) = smv(i,j);
328  }
329  }
330 }
331 
332 //
333 // Typedefs
334 //
335 
341 typedef SparseSubVectorT<RTOp_value_type> SparseSubVector;
347 typedef RTOpT<RTOp_value_type> RTOp;
348 
349 } // namespace RTOpPack
350 
351 #endif // RTOPPACK_OLD_TYPES_HPP
Teuchos::ArrayRCP< const Scalar > values_
ptrdiff_t stride() const
Scalar & operator()(Teuchos_Ordinal i, Teuchos_Ordinal j) const
One-based indexing (Preconditions: values()!=NULL && (1<=i<= subDim()) && (1<=j<=numSubCols()) ...
Teuchos_Ordinal leadingDim() const
SubMultiVectorT1B< RTOp_value_type > SubMultiVector
MutableSubMultiVectorT1B(Teuchos_Ordinal globalOffset, Teuchos_Ordinal subDim, Teuchos_Ordinal colOffset, Teuchos_Ordinal numSubCols, const Scalar *values, Teuchos_Ordinal leadingDim)
const Scalar & operator[](Teuchos_Ordinal i) const
Zero-based indexing (Preconditions: values()!=NULL && (0 <= i < subDim()))
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
MutableSubVectorT1B(const SubVectorView< Scalar > &sv)
const Scalar * values() const
SubMultiVectorT1B(Teuchos_Ordinal globalOffset, Teuchos_Ordinal subDim, Teuchos_Ordinal colOffset, Teuchos_Ordinal numSubCols, const Scalar *values, Teuchos_Ordinal leadingDim)
Class for a non-mutable sub-multi-vector (submatrix).
SubVectorT1B(const SubVectorT1B< Scalar > &sv)
SubVectorT1B< RTOp_value_type > SubVector
Teuchos_Ordinal subDim() const
Scalar & operator()(Teuchos_Ordinal i) const
One-based indexing (Preconditions: values()!=NULL && (1 <= i <= subDim()))
MutableSubVectorT1B< Scalar > col(const Teuchos_Ordinal j) const
Return a MutableSubVectorT1B view of the jth sub-column (Preconditions: values()!=NULL && (1<=j<=numS...
const Teuchos::ArrayRCP< const Scalar > arcp_values() const
Teuchos_Ordinal numSubCols() const
TEUCHOS_ORDINAL_TYPE Teuchos_Ordinal
RTOpT< RTOp_value_type > RTOp
SubVectorT1B(const ConstSubVectorView< Scalar > &sv)
Teuchos_Ordinal subDim() const
Scalar & operator[](Teuchos_Ordinal i) const
Zero-based indexing (Preconditions: values()!=NULL && (0 <= i < subDim()))
MutableSubVectorT1B(const MutableSubVectorT1B< Scalar > &sv)
const Scalar & operator()(Teuchos_Ordinal i, Teuchos_Ordinal j) const
One-based indexing (Preconditions: values()!=NULL && (1<=i<=subDim()) && (1<=j<= numSubCols()) ...
SubVectorT1B(Teuchos_Ordinal globalOffset, Teuchos_Ordinal subDim, const Scalar *values, ptrdiff_t stride)
void assign_entries(const MutableSubVectorT1B< Scalar > *msv, const SubVectorT1B< Scalar > &sv)
void initialize(Teuchos_Ordinal globalOffset, Teuchos_Ordinal subDim, Teuchos_Ordinal colOffset, Teuchos_Ordinal numSubCols, const Scalar *values, Teuchos_Ordinal leadingDim)
Teuchos_Ordinal globalOffset() const
Teuchos_Ordinal globalOffset() const
void initialize(Teuchos_Ordinal globalOffset, Teuchos_Ordinal subDim, Scalar *values, ptrdiff_t stride)
void setGlobalOffset(Teuchos_Ordinal globalOffset)
SparseSubVectorT< RTOp_value_type > SparseSubVector
MutableSubMultiVectorT1B(const MutableSubMultiVectorT1B< Scalar > &smv)
const Scalar & operator()(Teuchos_Ordinal i) const
One-based indexing (Preconditions: values()!=NULL && (1 <= i <= subDim()))
MutableSubVectorT1B(Teuchos_Ordinal globalOffset, Teuchos_Ordinal subDim, Scalar *values, ptrdiff_t stride)
Class for a mutable sub-vector.
MutableSubVectorT1B< RTOp_value_type > MutableSubVector
void initialize(Teuchos_Ordinal globalOffset, Teuchos_Ordinal subDim, Teuchos_Ordinal colOffset, Teuchos_Ordinal numSubCols, const Scalar *values, Teuchos_Ordinal leadingDim)
const Teuchos::ArrayRCP< Scalar > arcp_values() const
void initialize(Teuchos_Ordinal globalOffset, Teuchos_Ordinal subDim, const Scalar *values, ptrdiff_t stride)
T * get() const
SubMultiVectorT1B(const SubMultiVectorT1B< Scalar > &smv)
Class for a mutable sub-vector.
MutableSubMultiVectorT1B< RTOp_value_type > MutableSubMultiVector
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)
Class for a non-mutable sub-vector.
Teuchos_Ordinal colOffset() const
SubVectorT1B< Scalar > col(const Teuchos_Ordinal j) const
Return a SubVectorT1B view of the jth sub-column (Preconditions: values()!=NULL (1<=j<=numSubCols()) ...
void setGlobalOffset(Teuchos_Ordinal globalOffset)
const Scalar * values() const