Thyra  Version of the Day
Thyra_VectorStdOps_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_VECTOR_STD_OPS_HPP
43 #define THYRA_VECTOR_STD_OPS_HPP
44 
45 #include "Thyra_VectorStdOps_decl.hpp"
46 #include "Thyra_VectorSpaceBase.hpp"
47 #include "Thyra_VectorBase.hpp"
48 #include "RTOpPack_ROpDotProd.hpp"
49 #include "RTOpPack_ROpGetElement.hpp"
50 #include "RTOpPack_TOpSetElement.hpp"
51 #include "RTOpPack_ROpMin.hpp"
52 #include "RTOpPack_ROpMinIndex.hpp"
53 #include "RTOpPack_ROpMinIndexGreaterThanBound.hpp"
54 #include "RTOpPack_ROpMax.hpp"
55 #include "RTOpPack_ROpMaxIndex.hpp"
56 #include "RTOpPack_ROpMaxIndexLessThanBound.hpp"
57 #include "RTOpPack_ROpNorm1.hpp"
58 #include "RTOpPack_ROpNorm2.hpp"
59 #include "RTOpPack_ROpNormInf.hpp"
60 #include "RTOpPack_ROpSum.hpp"
61 #include "RTOpPack_ROpWeightedNorm2.hpp"
62 #include "RTOpPack_TOpAbs.hpp"
63 #include "RTOpPack_TOpAddScalar.hpp"
64 #include "RTOpPack_TOpAssignVectors.hpp"
65 #include "RTOpPack_TOpAXPY.hpp"
66 #include "RTOpPack_TOpEleWiseDivide.hpp"
67 #include "RTOpPack_TOpEleWiseProd.hpp"
68 #include "RTOpPack_TOpEleWiseConjProd.hpp"
69 #include "RTOpPack_TOpEleWiseProdUpdate.hpp"
70 #include "RTOpPack_TOpEleWiseScale.hpp"
71 #include "RTOpPack_TOpLinearCombination.hpp"
72 #include "RTOpPack_TOpScaleVector.hpp"
73 #include "RTOpPack_TOpReciprocal.hpp"
74 #include "RTOpPack_TOpRandomize.hpp"
75 #include "Teuchos_Assert.hpp"
76 #include "Teuchos_Assert.hpp"
77 
78 
79 //
80 // All scalar types
81 //
82 
83 
84 // Standard text names
85 
86 
87 // Reduction operations
88 
89 
90 template<class Scalar>
91 Scalar Thyra::sum( const VectorBase<Scalar>& v_rhs )
92 {
93  using Teuchos::tuple; using Teuchos::ptrInArg; using Teuchos::null;
94  RTOpPack::ROpSum<Scalar> sum_op;
95  Teuchos::RCP<RTOpPack::ReductTarget> sum_targ = sum_op.reduct_obj_create();
96  applyOp<Scalar>(sum_op,
97  tuple(ptrInArg(v_rhs)),
98  ArrayView<Ptr<VectorBase<Scalar> > >(null),
99  sum_targ.ptr() );
100  return sum_op(*sum_targ);
101 }
102 
103 
104 template<class Scalar>
105 typename Teuchos::ScalarTraits<Scalar>::magnitudeType
106 Thyra::norm_1( const VectorBase<Scalar>& v_rhs )
107 {
108  using Teuchos::tuple; using Teuchos::ptrInArg; using Teuchos::null;
109  RTOpPack::ROpNorm1<Scalar> norm_1_op;
110  Teuchos::RCP<RTOpPack::ReductTarget> norm_1_targ = norm_1_op.reduct_obj_create();
111  applyOp<Scalar>(norm_1_op, tuple(ptrInArg(v_rhs)),
112  ArrayView<Ptr<VectorBase<Scalar> > >(null),
113  norm_1_targ.ptr() );
114  return norm_1_op(*norm_1_targ);
115 }
116 
117 
118 template<class Scalar>
119 typename Teuchos::ScalarTraits<Scalar>::magnitudeType
120 Thyra::norm_2( const VectorBase<Scalar>& v_rhs )
121 {
122  using Teuchos::tuple; using Teuchos::ptrInArg; using Teuchos::null;
123  RTOpPack::ROpNorm2<Scalar> norm_2_op;
124  Teuchos::RCP<RTOpPack::ReductTarget> norm_2_targ = norm_2_op.reduct_obj_create();
125  applyOp<Scalar>(norm_2_op, tuple(ptrInArg(v_rhs)),
126  ArrayView<Ptr<VectorBase<Scalar> > >(null),
127  norm_2_targ.ptr() );
128  return norm_2_op(*norm_2_targ);
129 }
130 
131 
132 template<class Scalar>
133 typename Teuchos::ScalarTraits<Scalar>::magnitudeType
134 Thyra::norm_2( const VectorBase<Scalar>& w, const VectorBase<Scalar>& v )
135 {
136  using Teuchos::tuple; using Teuchos::ptrInArg; using Teuchos::null;
137  RTOpPack::ROpWeightedNorm2<Scalar> wght_norm_2_op;
138  Teuchos::RCP<RTOpPack::ReductTarget> wght_norm_2_targ = wght_norm_2_op.reduct_obj_create();
139  applyOp<Scalar>(wght_norm_2_op, tuple(ptrInArg(w), ptrInArg(v)),
140  ArrayView<const Ptr<VectorBase<Scalar> > >(null),
141  wght_norm_2_targ.ptr());
142  return wght_norm_2_op(*wght_norm_2_targ);
143 }
144 
145 
146 template<class Scalar>
147 typename Teuchos::ScalarTraits<Scalar>::magnitudeType
148 Thyra::norm_inf( const VectorBase<Scalar>& v_rhs )
149 {
150  using Teuchos::tuple; using Teuchos::ptrInArg; using Teuchos::null;
151  RTOpPack::ROpNormInf<Scalar> norm_inf_op;
152  Teuchos::RCP<RTOpPack::ReductTarget> norm_inf_targ = norm_inf_op.reduct_obj_create();
153  applyOp<Scalar>(norm_inf_op, tuple(ptrInArg(v_rhs)),
154  ArrayView<Ptr<VectorBase<Scalar> > >(null),
155  norm_inf_targ.ptr() );
156  return norm_inf_op(*norm_inf_targ);
157 }
158 
159 
160 template<class Scalar>
161 Scalar Thyra::dot( const VectorBase<Scalar>& v_rhs1, const VectorBase<Scalar>& v_rhs2 )
162 {
163  using Teuchos::tuple; using Teuchos::ptrInArg; using Teuchos::null;
164  RTOpPack::ROpDotProd<Scalar> dot_prod_op;
165  Teuchos::RCP<RTOpPack::ReductTarget>
166  dot_prod_targ = dot_prod_op.reduct_obj_create();
167  applyOp<Scalar>(dot_prod_op,
168  tuple(ptrInArg(v_rhs1), ptrInArg(v_rhs2))(),
169  ArrayView<Ptr<VectorBase<Scalar> > >(null),
170  dot_prod_targ.ptr()
171  );
172  return dot_prod_op(*dot_prod_targ);
173 }
174 
175 
176 template<class Scalar>
177 Scalar Thyra::get_ele( const VectorBase<Scalar>& v, Ordinal i )
178 {
179  using Teuchos::tuple; using Teuchos::ptrInArg; using Teuchos::null;
180 #ifdef THYRA_DEBUG
181  TEUCHOS_ASSERT_IN_RANGE_UPPER_EXCLUSIVE(i, 0, v.space()->dim());
182 #endif
183  RTOpPack::ROpGetElement<Scalar> get_ele_op(i);
184  Teuchos::RCP<RTOpPack::ReductTarget> get_ele_targ = get_ele_op.reduct_obj_create();
185  applyOp<Scalar>(get_ele_op, tuple(ptrInArg(v)),
186  ArrayView<Ptr<VectorBase<Scalar> > >(null),
187  get_ele_targ.ptr() );
188  return get_ele_op(*get_ele_targ);
189 }
190 
191 
192 // Transformation operations
193 
194 
195 template<class Scalar>
196 void Thyra::set_ele( Ordinal i, Scalar alpha, const Ptr<VectorBase<Scalar> > &v )
197 {
198  using Teuchos::tuple; using Teuchos::null;
199 #ifdef THYRA_DEBUG
200  TEUCHOS_ASSERT_IN_RANGE_UPPER_EXCLUSIVE(i, 0, v->space()->dim());
201 #endif
202  RTOpPack::TOpSetElement<Scalar> set_ele_op(i, alpha);
203  applyOp<Scalar>(set_ele_op,
204  ArrayView<Ptr<const VectorBase<Scalar> > >(null),
205  tuple(v),
206  null);
207 }
208 
209 
210 template<class Scalar>
211 void Thyra::put_scalar( const Scalar& alpha, const Ptr<VectorBase<Scalar> > &v_lhs )
212 {
213  v_lhs->assign(alpha);
214 }
215 
216 
217 template<class Scalar>
218 void Thyra::copy( const VectorBase<Scalar>& v_rhs,
219  const Ptr<VectorBase<Scalar> > &v_lhs )
220 {
221  using Teuchos::tuple; using Teuchos::ptrInArg; using Teuchos::null;
222  RTOpPack::TOpAssignVectors<Scalar> assign_vectors_op;
223  applyOp<Scalar>( assign_vectors_op, tuple(ptrInArg(v_rhs)), tuple(v_lhs), null );
224 }
225 
226 
227 template<class Scalar>
228 void Thyra::add_scalar( const Scalar& alpha, const Ptr<VectorBase<Scalar> > &v_lhs )
229 {
230  using Teuchos::tuple; using Teuchos::null;
231  RTOpPack::TOpAddScalar<Scalar> add_scalar_op(alpha);
232  applyOp<Scalar>(add_scalar_op,
233  ArrayView<Ptr<const VectorBase<Scalar> > >(null),
234  tuple(v_lhs), null );
235 }
236 
237 
238 template<class Scalar>
239 void Thyra::scale( const Scalar& alpha, const Ptr<VectorBase<Scalar> > &v_lhs )
240 {
241  using Teuchos::tuple; using Teuchos::null;
242  if( alpha == ScalarTraits<Scalar>::zero() ) {
243  assign(v_lhs, ScalarTraits<Scalar>::zero());
244  }
245  else if( alpha != ScalarTraits<Scalar>::one() ) {
246  RTOpPack::TOpScaleVector<Scalar> scale_vector_op(alpha);
247  applyOp<Scalar>(scale_vector_op,
248  ArrayView<Ptr<const VectorBase<Scalar> > >(null),
249  tuple(v_lhs), null );
250  }
251 }
252 
253 
254 template<class Scalar>
255 void Thyra::abs( const VectorBase<Scalar>& x, const Ptr<VectorBase<Scalar> > &y )
256 {
257  using Teuchos::tuple; using Teuchos::ptrInArg; using Teuchos::null;
258  RTOpPack::TOpAbs<Scalar> abs_op;
259  applyOp<Scalar>( abs_op, tuple(ptrInArg(x)), tuple(y), null );
260 }
261 
262 
263 template<class Scalar>
264 void Thyra::reciprocal( const VectorBase<Scalar>& x, const Ptr<VectorBase<Scalar> > &y )
265 {
266  using Teuchos::tuple; using Teuchos::ptrInArg; using Teuchos::null;
267  RTOpPack::TOpReciprocal<Scalar> recip_op;
268  applyOp<Scalar>( recip_op, tuple(ptrInArg(x)), tuple(y), null );
269 }
270 
271 
272 template<class Scalar>
273 void Thyra::ele_wise_prod(
274  const Scalar& alpha, const VectorBase<Scalar>& v_rhs1,
275  const VectorBase<Scalar>& v_rhs2, const Ptr<VectorBase<Scalar> > &v_lhs
276  )
277 {
278  using Teuchos::tuple; using Teuchos::ptrInArg; using Teuchos::null;
279  RTOpPack::TOpEleWiseProd<Scalar> ele_wise_prod_op(alpha);
280  applyOp<Scalar>( ele_wise_prod_op, tuple(ptrInArg(v_rhs1),ptrInArg(v_rhs2)),
281  tuple(v_lhs), null );
282 }
283 
284 
285 template<class Scalar>
286 void Thyra::ele_wise_conj_prod(
287  const Scalar& alpha, const VectorBase<Scalar>& v_rhs1,
288  const VectorBase<Scalar>& v_rhs2, const Ptr<VectorBase<Scalar> > &v_lhs
289  )
290 {
291  using Teuchos::tuple; using Teuchos::ptrInArg; using Teuchos::null;
292  RTOpPack::TOpEleWiseConjProd<Scalar> ele_wise_conj_prod_op(alpha);
293  applyOp<Scalar>( ele_wise_conj_prod_op, tuple(ptrInArg(v_rhs1),ptrInArg(v_rhs2)),
294  tuple(v_lhs), null );
295 }
296 
297 
298 template<class Scalar>
299 void Thyra::ele_wise_scale( const VectorBase<Scalar>& x,
300  const Ptr<VectorBase<Scalar> > &y )
301 {
302  using Teuchos::tuple; using Teuchos::ptrInArg; using Teuchos::null;
304  applyOp<Scalar>( ele_wise_scale, tuple(ptrInArg(x)), tuple(y), null );
305 }
306 
307 
308 template<class Scalar>
309 void Thyra::Vp_StVtV(
310  const Ptr<VectorBase<Scalar> > &v_lhs,
311  const Scalar& alpha, const VectorBase<Scalar>& v_rhs1,
312  const VectorBase<Scalar>& v_rhs2
313  )
314 {
315  ele_wise_prod(alpha,v_rhs1,v_rhs2,v_lhs);
316 }
317 
318 
319 template<class Scalar>
320 void Thyra::ele_wise_prod_update(
321  const Scalar& alpha, const VectorBase<Scalar>& v_rhs1,
322  const Ptr<VectorBase<Scalar> > &v_lhs
323  )
324 {
325  using Teuchos::tuple; using Teuchos::ptrInArg; using Teuchos::null;
326  RTOpPack::TOpEleWiseProdUpdate<Scalar> ele_wise_prod_update_op(alpha);
327  applyOp<Scalar>( ele_wise_prod_update_op, tuple(ptrInArg(v_rhs1)),
328  tuple(v_lhs), null );
329 }
330 
331 
332 template<class Scalar>
333 void Thyra::Vt_StV(
334  const Ptr<VectorBase<Scalar> > &v_lhs,
335  const Scalar& alpha, const VectorBase<Scalar>& x )
336 {
337  ele_wise_prod_update(alpha,x,v_lhs);
338 }
339 
340 
341 template<class Scalar>
342 void Thyra::ele_wise_divide(
343  const Scalar& alpha, const VectorBase<Scalar>& v_rhs1,
344  const VectorBase<Scalar>& v_rhs2,
345  const Ptr<VectorBase<Scalar> > &v_lhs
346  )
347 {
348  using Teuchos::tuple; using Teuchos::ptrInArg; using Teuchos::null;
349  RTOpPack::TOpEleWiseDivide<Scalar> ele_wise_divide_op(alpha);
350  applyOp<Scalar>( ele_wise_divide_op, tuple(ptrInArg(v_rhs1),ptrInArg(v_rhs2)),
351  tuple(v_lhs), null );
352 }
353 
354 
355 template<class Scalar>
356 void Thyra::linear_combination(
357  const ArrayView<const Scalar> &alpha,
358  const ArrayView<const Ptr<const VectorBase<Scalar> > > &x,
359  const Scalar &beta,
360  const Ptr<VectorBase<Scalar> > &y
361  )
362 {
363  using Teuchos::tuple; using Teuchos::ptr; using Teuchos::ptrInArg;
364  using Teuchos::null;
365  const int m = x.size();
366  if( beta == Teuchos::ScalarTraits<Scalar>::one() && m == 1 ) {
367  Vp_StV( y, alpha[0], *x[0] );
368  return;
369  }
370  else if( m == 0 ) {
371  Vt_S( y, beta );
372  return;
373  }
374  RTOpPack::TOpLinearCombination<Scalar> lin_comb_op(alpha,beta);
375  applyOp<Scalar>( lin_comb_op, x, tuple(y), null );
376 }
377 
378 
379 template<class Scalar>
380 void Thyra::seed_randomize( unsigned int s )
381 {
383 }
384 
385 
386 template<class Scalar>
387 void Thyra::randomize( Scalar l, Scalar u, const Ptr<VectorBase<Scalar> > &v )
388 {
389  using Teuchos::tuple; using Teuchos::null;
390  RTOpPack::TOpRandomize<Scalar> random_vector_op(l,u);
391  applyOp<Scalar>( random_vector_op,
392  ArrayView<Ptr<const VectorBase<Scalar> > >(null),
393  tuple(v),
394  null );
395  // Warning! If the RTOpPack::TOpRandomize<Scalar> object is ever made
396  // static, the one must be careful to change the seed in between calls.
397  // Right now the seed is being incremented by the constructor automatically.
398  // It is important to generate different random vectors on each call
399  // (i.e. to generate different columns in a multi-vector).
400 }
401 
402 
403 // Linear algebra names
404 
405 
406 template<class Scalar>
407 void Thyra::assign( const Ptr<VectorBase<Scalar> > &v_lhs, const Scalar& alpha )
408 {
409  put_scalar(alpha,v_lhs);
410 }
411 
412 
413 template<class Scalar>
414 void Thyra::assign( const Ptr<VectorBase<Scalar> > &v_lhs, const VectorBase<Scalar>& v_rhs )
415 {
416  copy(v_rhs,v_lhs);
417 }
418 
419 
420 template<class Scalar>
421 void Thyra::Vp_S( const Ptr<VectorBase<Scalar> > &v_lhs, const Scalar& alpha )
422 {
423  add_scalar(alpha,v_lhs);
424 }
425 
426 
427 template<class Scalar>
428 void Thyra::Vt_S( const Ptr<VectorBase<Scalar> > &v_lhs, const Scalar& alpha )
429 {
430  scale(alpha,v_lhs);
431 }
432 
433 
434 template<class Scalar>
435 void Thyra::V_StV( const Ptr<VectorBase<Scalar> > &y, const Scalar& alpha,
436  const VectorBase<Scalar> &x
437  )
438 {
439  using Teuchos::tuple; using Teuchos::ptrInArg;
440  linear_combination<Scalar>( tuple<Scalar>(alpha), tuple(ptrInArg(x)),
441  ScalarTraits<Scalar>::zero(), y );
442 }
443 
444 
445 template<class Scalar>
446 void Thyra::Vp_StV( const Ptr<VectorBase<Scalar> > &v_lhs, const Scalar& alpha,
447  const VectorBase<Scalar>& v_rhs
448  )
449 {
450  using Teuchos::tuple; using Teuchos::ptrInArg; using Teuchos::null;
451  RTOpPack::TOpAXPY<Scalar> axpy_op(alpha);
452  applyOp<Scalar>( axpy_op, tuple(ptrInArg(v_rhs)), tuple(v_lhs), null );
453 }
454 
455 
456 template<class Scalar>
457 void Thyra::Vp_V( const Ptr<VectorBase<Scalar> > &y, const VectorBase<Scalar>& x,
458  const Scalar& beta
459  )
460 {
461  using Teuchos::tuple; using Teuchos::ptrInArg;
462  linear_combination<Scalar>(
463  tuple<Scalar>(Teuchos::ScalarTraits<Scalar>::one()),
464  tuple(ptrInArg(x)),
465  beta, y );
466 }
467 
468 
469 template<class Scalar>
470 void Thyra::V_V( const Ptr<VectorBase<Scalar> > &y, const VectorBase<Scalar>& x )
471 {
472  assign(y,x);
473 }
474 
475 
476 template<class Scalar>
477 void Thyra::V_S( const Ptr<VectorBase<Scalar> > &y, const Scalar& alpha )
478 {
479  assign(y,alpha);
480 }
481 
482 
483 template<class Scalar>
484 void Thyra::V_VpV( const Ptr<VectorBase<Scalar> > &z, const VectorBase<Scalar>& x,
485  const VectorBase<Scalar>& y
486  )
487 {
488  using Teuchos::tuple; using Teuchos::ptrInArg;
489  typedef Teuchos::ScalarTraits<Scalar> ST;
490  linear_combination<Scalar>(
491  tuple(ST::one(),ST::one()),
492  tuple(ptrInArg(x),ptrInArg(y)),
493  ST::zero(), z
494  );
495 }
496 
497 
498 template<class Scalar>
499 void Thyra::V_VmV( const Ptr<VectorBase<Scalar> > &z, const VectorBase<Scalar>& x,
500  const VectorBase<Scalar>& y
501  )
502 {
503  using Teuchos::tuple; using Teuchos::ptrInArg;
504  typedef Teuchos::ScalarTraits<Scalar> ST;
505  linear_combination<Scalar>(
506  tuple(ST::one(),Scalar(-ST::one())),
507  tuple(ptrInArg(x),ptrInArg(y)),
508  ST::zero(), z
509  );
510 }
511 
512 
513 template<class Scalar>
514 void Thyra::V_StVpV( const Ptr<VectorBase<Scalar> > &z, const Scalar &alpha,
515  const VectorBase<Scalar>& x, const VectorBase<Scalar>& y
516  )
517 {
518  using Teuchos::tuple; using Teuchos::ptrInArg;
519  typedef Teuchos::ScalarTraits<Scalar> ST;
520  linear_combination<Scalar>(
521  tuple(alpha, ST::one()), tuple(ptrInArg(x),ptrInArg(y)),
522  ST::zero(), z
523  );
524 }
525 
526 
527 template<class Scalar>
528 void Thyra::V_VpStV( const Ptr<VectorBase<Scalar> > &z,
529  const VectorBase<Scalar>& x,
530  const Scalar &alpha, const VectorBase<Scalar>& y )
531 {
532  using Teuchos::tuple; using Teuchos::ptrInArg;
533  typedef Teuchos::ScalarTraits<Scalar> ST;
534  linear_combination<Scalar>(
535  tuple(ST::one(), alpha), tuple(ptrInArg(x),ptrInArg(y)),
536  ST::zero(), z
537  );
538 }
539 
540 
541 template<class Scalar>
542 void Thyra::V_StVpStV( const Ptr<VectorBase<Scalar> > &z, const Scalar &alpha,
543  const VectorBase<Scalar>& x, const Scalar &beta, const VectorBase<Scalar>& y
544  )
545 {
546  using Teuchos::tuple; using Teuchos::ptrInArg;
547  typedef Teuchos::ScalarTraits<Scalar> ST;
548  linear_combination<Scalar>(
549  tuple(alpha, beta), tuple(ptrInArg(x),ptrInArg(y)),
550  ST::zero(), z
551  );
552 }
553 
554 
555 //
556 // For real types only
557 //
558 
559 
560 template<class Scalar>
561 Scalar Thyra::min( const VectorBase<Scalar>& x ) {
562  using Teuchos::tuple; using Teuchos::ptrInArg; using Teuchos::null;
563  RTOpPack::ROpMin<Scalar> min_op;
564  Teuchos::RCP<RTOpPack::ReductTarget> min_targ = min_op.reduct_obj_create();
565  applyOp<Scalar>( min_op, tuple(ptrInArg(x)),
566  ArrayView<const Ptr<VectorBase<Scalar> > >(null),
567  min_targ.ptr() );
568  return min_op(*min_targ);
569 }
570 
571 
572 template<class Scalar>
573 void Thyra::min( const VectorBase<Scalar>& x,
574  const Ptr<Scalar> &minEle, const Ptr<Ordinal> &minIndex
575  )
576 {
577  using Teuchos::tuple; using Teuchos::ptrInArg; using Teuchos::null;
579  Teuchos::RCP<RTOpPack::ReductTarget> min_targ = min_op.reduct_obj_create();
580  applyOp<Scalar>( min_op, tuple(ptrInArg(x)),
581  ArrayView<const Ptr<VectorBase<Scalar> > >(null),
582  min_targ.ptr() );
583  RTOpPack::ScalarIndex<Scalar> scalarIndex = min_op(*min_targ);
584  *minEle = scalarIndex.scalar;
585  *minIndex = scalarIndex.index;
586 }
587 
588 
589 template<class Scalar>
590 void Thyra::minGreaterThanBound( const VectorBase<Scalar>& x,
591  const Scalar &bound, const Ptr<Scalar> &minEle, const Ptr<Ordinal> &minIndex
592  )
593 {
594  using Teuchos::tuple; using Teuchos::ptrInArg; using Teuchos::null;
596  Teuchos::RCP<RTOpPack::ReductTarget> min_targ = min_op.reduct_obj_create();
597  applyOp<Scalar>( min_op, tuple(ptrInArg(x)),
598  ArrayView<const Ptr<VectorBase<Scalar> > >(null),
599  min_targ.ptr() );
600  RTOpPack::ScalarIndex<Scalar> scalarIndex = min_op(*min_targ);
601  *minEle = scalarIndex.scalar;
602  *minIndex = scalarIndex.index;
603 }
604 
605 
606 template<class Scalar>
607 Scalar Thyra::max( const VectorBase<Scalar>& x )
608 {
609  using Teuchos::tuple; using Teuchos::ptrInArg; using Teuchos::null;
610  RTOpPack::ROpMax<Scalar> max_op;
611  Teuchos::RCP<RTOpPack::ReductTarget> max_targ = max_op.reduct_obj_create();
612  applyOp<Scalar>( max_op, tuple(ptrInArg(x)),
613  ArrayView<const Ptr<VectorBase<Scalar> > >(null),
614  max_targ.ptr() );
615  return max_op(*max_targ);
616 }
617 
618 
619 template<class Scalar>
620 void Thyra::max( const VectorBase<Scalar>& x,
621  const Ptr<Scalar> &maxEle, const Ptr<Ordinal> &maxIndex
622  )
623 {
624  using Teuchos::tuple; using Teuchos::ptrInArg; using Teuchos::null;
626  Teuchos::RCP<RTOpPack::ReductTarget> max_targ = max_op.reduct_obj_create();
627  applyOp<Scalar>( max_op, tuple(ptrInArg(x)),
628  ArrayView<const Ptr<VectorBase<Scalar> > >(null),
629  max_targ.ptr() );
630  RTOpPack::ScalarIndex<Scalar> scalarIndex = max_op(*max_targ);
631  *maxEle = scalarIndex.scalar;
632  *maxIndex = scalarIndex.index;
633 }
634 
635 
636 template<class Scalar>
637 void Thyra::maxLessThanBound( const VectorBase<Scalar>& x,
638  const Scalar &bound, const Ptr<Scalar> &maxEle, const Ptr<Ordinal> &maxIndex
639  )
640 {
641  using Teuchos::tuple; using Teuchos::ptrInArg; using Teuchos::null;
643  Teuchos::RCP<RTOpPack::ReductTarget> max_targ = max_op.reduct_obj_create();
644  applyOp<Scalar>( max_op, tuple(ptrInArg(x)),
645  ArrayView<const Ptr<VectorBase<Scalar> > >(null),
646  max_targ.ptr() );
647  RTOpPack::ScalarIndex<Scalar> scalarIndex = max_op(*max_targ);
648  *maxEle = scalarIndex.scalar;
649  *maxIndex = scalarIndex.index;
650 }
651 
652 
653 //
654 // Explicit instantiation macro
655 //
656 
657 
658 #define THYRA_VECTOR_STD_OPS_INSTANT(SCALAR) \
659  \
660  template SCALAR sum( const VectorBase<SCALAR >& v_rhs ); \
661  \
662  template ScalarTraits<SCALAR >::magnitudeType \
663  norm_1( const VectorBase<SCALAR >& v_rhs ); \
664  \
665  template ScalarTraits<SCALAR >::magnitudeType \
666  norm_2( const VectorBase<SCALAR >& v_rhs ); \
667  \
668  template ScalarTraits<SCALAR >::magnitudeType \
669  norm_2( const VectorBase<SCALAR >& w, const VectorBase<SCALAR >& v ); \
670  \
671  template ScalarTraits<SCALAR >::magnitudeType \
672  norm_inf( const VectorBase<SCALAR >& v_rhs ); \
673  \
674  template SCALAR dot( const VectorBase<SCALAR >& v_rhs1, const VectorBase<SCALAR >& v_rhs2 ); \
675  \
676  template SCALAR get_ele( const VectorBase<SCALAR >& v, Ordinal i ); \
677  \
678  template void set_ele( Ordinal i, SCALAR alpha, const Ptr<VectorBase<SCALAR > > &v ); \
679  \
680  template void put_scalar( const SCALAR& alpha, const Ptr<VectorBase<SCALAR > > &v_lhs ); \
681  \
682  template void copy( const VectorBase<SCALAR >& v_rhs, \
683  const Ptr<VectorBase<SCALAR > > &v_lhs ); \
684  \
685  template void add_scalar( const SCALAR& alpha, const Ptr<VectorBase<SCALAR > > &v_lhs ); \
686  \
687  template void scale( const SCALAR& alpha, const Ptr<VectorBase<SCALAR > > &v_lhs ); \
688  \
689  template void abs( const VectorBase< SCALAR > &x, const Ptr<VectorBase< SCALAR > > &y ); \
690  \
691  template void reciprocal( const VectorBase< SCALAR > &x, const Ptr<VectorBase< SCALAR > > &y ); \
692  \
693  template void ele_wise_prod( \
694  const SCALAR& alpha, const VectorBase<SCALAR >& v_rhs1, \
695  const VectorBase<SCALAR >& v_rhs2, const Ptr<VectorBase<SCALAR > > &v_lhs \
696  ); \
697  \
698  template void ele_wise_conj_prod( \
699  const SCALAR& alpha, const VectorBase<SCALAR >& v_rhs1, \
700  const VectorBase<SCALAR >& v_rhs2, const Ptr<VectorBase<SCALAR > > &v_lhs \
701  ); \
702  \
703  template void ele_wise_scale( const VectorBase<SCALAR>& x, \
704  const Ptr<VectorBase<SCALAR> > &y ); \
705  \
706  template void Vp_StVtV( \
707  const Ptr<VectorBase<SCALAR > > &v_lhs, \
708  const SCALAR& alpha, const VectorBase<SCALAR >& v_rhs1, \
709  const VectorBase<SCALAR >& v_rhs2 \
710  ); \
711  \
712  template void ele_wise_prod_update( \
713  const SCALAR& alpha, const VectorBase<SCALAR >& v_rhs1, \
714  const Ptr<VectorBase<SCALAR > > &v_lhs \
715  ); \
716  \
717  template void Vt_StV( \
718  const Ptr<VectorBase<SCALAR > > &v_lhs, \
719  const SCALAR& alpha, const VectorBase<SCALAR >& x ); \
720  \
721  template void ele_wise_divide( \
722  const SCALAR& alpha, const VectorBase<SCALAR >& v_rhs1, \
723  const VectorBase<SCALAR >& v_rhs2, \
724  const Ptr<VectorBase<SCALAR > > &v_lhs \
725  ); \
726  \
727  template void linear_combination( \
728  const ArrayView<const SCALAR > &alpha, \
729  const ArrayView<const Ptr<const VectorBase<SCALAR > > > &x, \
730  const SCALAR &beta, \
731  const Ptr<VectorBase<SCALAR > > &y \
732  ); \
733  \
734  template void seed_randomize<SCALAR >( unsigned int s ); \
735  \
736  template void randomize( SCALAR l, SCALAR u, const Ptr<VectorBase<SCALAR > > &v ); \
737  \
738  template void assign( const Ptr<VectorBase<SCALAR > > &v_lhs, const SCALAR& alpha ); \
739  \
740  template void assign( const Ptr<VectorBase<SCALAR > > &v_lhs, const VectorBase<SCALAR >& v_rhs ); \
741  \
742  template void Vp_S( const Ptr<VectorBase<SCALAR > > &v_lhs, const SCALAR& alpha ); \
743  \
744  template void Vt_S( const Ptr<VectorBase<SCALAR > > &v_lhs, const SCALAR& alpha ); \
745  \
746  template void V_StV( const Ptr<VectorBase<SCALAR > > &y, const SCALAR& alpha, \
747  const VectorBase<SCALAR > &x \
748  ); \
749  \
750  template void Vp_StV( const Ptr<VectorBase<SCALAR > > &v_lhs, const SCALAR& alpha, \
751  const VectorBase<SCALAR >& v_rhs \
752  ); \
753  \
754  template void Vp_V( const Ptr<VectorBase<SCALAR > > &y, const VectorBase<SCALAR >& x, \
755  const SCALAR& beta \
756  ); \
757  \
758  template void V_V( const Ptr<VectorBase<SCALAR > > &y, const VectorBase<SCALAR >& x ); \
759  \
760  template void V_S( const Ptr<VectorBase<SCALAR > > &y, const SCALAR& alpha ); \
761  \
762  template void V_VpV( const Ptr<VectorBase<SCALAR > > &z, const VectorBase<SCALAR >& x, \
763  const VectorBase<SCALAR >& y \
764  ); \
765  \
766  template void V_VmV( const Ptr<VectorBase<SCALAR > > &z, const VectorBase<SCALAR >& x, \
767  const VectorBase<SCALAR >& y \
768  ); \
769  \
770  template void V_StVpV( const Ptr<VectorBase<SCALAR > > &z, const SCALAR &alpha, \
771  const VectorBase<SCALAR >& x, const VectorBase<SCALAR >& y \
772  ); \
773  \
774  template void V_VpStV( const Ptr<VectorBase<SCALAR > > &z, \
775  const VectorBase<SCALAR >& x, \
776  const SCALAR &alpha, const VectorBase<SCALAR >& y ); \
777  \
778  template void V_StVpStV( const Ptr<VectorBase<SCALAR > > &z, const SCALAR &alpha, \
779  const VectorBase<SCALAR >& x, const SCALAR &beta, const VectorBase<SCALAR >& y \
780  ); \
781 
782 
783 
784 #define THYRA_VECTOR_STD_OPS_REAL_INSTANT(SCALAR) \
785  \
786  template SCALAR min( const VectorBase<SCALAR >& x ); \
787  \
788  template void min( const VectorBase<SCALAR >& x, \
789  const Ptr<SCALAR > &minEle, const Ptr<Ordinal> &minIndex \
790  ); \
791  \
792  template void minGreaterThanBound( const VectorBase<SCALAR >& x, \
793  const SCALAR &bound, const Ptr<SCALAR > &minEle, const Ptr<Ordinal> &minIndex \
794  ); \
795  \
796  template SCALAR max( const VectorBase<SCALAR >& x ); \
797  \
798  template void max( const VectorBase<SCALAR >& x, \
799  const Ptr<SCALAR > &maxEle, const Ptr<Ordinal> &maxIndex \
800  ); \
801  \
802  template void maxLessThanBound( const VectorBase<SCALAR >& x, \
803  const SCALAR &bound, const Ptr<SCALAR > &maxEle, const Ptr<Ordinal> &maxIndex \
804  ); \
805 
806 
807 #endif // THYRA_VECTOR_STD_OPS_HPP
void put_scalar(const Scalar &alpha, const Ptr< VectorBase< Scalar > > &y)
Assign all elements to a scalar: y(i) = alpha, i = 0...y->space()->dim()-1.
void ele_wise_prod_update(const Scalar &alpha, const VectorBase< Scalar > &x, const Ptr< VectorBase< Scalar > > &y)
Element-wise product update: y(i) *= alpha * x(i), i = 0...y->space()->dim()-1.
void assign(const Ptr< MultiVectorBase< Scalar > > &V, Scalar alpha)
V = alpha.
void copy(const VectorBase< Scalar > &x, const Ptr< VectorBase< Scalar > > &y)
Vector assignment: y(i) = x(i), i = 0...y->space()->dim()-1.
RCP< const LinearOpBase< Scalar > > scale(const Scalar &scalar, const RCP< const LinearOpBase< Scalar > > &Op, const std::string &label="")
Build an implicit const scaled linear operator.
Teuchos::Ordinal Ordinal
Type for the dimension of a vector space. `*.
Teuchos::RCP< ReductTarget > reduct_obj_create() const
void ele_wise_scale(const VectorBase< Scalar > &x, const Ptr< VectorBase< Scalar > > &y)
Element-wise scaling: y(i) *= x(i), i = 0...y->space()->dim()-1.
void add_scalar(const Scalar &alpha, const Ptr< VectorBase< Scalar > > &y)
Add a scalar to all elements: y(i) += alpha, i = 0...y->space()->dim()-1.
static void set_static_seed(const unsigned int static_seed)
void ele_wise_prod(const Scalar &alpha, const VectorBase< Scalar > &x, const VectorBase< Scalar > &v, const Ptr< VectorBase< Scalar > > &y)
Element-wise product update: y(i) += alpha * x(i) * v(i), i = 0...y->space()->dim()-1.
void Vp_StV(const Ptr< VectorBase< Scalar > > &y, const Scalar &alpha, const VectorBase< Scalar > &x)
AXPY: y(i) = alpha * x(i) + y(i), i = 0...y->space()->dim()-1.
void Vt_S(const Ptr< MultiVectorBase< Scalar > > &Z, const Scalar &alpha)
Z(i,j) *= alpha, i = 0...Z->range()->dim()-1, j = 0...Z->domain()->dim()-1.