Thyra  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Thyra_MultiVectorDefaultBase_def.hpp
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Thyra: Interfaces and Support for Abstract Numerical Algorithms
5 // Copyright (2004) 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 (bartlettra@ornl.gov)
38 //
39 // ***********************************************************************
40 // @HEADER
41 
42 #ifndef THYRA_MULTI_VECTOR_DEFAULT_BASE_DEF_HPP
43 #define THYRA_MULTI_VECTOR_DEFAULT_BASE_DEF_HPP
44 
45 
46 #include "Thyra_MultiVectorDefaultBase_decl.hpp"
47 #include "Thyra_LinearOpDefaultBase.hpp"
48 #include "Thyra_MultiVectorStdOps.hpp"
49 #include "Thyra_VectorSpaceFactoryBase.hpp"
50 #include "Thyra_VectorSpaceBase.hpp"
51 #include "Thyra_VectorBase.hpp"
52 #include "Thyra_AssertOp.hpp"
53 #include "Thyra_DefaultColumnwiseMultiVector.hpp"
54 #include "RTOpPack_TOpAssignScalar.hpp"
55 #include "RTOpPack_ROpDotProd.hpp"
56 #include "RTOpPack_ROpNorm1.hpp"
57 #include "RTOpPack_ROpNorm2.hpp"
58 #include "RTOpPack_ROpNormInf.hpp"
59 #include "RTOpPack_TOpAssignVectors.hpp"
60 #include "RTOpPack_TOpAXPY.hpp"
61 #include "RTOpPack_TOpLinearCombination.hpp"
62 #include "RTOpPack_TOpScaleVector.hpp"
63 #include "Teuchos_Workspace.hpp"
64 #include "Teuchos_Assert.hpp"
65 #include "Teuchos_as.hpp"
66 
67 
68 namespace Thyra {
69 
70 
71 // Overridden public member functions from MultiVectorBase
72 
73 
74 template<class Scalar>
75 RCP<MultiVectorBase<Scalar> >
77 {
79  &l_domain = *this->domain(),
80  &l_range = *this->range();
82  copy = createMembers(l_range,l_domain.dim());
83  ::Thyra::assign<Scalar>(copy.ptr(), *this);
84  return copy;
85 }
86 
87 
88 // protected
89 
90 
91 // Overridden protected member functions from MultiVectorBase
92 
93 template<class Scalar>
95 {
96  using Teuchos::tuple; using Teuchos::null;
97  RTOpPack::TOpAssignScalar<Scalar> assign_scalar_op(alpha);
98  Thyra::applyOp<Scalar>(assign_scalar_op,
100  tuple<Ptr<MultiVectorBase<Scalar> > >(ptr(this)), null);
101 }
102 
103 template<class Scalar>
105 {
106  using Teuchos::tuple; using Teuchos::ptrInArg; using Teuchos::null;
107  RTOpPack::TOpAssignVectors<Scalar> assign_vectors_op;
108  Thyra::applyOp<Scalar>(assign_vectors_op, tuple(ptrInArg(mv)),
109  tuple<Ptr<MultiVectorBase<Scalar> > >(ptr(this)), null);
110 }
111 
112 
113 template<class Scalar>
115 {
116  using Teuchos::tuple; using Teuchos::null;
117  typedef ScalarTraits<Scalar> ST;
118  if (alpha==ST::zero()) {
119  this->assign(ST::zero());
120  //assign(tuple<Ptr<MultiVectorBase<Scalar> > >(ptr(this)), ST::zero());
121  return;
122  }
123  if (alpha==ST::one()) {
124  return;
125  }
126  RTOpPack::TOpScaleVector<Scalar> scale_vector_op(alpha);
127  Thyra::applyOp<Scalar>(scale_vector_op,
129  tuple<Ptr<MultiVectorBase<Scalar> > >(ptr(this)), null );
130 }
131 
132 
133 template<class Scalar>
135  Scalar alpha,
136  const MultiVectorBase<Scalar>& mv
137  )
138 {
139  using Teuchos::tuple; using Teuchos::ptrInArg; using Teuchos::null;
140  RTOpPack::TOpAXPY<Scalar> axpy_op(alpha);
141  Thyra::applyOp<Scalar>( axpy_op, tuple(ptrInArg(mv)),
142  tuple<Ptr<MultiVectorBase<Scalar> > >(ptr(this)), null );
143 }
144 
145 
146 template<class Scalar>
148  const ArrayView<const Scalar>& alpha,
149  const ArrayView<const Ptr<const MultiVectorBase<Scalar> > >& mv,
150  const Scalar& beta
151  )
152 {
153  using Teuchos::tuple; using Teuchos::null;
154 #ifdef TEUCHOS_DEBUG
155  TEUCHOS_ASSERT_EQUALITY(alpha.size(), mv.size());
156 #endif
157  const int m = alpha.size();
158  if ( beta == ScalarTraits<Scalar>::one() && m == 1 ) {
159  this->update(alpha[0], *mv[0]);
160  return;
161  }
162  else if (m == 0) {
163  this->scale(beta);
164  return;
165  }
166  RTOpPack::TOpLinearCombination<Scalar> lin_comb_op(alpha, beta);
167  Thyra::applyOp<Scalar>(lin_comb_op, mv,
168  tuple<Ptr<MultiVectorBase<Scalar> > >(ptr(this)), null );
169 }
170 
171 
172 template<class Scalar>
174  const ArrayView<typename ScalarTraits<Scalar>::magnitudeType>& norms
175  ) const
176 {
177  using Teuchos::tuple; using Teuchos::ptrInArg; using Teuchos::null;
178  const int m = this->domain()->dim();
179  RTOpPack::ROpNorm1<Scalar> norm_op;
180  Array<RCP<RTOpPack::ReductTarget> > rcp_op_targs(m);
181  Array<Ptr<RTOpPack::ReductTarget> > op_targs(m);
182  for(int kc = 0; kc < m; ++kc) {
183  rcp_op_targs[kc] = norm_op.reduct_obj_create();
184  op_targs[kc] = rcp_op_targs[kc].ptr();
185  }
186  Thyra::applyOp<Scalar>(norm_op,
187  tuple<Ptr<const MultiVectorBase<Scalar> > >(ptrInArg(*this)),
189  op_targs);
190  for(int kc = 0; kc < m; ++kc) {
191  norms[kc] = norm_op(*op_targs[kc]);
192  }
193 }
194 
195 
196 template<class Scalar>
198  const ArrayView<typename ScalarTraits<Scalar>::magnitudeType>& norms
199  ) const
200 {
201  using Teuchos::tuple; using Teuchos::ptrInArg; using Teuchos::null;
202  const int m = this->domain()->dim();
204  Array<RCP<RTOpPack::ReductTarget> > rcp_op_targs(m);
205  Array<Ptr<RTOpPack::ReductTarget> > op_targs(m);
206  for(int kc = 0; kc < m; ++kc) {
207  rcp_op_targs[kc] = norm_op.reduct_obj_create();
208  op_targs[kc] = rcp_op_targs[kc].ptr();
209  }
210  Thyra::applyOp<Scalar>(norm_op,
211  tuple<Ptr<const MultiVectorBase<Scalar> > >(ptrInArg(*this)),
213  op_targs);
214  for(int kc = 0; kc < m; ++kc) {
215  norms[kc] = norm_op(*op_targs[kc]);
216  }
217 }
218 
219 
220 template<class Scalar>
222  const MultiVectorBase<Scalar>& mv,
223  const ArrayView<Scalar>& prods
224  ) const
225 {
226  using Teuchos::tuple; using Teuchos::ptrInArg; using Teuchos::null;
227  const int m = this->domain()->dim();
228  RTOpPack::ROpDotProd<Scalar> dot_op;
229  Array<RCP<RTOpPack::ReductTarget> > rcp_dot_targs(m);
230  Array<Ptr<RTOpPack::ReductTarget> > dot_targs(m);
231  for( int kc = 0; kc < m; ++kc ) {
232  rcp_dot_targs[kc] = dot_op.reduct_obj_create();
233  dot_targs[kc] = rcp_dot_targs[kc].ptr();
234  }
235  Thyra::applyOp<Scalar>( dot_op,
236  tuple<Ptr<const MultiVectorBase<Scalar> > >(ptrInArg(mv), ptrInArg(*this)),
238  dot_targs );
239  for( int kc = 0; kc < m; ++kc ) {
240  prods[kc] = dot_op(*dot_targs[kc]);
241  }
242 }
243 
244 
245 template<class Scalar>
247  const ArrayView<typename ScalarTraits<Scalar>::magnitudeType>& norms
248  ) const
249 {
250  using Teuchos::tuple; using Teuchos::ptrInArg; using Teuchos::null;
251  const int m = this->domain()->dim();
252  RTOpPack::ROpNormInf<Scalar> norm_op;
253  Array<RCP<RTOpPack::ReductTarget> > rcp_op_targs(m);
254  Array<Ptr<RTOpPack::ReductTarget> > op_targs(m);
255  for(int kc = 0; kc < m; ++kc) {
256  rcp_op_targs[kc] = norm_op.reduct_obj_create();
257  op_targs[kc] = rcp_op_targs[kc].ptr();
258  }
259  Thyra::applyOp<Scalar>(norm_op,
260  tuple<Ptr<const MultiVectorBase<Scalar> > >(ptrInArg(*this)),
262  op_targs);
263  for(int kc = 0; kc < m; ++kc) {
264  norms[kc] = norm_op(*op_targs[kc]);
265  }
266 }
267 
268 
269 template<class Scalar>
272 {
273  using Teuchos::Workspace;
274  using Teuchos::as;
276  const VectorSpaceBase<Scalar> &l_domain = *this->domain();
277  const VectorSpaceBase<Scalar> &l_range = *this->range();
278  const Ordinal dimDomain = l_domain.dim();
279  const Range1D colRng = Teuchos::full_range(colRng_in,0,dimDomain-1);
280  if( colRng.lbound() == 0 && as<Ordinal>(colRng.ubound()) == dimDomain-1 )
281  return Teuchos::rcp(this,false); // Takes all of the columns!
282  if( colRng.size() ) {
283  // We have to create a view of a subset of the columns
284  Workspace< RCP< VectorBase<Scalar> > > col_vecs(wss,colRng.size());
285  for( Ordinal j = colRng.lbound(); j <= colRng.ubound(); ++j )
286  col_vecs[j-colRng.lbound()] = Teuchos::rcp_const_cast<VectorBase<Scalar> >(this->col(j));
287  return Teuchos::rcp(
289  this->range(),l_range.smallVecSpcFcty()->createVecSpc(colRng.size()),col_vecs
290  )
291  );
292  }
293  return Teuchos::null; // There was an empty set in colRng_in!
294 }
295 
296 
297 template<class Scalar>
300 {
301  using Teuchos::Workspace;
302  using Teuchos::as;
304  const VectorSpaceBase<Scalar> &l_domain = *this->domain();
305  const VectorSpaceBase<Scalar> &l_range = *this->range();
306  const Ordinal dimDomain = l_domain.dim();
307  const Range1D colRng = Teuchos::full_range(colRng_in,0,dimDomain-1);
308  if( colRng.lbound() == 0 && as<Ordinal>(colRng.ubound()) == dimDomain-1 )
309  return Teuchos::rcp(this,false); // Takes all of the columns!
310  if( colRng.size() ) {
311  // We have to create a view of a subset of the columns
312  Workspace< RCP< VectorBase<Scalar> > > col_vecs(wss,colRng.size());
313  for( Ordinal j = colRng.lbound(); j <= colRng.ubound(); ++j )
314  col_vecs[j-colRng.lbound()] = this->col(j);
315  return Teuchos::rcp(
317  this->range(),l_range.smallVecSpcFcty()->createVecSpc(colRng.size()),col_vecs
318  )
319  );
320  }
321  return Teuchos::null; // There was an empty set in colRng_in!
322 }
323 
324 
325 template<class Scalar>
328  const ArrayView<const int> &cols
329  ) const
330 {
331  using Teuchos::Workspace;
333  const VectorSpaceBase<Scalar> &l_range = *this->range();
334  const int numCols = cols.size();
335 #ifdef TEUCHOS_DEBUG
336  const VectorSpaceBase<Scalar> &l_domain = *this->domain();
337  const Ordinal dimDomain = l_domain.dim();
338  const char msg_err[] = "MultiVectorDefaultBase<Scalar>::subView(numCols,cols[]): Error!";
339  TEUCHOS_TEST_FOR_EXCEPTION( numCols < 1 || dimDomain < numCols, std::invalid_argument, msg_err );
340 #endif
341  // We have to create a view of a subset of the columns
342  Workspace< RCP< VectorBase<Scalar> > > col_vecs(wss,numCols);
343  for( int k = 0; k < numCols; ++k ) {
344  const int col_k = cols[k];
345 #ifdef TEUCHOS_DEBUG
347  !( 0 <= col_k && col_k < dimDomain ), std::invalid_argument
348  ,msg_err << " col["<<k<<"] = " << col_k << " is not in the range [0,"<<(dimDomain-1)<<"]!"
349  );
350 #endif
351  col_vecs[k] = Teuchos::rcp_const_cast<VectorBase<Scalar> >(this->col(col_k));
352  }
353  return Teuchos::rcp(
355  this->range(), l_range.smallVecSpcFcty()->createVecSpc(numCols), col_vecs
356  )
357  );
358 }
359 
360 
361 template<class Scalar>
364  const ArrayView<const int> &cols
365  )
366 {
367  using Teuchos::Workspace;
369  const VectorSpaceBase<Scalar> &l_range = *this->range();
370  const int numCols = cols.size();
371 #ifdef TEUCHOS_DEBUG
372  const VectorSpaceBase<Scalar> &l_domain = *this->domain();
373  const Ordinal dimDomain = l_domain.dim();
374  const char msg_err[] = "MultiVectorDefaultBase<Scalar>::subView(numCols,cols[]): Error!";
375  TEUCHOS_TEST_FOR_EXCEPTION( numCols < 1 || dimDomain < numCols, std::invalid_argument, msg_err );
376 #endif
377  // We have to create a view of a subset of the columns
378  Workspace< RCP< VectorBase<Scalar> > > col_vecs(wss,numCols);
379  for( int k = 0; k < numCols; ++k ) {
380  const int col_k = cols[k];
381 #ifdef TEUCHOS_DEBUG
383  !( 0 <= col_k && col_k < dimDomain ), std::invalid_argument
384  ,msg_err << " col["<<k<<"] = " << col_k << " is not in the range [0,"<<(dimDomain-1)<<"]!"
385  );
386 #endif
387  col_vecs[k] = this->col(col_k);
388  }
389  return Teuchos::rcp(
391  this->range(), l_range.smallVecSpcFcty()->createVecSpc(numCols), col_vecs
392  )
393  );
394 }
395 
396 
397 template<class Scalar>
399  const RTOpPack::RTOpT<Scalar> &prim_op,
400  const ArrayView<const Ptr<const MultiVectorBase<Scalar> > > &multi_vecs,
401  const ArrayView<const Ptr<MultiVectorBase<Scalar> > > &targ_multi_vecs,
402  const ArrayView<const Ptr<RTOpPack::ReductTarget> > &reduct_objs,
403  const Ordinal prim_global_offset_in
404  ) const
405 {
406 
407  using Teuchos::Workspace;
408  using Teuchos::as;
410 
411  const int num_multi_vecs = multi_vecs.size();
412  const int num_targ_multi_vecs = targ_multi_vecs.size();
413 
414  // ToDo: Validate the input!
415 
416  const VectorSpaceBase<Scalar> &l_domain = *this->domain();
417 
418  // Get the primary and secondary dimensions.
419 
420  const Ordinal sec_dim = l_domain.dim();
421 
422  //
423  // Apply the reduction/transformation operator and transform the
424  // target vectors and reduce each of the reduction objects.
425  //
426 
427  Workspace<RCP<const VectorBase<Scalar> > > vecs_s(wss, num_multi_vecs);
428  Workspace<Ptr<const VectorBase<Scalar> > > vecs(wss, num_multi_vecs);
429  Workspace<RCP<VectorBase<Scalar> > > targ_vecs_s(wss, num_targ_multi_vecs);
430  Workspace<Ptr<VectorBase<Scalar> > > targ_vecs(wss, num_targ_multi_vecs);
431 
432  for(Ordinal j = 0; j < sec_dim; ++j) {
433  // Fill the arrays of vector arguments
434  {for(Ordinal k = 0; k < as<Ordinal>(num_multi_vecs); ++k) {
435  vecs_s[k] = multi_vecs[k]->col(j);
436  vecs[k] = vecs_s[k].ptr();
437  }}
438  {for(Ordinal k = 0; k < as<Ordinal>(num_targ_multi_vecs); ++k) {
439  targ_vecs_s[k] = targ_multi_vecs[k]->col(j);
440  targ_vecs[k] = targ_vecs_s[k].ptr();
441  }}
442  // Apply the reduction/transformation operator
443  Thyra::applyOp(
444  prim_op,
445  vecs().getConst(),
446  targ_vecs().getConst(),
447  reduct_objs.size() ? reduct_objs[j] : Ptr<RTOpPack::ReductTarget>(),
448  prim_global_offset_in);
449  }
450  // At this point all of the designated targ vectors in the target multi-vectors have
451  // been transformed and all the reduction objects in reduct_obj[] have accumulated
452  // the reductions.
453 }
454 
455 
456 template<class Scalar>
458  const RTOpPack::RTOpT<Scalar> &prim_op,
459  const RTOpPack::RTOpT<Scalar> &sec_op,
460  const ArrayView<const Ptr<const MultiVectorBase<Scalar> > > &multi_vecs,
461  const ArrayView<const Ptr<MultiVectorBase<Scalar> > > &targ_multi_vecs,
462  const Ptr<RTOpPack::ReductTarget> &reduct_obj,
463  const Ordinal prim_global_offset_in
464  ) const
465 {
466 
467  using Teuchos::Workspace;
469 
470  // ToDo: Validate the input!
471 
472  const VectorSpaceBase<Scalar> &l_domain = *this->domain();
473 
474  // Get the primary and secondary dimensions.
475  const Ordinal sec_dim = l_domain.dim();
476 
477  // Create a temporary buffer for the reduction objects of the primary reduction
478  // so that we can call the companion version of this method.
479  const int reduct_objs_size = (!is_null(reduct_obj) ? sec_dim : 0);
480  Workspace<RCP<RTOpPack::ReductTarget> > rcp_reduct_objs(wss, reduct_objs_size);
481  Workspace<Ptr<RTOpPack::ReductTarget> > reduct_objs(wss, reduct_objs_size);
482  if (!is_null(reduct_obj)) {
483  for(Ordinal k = 0; k < sec_dim; ++k) {
484  rcp_reduct_objs[k] = prim_op.reduct_obj_create();
485  reduct_objs[k] = rcp_reduct_objs[k].ptr();
486  }
487  }
488 
489  // Call the companion version that accepts an array of reduction objects
490  this->applyOp(
491  prim_op, multi_vecs, targ_multi_vecs, reduct_objs,
492  prim_global_offset_in);
493 
494  // Reduce all the reduction objects using the secondary reduction operator
495  // into one reduction object and free the intermediate reduction objects.
496  if (!is_null(reduct_obj)) {
497  for (Ordinal k = 0; k < sec_dim; ++k) {
498  sec_op.reduce_reduct_objs( *reduct_objs[k], reduct_obj );
499  }
500  }
501 }
502 
503 
504 template<class Scalar>
506  const Range1D &rowRng_in,
507  const Range1D &colRng_in,
509  ) const
510 {
511  const Ordinal
512  rangeDim = this->range()->dim(),
513  domainDim = this->domain()->dim();
514  const Range1D
515  rowRng = rowRng_in.full_range() ? Range1D(0,rangeDim-1) : rowRng_in,
516  colRng = colRng_in.full_range() ? Range1D(0,domainDim-1) : colRng_in;
517 #ifdef TEUCHOS_DEBUG
519  !(rowRng.ubound() < rangeDim), std::out_of_range
520  ,"MultiVectorDefaultBase<Scalar>::acquireDetachedMultiVectorViewImpl(...): Error, rowRng = ["
521  <<rowRng.lbound()<<","<<rowRng.ubound()<<"] is not in the range = [0,"
522  <<(rangeDim-1)<<"]!"
523  );
525  !(colRng.ubound() < domainDim), std::out_of_range
526  ,"MultiVectorDefaultBase<Scalar>::acquireDetachedMultiVectorViewImpl(...): Error, colRng = ["
527  <<colRng.lbound()<<","<<colRng.ubound()<<"] is not in the range = [0,"
528  <<(domainDim-1)<<"]!"
529  );
530 #endif
531  // Allocate storage for the multi-vector (stored column-major)
532  const ArrayRCP<Scalar> values = Teuchos::arcp<Scalar>(rowRng.size() * colRng.size());
533  // Extract multi-vector values column by column
534  RTOpPack::ConstSubVectorView<Scalar> sv; // uninitialized by default
535  for( int k = colRng.lbound(); k <= colRng.ubound(); ++k ) {
536  RCP<const VectorBase<Scalar> > col_k = this->col(k);
537  col_k->acquireDetachedView( rowRng, &sv );
538  for( int i = 0; i < rowRng.size(); ++i )
539  values[ i + k*rowRng.size() ] = sv[i];
540  col_k->releaseDetachedView( &sv );
541  }
542  // Initialize the multi-vector view object
543  sub_mv->initialize(
544  rowRng.lbound(), // globalOffset
545  rowRng.size(), // subDim
546  colRng.lbound(), // colOffset
547  colRng.size(), // numSubCols
548  values, // values
549  rowRng.size() // leadingDim
550  );
551 }
552 
553 
554 template<class Scalar>
557  ) const
558 {
559  // Here we just need to free the view and that is it!
560  sub_mv->uninitialize();
561 }
562 
563 
564 template<class Scalar>
566  const Range1D &rowRng,
567  const Range1D &colRng,
569  )
570 {
571  using Teuchos::as;
572  // Use the non-const implementation since it does exactly the
573  // correct thing in this case also!
575  rowRng, colRng,
577  // This cast will work as long as SubMultiVectorView
578  // maintains no extra state over ConstSubMultiVectorView (which it
579  // currently does not) but this is something that I should
580  // technically check for some how.
581  );
582 }
583 
584 
585 template<class Scalar>
588  )
589 {
590 #ifdef TEUCHOS_DEBUG
592  sub_mv==NULL, std::logic_error,
593  "MultiVectorDefaultBase<Scalar>::commitNonconstDetachedMultiVectorViewImpl(...): Error!"
594  );
595 #endif
596  // Set back the multi-vector values column by column
597  const Range1D rowRng(sub_mv->globalOffset(),sub_mv->globalOffset()+sub_mv->subDim()-1);
598  RTOpPack::SubVectorView<Scalar> msv; // uninitialized by default
599  for( int k = sub_mv->colOffset(); k < sub_mv->numSubCols(); ++k ) {
600  RCP<VectorBase<Scalar> > col_k = this->col(k);
601  col_k->acquireDetachedView( rowRng, &msv );
602  for( int i = 0; i < rowRng.size(); ++i )
603  msv[i] = sub_mv->values()[ i + k*rowRng.size() ];
604  col_k->commitDetachedView( &msv );
605  }
606  // Zero out the view
607  sub_mv->uninitialize();
608 }
609 
610 
611 } // end namespace Thyra
612 
613 
614 #endif // THYRA_MULTI_VECTOR_DEFAULT_BASE_DEF_HPP
virtual RCP< MultiVectorBase< Scalar > > clone_mv() const
RCP< MultiVectorBase< Scalar > > nonconstContigSubViewImpl(const Range1D &colRng)
bool is_null(const boost::shared_ptr< T > &p)
virtual void releaseDetachedMultiVectorViewImpl(RTOpPack::ConstSubMultiVectorView< Scalar > *sub_mv) const
virtual void acquireNonconstDetachedMultiVectorViewImpl(const Range1D &rowRng, const Range1D &colRng, RTOpPack::SubMultiVectorView< Scalar > *sub_mv)
virtual void assignMultiVecImpl(const MultiVectorBase< Scalar > &mv)
Default implementation of assign(MV) using RTOps.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
RCP< const MultiVectorBase< Scalar > > contigSubViewImpl(const Range1D &colRng) const
size_type size() const
virtual void mvMultiReductApplyOpImpl(const RTOpPack::RTOpT< Scalar > &primary_op, const ArrayView< const Ptr< const MultiVectorBase< Scalar > > > &multi_vecs, const ArrayView< const Ptr< MultiVectorBase< Scalar > > > &targ_multi_vecs, const ArrayView< const Ptr< RTOpPack::ReductTarget > > &reduct_objs, const Ordinal primary_global_offset) const
virtual void linearCombinationImpl(const ArrayView< const Scalar > &alpha, const ArrayView< const Ptr< const MultiVectorBase< Scalar > > > &mv, const Scalar &beta)
Default implementation of linear_combination using RTOps.
const ArrayRCP< Scalar > values() const
Abstract interface for objects that represent a space for vectors.
virtual void assignImpl(Scalar alpha)
Default implementation of assign(scalar) using RTOps.
Ordinal ubound() const
bool full_range() const
RCP< const MultiVectorBase< Scalar > > nonContigSubViewImpl(const ArrayView< const int > &cols) const
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Teuchos::Ordinal Ordinal
Type for the dimension of a vector space. `*.
Interface for a collection of column vectors called a multi-vector.
virtual void mvSingleReductApplyOpImpl(const RTOpPack::RTOpT< Scalar > &primary_op, const RTOpPack::RTOpT< Scalar > &secondary_op, const ArrayView< const Ptr< const MultiVectorBase< Scalar > > > &multi_vecs, const ArrayView< const Ptr< MultiVectorBase< Scalar > > > &targ_multi_vecs, const Ptr< RTOpPack::ReductTarget > &reduct_obj, const Ordinal primary_global_offset) const
Ptr< T > ptr() const
virtual RCP< const VectorSpaceFactoryBase< Scalar > > smallVecSpcFcty() const =0
Return a VectorSpaceFactoryBase object for the creation of (usually serial) vector spaces with a smal...
Abstract interface for finite-dimensional dense vectors.
Default subclass for MultiVectorBase implemented using columns of separate abstract vectors...
virtual void commitNonconstDetachedMultiVectorViewImpl(RTOpPack::SubMultiVectorView< Scalar > *sub_mv)
virtual void norms1Impl(const ArrayView< typename ScalarTraits< Scalar >::magnitudeType > &norms) const
Default implementation of norms_1 using RTOps.
void reduce_reduct_objs(const ReductTarget &in_reduct_obj, const Ptr< ReductTarget > &inout_reduct_obj) const
RCP< MultiVectorBase< Scalar > > nonconstNonContigSubViewImpl(const ArrayView< const int > &cols)
Teuchos::RCP< ReductTarget > reduct_obj_create() const
Ordinal lbound() const
virtual void scaleImpl(Scalar alpha)
Default implementation of scale using RTOps.
Ordinal size() const
TypeTo as(const TypeFrom &t)
void initialize(Ordinal globalOffset_in, Ordinal subDim_in, Ordinal colOffset_in, Ordinal numSubCols_in, const ArrayRCP< const Scalar > &values_in, Ordinal leadingDim_in)
virtual void acquireDetachedMultiVectorViewImpl(const Range1D &rowRng, const Range1D &colRng, RTOpPack::ConstSubMultiVectorView< Scalar > *sub_mv) const
#define TEUCHOS_ASSERT_EQUALITY(val1, val2)
const T & getConst(T &t)
virtual void norms2Impl(const ArrayView< typename ScalarTraits< Scalar >::magnitudeType > &norms) const
Default implementation of norms_2 using RTOps.
virtual Ordinal dim() const =0
Return the dimension of the vector space.
virtual void dotsImpl(const MultiVectorBase< Scalar > &mv, const ArrayView< Scalar > &prods) const
Default implementation of dots using RTOps.
TEUCHOSCORE_LIB_DLL_EXPORT Teuchos::RCP< WorkspaceStore > get_default_workspace_store()
virtual void normsInfImpl(const ArrayView< typename ScalarTraits< Scalar >::magnitudeType > &norms) const
Default implementation of norms_inf using RTOps.
virtual void updateImpl(Scalar alpha, const MultiVectorBase< Scalar > &mv)
Default implementation of update using RTOps.
Teuchos::Range1D Range1D