Thyra  Version of the Day
Thyra_VectorStdOps_decl.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 
43 #ifndef THYRA_VECTOR_STD_OPS_DECL_HPP
44 #define THYRA_VECTOR_STD_OPS_DECL_HPP
45 
46 
47 #include "Thyra_OperatorVectorTypes.hpp"
48 
49 
50 namespace Thyra {
51 
52 
58 template<class Scalar>
59 Scalar sum( const VectorBase<Scalar>& v );
60 
61 
68 template<class Scalar>
69 Scalar scalarProd( const VectorBase<Scalar>& x, const VectorBase<Scalar>& y );
70 
71 
78 template<class Scalar>
79 Scalar inner( const VectorBase<Scalar>& x, const VectorBase<Scalar>& y );
80 
81 
89 template<class Scalar>
92 
93 
98 template<class Scalar>
101 
102 
107 template<class Scalar>
110 
111 
117 template<class Scalar>
120 
121 
126 template<class Scalar>
128 norm_inf( const VectorBase<Scalar>& v_rhs );
129 
130 
135 template<class Scalar>
136 Scalar dot( const VectorBase<Scalar>& x, const VectorBase<Scalar>& y );
137 
138 
143 template<class Scalar>
144 Scalar get_ele( const VectorBase<Scalar>& v, Ordinal i );
145 
146 
151 template<class Scalar>
152 void set_ele( Ordinal i, Scalar alpha, const Ptr<VectorBase<Scalar> > &v );
153 
154 
160 template<class Scalar>
161 void put_scalar( const Scalar& alpha, const Ptr<VectorBase<Scalar> > &y );
162 
163 
169 template<class Scalar>
170 void copy( const VectorBase<Scalar>& x, const Ptr<VectorBase<Scalar> > &y );
171 
172 
178 template<class Scalar>
179 void add_scalar( const Scalar& alpha, const Ptr<VectorBase<Scalar> > &y );
180 
181 
191 template<class Scalar>
192 void scale( const Scalar& alpha, const Ptr<VectorBase<Scalar> > &y );
193 
194 
200 template<class Scalar>
201 void abs( const VectorBase<Scalar> &x, const Ptr<VectorBase<Scalar> > &y );
202 
203 
209 template<class Scalar>
211 
212 
218 template<class Scalar>
219 void ele_wise_prod( const Scalar& alpha, const VectorBase<Scalar>& x,
220  const VectorBase<Scalar>& v, const Ptr<VectorBase<Scalar> > &y );
221 
222 
228 template<class Scalar>
229 void pair_wise_max(const Scalar& alpha, const VectorBase<Scalar>& x,
230  const VectorBase<Scalar>& v, const Ptr<VectorBase<Scalar> > &y );
231 
237 template<class Scalar>
238 void ele_wise_conj_prod( const Scalar& alpha, const VectorBase<Scalar>& x,
239  const VectorBase<Scalar>& v, const Ptr<VectorBase<Scalar> > &y );
240 
241 
247 template<class Scalar>
249 
250 
256 template<class Scalar>
257 void Vp_StVtV( const Ptr<VectorBase<Scalar> > &y, const Scalar& alpha,
258  const VectorBase<Scalar>& x, const VectorBase<Scalar>& v);
259 
260 
266 template<class Scalar>
267 void ele_wise_prod_update( const Scalar& alpha, const VectorBase<Scalar>& x,
268  const Ptr<VectorBase<Scalar> > &y );
269 
270 
276 template<class Scalar>
277 void pair_wise_max_update( const Scalar& alpha, const VectorBase<Scalar>& x,
278  const Ptr<VectorBase<Scalar> > &y );
279 
285 template<class Scalar>
286 void Vt_StV( const Ptr<VectorBase<Scalar> > &y, const Scalar& alpha,
287  const VectorBase<Scalar> &x );
288 
289 
295 template<class Scalar>
296 void ele_wise_divide( const Scalar& alpha, const VectorBase<Scalar>& x,
297  const VectorBase<Scalar>& v, const Ptr<VectorBase<Scalar> > &y );
298 
299 
322 template<class Scalar>
324  const ArrayView<const Scalar> &alpha,
325  const ArrayView<const Ptr<const VectorBase<Scalar> > > &x,
326  const Scalar &beta,
327  const Ptr<VectorBase<Scalar> > &y
328  );
329 
330 
340 template<class Scalar>
341 void seed_randomize( unsigned int s );
342 
343 
354 template<class Scalar>
355 void randomize( Scalar l, Scalar u, const Ptr<VectorBase<Scalar> > &v );
356 
357 
363 template<class Scalar>
364 void assign( const Ptr<VectorBase<Scalar> > &y, const Scalar& alpha );
365 
366 
372 template<class Scalar>
373 void assign( const Ptr<VectorBase<Scalar> > &y, const VectorBase<Scalar>& x );
374 
375 
381 template<class Scalar>
382 void Vp_S( const Ptr<VectorBase<Scalar> > &y, const Scalar& alpha );
383 
384 
394 template<class Scalar>
395 void Vt_S( const Ptr<VectorBase<Scalar> > &y, const Scalar& alpha );
396 
397 
403 template<class Scalar>
404 void V_StV( const Ptr<VectorBase<Scalar> > &y, const Scalar& alpha,
405  const VectorBase<Scalar> &x );
406 
407 
413 template<class Scalar>
414 void Vp_StV( const Ptr<VectorBase<Scalar> > &y, const Scalar& alpha,
415  const VectorBase<Scalar>& x );
416 
417 
422 template<class Scalar>
423 void Vp_V(
424  const Ptr<VectorBase<Scalar> > &y, const VectorBase<Scalar>& x,
425  const Scalar& beta = static_cast<Scalar>(1.0)
426  );
427 
428 
433 template<class Scalar>
434 void V_V( const Ptr<VectorBase<Scalar> > &y, const VectorBase<Scalar>& x );
435 
436 
441 template<class Scalar>
442 void V_S( const Ptr<VectorBase<Scalar> > &y, const Scalar& alpha );
443 
444 
449 template<class Scalar>
450 void V_VpV( const Ptr<VectorBase<Scalar> > &z, const VectorBase<Scalar>& x,
451  const VectorBase<Scalar>& y );
452 
453 
458 template<class Scalar>
459 void V_VmV( const Ptr<VectorBase<Scalar> > &z, const VectorBase<Scalar>& x,
460  const VectorBase<Scalar>& y );
461 
462 
467 template<class Scalar>
468 void V_StVpV( const Ptr<VectorBase<Scalar> > &z, const Scalar &alpha,
469  const VectorBase<Scalar>& x, const VectorBase<Scalar>& y );
470 
471 
476 template<class Scalar>
477 void V_VpStV( const Ptr<VectorBase<Scalar> > &z,
478  const VectorBase<Scalar>& x,
479  const Scalar &alpha, const VectorBase<Scalar>& y );
480 
481 
486 template<class Scalar>
487 void V_StVpStV( const Ptr<VectorBase<Scalar> > &z, const Scalar &alpha,
488  const VectorBase<Scalar>& x, const Scalar &beta, const VectorBase<Scalar>& y );
489 
490 
495 template<class Scalar>
496 Scalar min( const VectorBase<Scalar>& x );
497 
498 
518 template<class Scalar>
519 void min( const VectorBase<Scalar>& x,
520  const Ptr<Scalar> &maxEle, const Ptr<Ordinal> &maxIndex );
521 
522 
552 template<class Scalar>
553 void minGreaterThanBound( const VectorBase<Scalar>& x, const Scalar &bound,
554  const Ptr<Scalar> &minEle, const Ptr<Ordinal> &minIndex );
555 
556 
561 template<class Scalar>
562 Scalar max( const VectorBase<Scalar>& x );
563 
564 
584 template<class Scalar>
585 void max( const VectorBase<Scalar>& x,
586  const Ptr<Scalar> &maxEle, const Ptr<Ordinal> &maxIndex );
587 
588 
617 template<class Scalar>
618 void maxLessThanBound( const VectorBase<Scalar>& x, const Scalar &bound,
619  const Ptr<Scalar> &maxEle, const Ptr<Ordinal> &maxIndex );
620 
621 
622 
623 
624 } // end namespace Thyra
625 
626 
627 // /////////////////////////
628 // Inline functions
629 
630 
631 template<class Scalar>
632 inline
633 Scalar Thyra::scalarProd( const VectorBase<Scalar>& x, const VectorBase<Scalar>& y )
634 {
635  return x.space()->scalarProd(x, y);
636 }
637 
638 
639 template<class Scalar>
640 inline
641 Scalar Thyra::inner( const VectorBase<Scalar>& x, const VectorBase<Scalar>& y )
642 {
643  return x.space()->scalarProd(x, y);
644 }
645 
646 
647 template<class Scalar>
648 inline
650 Thyra::norm( const VectorBase<Scalar>& v )
651 {
653  return ST::magnitude(ST::squareroot(v.space()->scalarProd(v, v)));
654 }
655 
656 
657 #endif // THYRA_VECTOR_STD_OPS_DECL_HPP
Abstract interface for finite-dimensional dense vectors.
Scalar dot(const VectorBase< Scalar > &x, const VectorBase< Scalar > &y)
Dot product: result = conj(x)'*y.
void maxLessThanBound(const VectorBase< Scalar > &x, const Scalar &bound, const Ptr< Scalar > &maxEle, const Ptr< Ordinal > &maxIndex)
Max element less than bound and its index: Returns maxEle = x(k) and maxIndex = k such that x(k) >= x...
void V_StVpV(const Ptr< VectorBase< Scalar > > &z, const Scalar &alpha, const VectorBase< Scalar > &x, const VectorBase< Scalar > &y)
z(i) = alpha*x(i) + y(i), i = 0...z->space()->dim()-1.
void linear_combination(const ArrayView< const Scalar > &alpha, const ArrayView< const Ptr< const VectorBase< Scalar > > > &x, const Scalar &beta, const Ptr< VectorBase< Scalar > > &y)
Linear combination: y(i) = beta*y(i) + sum( alpha[k]*x[k](i), k=0...m-1 ), i = 0.....
Scalar sum(const VectorBase< Scalar > &v)
Sum of vector elements: result = sum( v(i), i = 0...v.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 min(const VectorBase< Scalar > &x, const Ptr< Scalar > &maxEle, const Ptr< Ordinal > &maxIndex)
Min element and its index: Returns maxEle = x(k) and maxIndex = k such that x(k) <= x(i) for all i = ...
void seed_randomize(unsigned int s)
Seed the random number generator used in randomize().
void V_VpStV(const Ptr< VectorBase< Scalar > > &z, const VectorBase< Scalar > &x, const Scalar &alpha, const VectorBase< Scalar > &y)
z(i) = x(i) + alpha*y(i), i = 0...z->space()->dim()-1.
void Vp_S(const Ptr< VectorBase< Scalar > > &y, const Scalar &alpha)
Add a scalar to all elements: y(i) += alpha, i = 0...y->space()->dim()-1.
void V_StV(const Ptr< VectorBase< Scalar > > &y, const Scalar &alpha, const VectorBase< Scalar > &x)
Assign scaled vector: y(i) = alpha * x(i), i = 0...y->space()->dim()-1.
void reciprocal(const VectorBase< Scalar > &x, const Ptr< VectorBase< Scalar > > &y)
Element-wise reciprocal: y(i) = 1/x(i), i = 0...y->space()->dim()-1.
void Vt_S(const Ptr< VectorBase< Scalar > > &y, const Scalar &alpha)
Scale all elements by a scalar: y(i) *= alpha, i = 0...y->space()->dim()-1.
void ele_wise_conj_prod(const Scalar &alpha, const VectorBase< Scalar > &x, const VectorBase< Scalar > &v, const Ptr< VectorBase< Scalar > > &y)
Element-wise conjugate product update: y(i) += alpha * conj(x(i)) * v(i), i = 0......
Scalar inner(const VectorBase< Scalar > &x, const VectorBase< Scalar > &y)
Inner/Scalar product result = <x,y>.
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.
Teuchos::ScalarTraits< Scalar >::magnitudeType norm(const VectorBase< Scalar > &v)
Natural norm: result = sqrt(<v,v>).
void V_S(const Ptr< VectorBase< Scalar > > &y, const Scalar &alpha)
y(i) = alpha, i = 0...y->space()->dim()-1.
void V_VpV(const Ptr< VectorBase< Scalar > > &z, const VectorBase< Scalar > &x, const VectorBase< Scalar > &y)
z(i) = x(i) + y(i), i = 0...z->space()->dim()-1.
void pair_wise_max_update(const Scalar &alpha, const VectorBase< Scalar > &x, const Ptr< VectorBase< Scalar > > &y)
Element-wise maximum update: y(i) = alpha * max(x(i), y(i)), i = 0...y->space()->dim()-1.
virtual RCP< const VectorSpaceBase< Scalar > > space() const =0
Return a smart pointer to the vector space that this vector belongs to.
Scalar min(const VectorBase< Scalar > &x)
Min element: result = min{ x(i), i = 0...x.space()->dim()-1 } .
Teuchos::ScalarTraits< Scalar >::magnitudeType norm_2(const VectorBase< Scalar > &v)
Euclidean (2) norm: result = ||v||2.
void assign(const Ptr< VectorBase< Scalar > > &y, const VectorBase< Scalar > &x)
Vector assignment: y(i) = x(i), i = 0...y->space()->dim()-1.
void pair_wise_max(const Scalar &alpha, const VectorBase< Scalar > &x, const VectorBase< Scalar > &v, const Ptr< VectorBase< Scalar > > &y)
Element-wise maximum: y(i) = alpha * max(x(i), v(i)), i = 0...y->space()->dim()-1.
void scale(const Scalar &alpha, const Ptr< VectorBase< Scalar > > &y)
Scale all elements by a scalar: y(i) *= alpha, i = 0...y->space()->dim()-1.
void Vp_StVtV(const Ptr< VectorBase< Scalar > > &y, const Scalar &alpha, const VectorBase< Scalar > &x, const VectorBase< Scalar > &v)
Element-wise product update: y(i) += alpha * x(i) * v(i), i = 0...y->space()->dim()-1.
void randomize(Scalar l, Scalar u, const Ptr< VectorBase< Scalar > > &v)
Random vector generation: v(i) = rand(l,u), , i = 1...v->space()->dim().
Scalar max(const VectorBase< Scalar > &x)
Max element: result = max{ x(i), i = 1...n } .
Teuchos::ScalarTraits< Scalar >::magnitudeType norm_2(const VectorBase< Scalar > &w, const VectorBase< Scalar > &v)
Weighted Euclidean (2) norm: result = sqrt( sum( w(i)*conj(v(i))*v(i)) ).
Teuchos::ScalarTraits< Scalar >::magnitudeType norm_1(const VectorBase< Scalar > &v)
One (1) norm: result = ||v||1.
void ele_wise_divide(const Scalar &alpha, const VectorBase< Scalar > &x, const VectorBase< Scalar > &v, const Ptr< VectorBase< Scalar > > &y)
Element-wise division update: y(i) += alpha * x(i) / v(i), i = 0...y->space()->dim()-1.
void set_ele(Ordinal i, Scalar alpha, const Ptr< VectorBase< Scalar > > &v)
Set single element: v(i) = alpha.
void minGreaterThanBound(const VectorBase< Scalar > &x, const Scalar &bound, const Ptr< Scalar > &minEle, const Ptr< Ordinal > &minIndex)
Minimum element greater than some bound and its index: Returns minEle = x(k) and minIndex = k such th...
void Vt_StV(const Ptr< VectorBase< Scalar > > &y, const Scalar &alpha, const VectorBase< Scalar > &x)
Element-wise product update: y(i) *= alpha * x(i), i = 0...y->space()->dim()-1.
Scalar get_ele(const VectorBase< Scalar > &v, Ordinal i)
Get single element: result = v(i).
void Vp_V(const Ptr< VectorBase< Scalar > > &y, const VectorBase< Scalar > &x, const Scalar &beta=static_cast< Scalar >(1.0))
y(i) = x(i) + beta*y(i), i = 0...y->space()->dim()-1.
void abs(const VectorBase< Scalar > &x, const Ptr< VectorBase< Scalar > > &y)
Element-wise absolute value: y(i) = abs(x(i)), i = 0...y->space()->dim()-1.
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.
Scalar scalarProd(const VectorBase< Scalar > &x, const VectorBase< Scalar > &y)
Scalar product result = <x,y>.
void max(const VectorBase< Scalar > &x, const Ptr< Scalar > &maxEle, const Ptr< Ordinal > &maxIndex)
Max element and its index: Returns maxEle = x(k) and maxIndex = k such that x(k) >= x(i) for i = 0....
void V_StVpStV(const Ptr< VectorBase< Scalar > > &z, const Scalar &alpha, const VectorBase< Scalar > &x, const Scalar &beta, const VectorBase< Scalar > &y)
z(i) = alpha*x(i) + beta*y(i), i = 0...z->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 V_VmV(const Ptr< VectorBase< Scalar > > &z, const VectorBase< Scalar > &x, const VectorBase< Scalar > &y)
z(i) = x(i) - y(i), i = 0...z->space()->dim()-1.
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 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 copy(const VectorBase< Scalar > &x, const Ptr< VectorBase< Scalar > > &y)
Vector assignment: y(i) = x(i), i = 0...y->space()->dim()-1.
void V_V(const Ptr< VectorBase< Scalar > > &y, const VectorBase< Scalar > &x)
y(i) = x(i), i = 0...y->space()->dim()-1.
void assign(const Ptr< VectorBase< Scalar > > &y, const Scalar &alpha)
Assign all elements to a scalar: y(i) = alpha, i = 0...y->space()->dim()-1.
Teuchos::ScalarTraits< Scalar >::magnitudeType norm_inf(const VectorBase< Scalar > &v_rhs)
Infinity norm: result = ||v||inf.
Teuchos::Ordinal Ordinal
Type for the dimension of a vector space. `*.