Thyra Version of the Day
Loading...
Searching...
No Matches
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
50namespace Thyra {
51
52
58template<class Scalar>
59Scalar sum( const VectorBase<Scalar>& v );
60
61
68template<class Scalar>
70
71
78template<class Scalar>
79Scalar inner( const VectorBase<Scalar>& x, const VectorBase<Scalar>& y );
80
81
89template<class Scalar>
92
93
98template<class Scalar>
101
102
107template<class Scalar>
110
111
117template<class Scalar>
120
121
126template<class Scalar>
129
130
135template<class Scalar>
136Scalar dot( const VectorBase<Scalar>& x, const VectorBase<Scalar>& y );
137
138
143template<class Scalar>
144Scalar get_ele( const VectorBase<Scalar>& v, Ordinal i );
145
146
151template<class Scalar>
152void set_ele( Ordinal i, Scalar alpha, const Ptr<VectorBase<Scalar> > &v );
153
154
160template<class Scalar>
161void put_scalar( const Scalar& alpha, const Ptr<VectorBase<Scalar> > &y );
162
163
169template<class Scalar>
170void copy( const VectorBase<Scalar>& x, const Ptr<VectorBase<Scalar> > &y );
171
172
178template<class Scalar>
179void add_scalar( const Scalar& alpha, const Ptr<VectorBase<Scalar> > &y );
180
181
191template<class Scalar>
192void scale( const Scalar& alpha, const Ptr<VectorBase<Scalar> > &y );
193
194
200template<class Scalar>
201void abs( const VectorBase<Scalar> &x, const Ptr<VectorBase<Scalar> > &y );
202
203
209template<class Scalar>
211
212
218template<class Scalar>
219void ele_wise_prod( const Scalar& alpha, const VectorBase<Scalar>& x,
220 const VectorBase<Scalar>& v, const Ptr<VectorBase<Scalar> > &y );
221
222
228template<class Scalar>
229void pair_wise_max(const Scalar& alpha, const VectorBase<Scalar>& x,
230 const VectorBase<Scalar>& v, const Ptr<VectorBase<Scalar> > &y );
231
237template<class Scalar>
238void ele_wise_conj_prod( const Scalar& alpha, const VectorBase<Scalar>& x,
239 const VectorBase<Scalar>& v, const Ptr<VectorBase<Scalar> > &y );
240
241
247template<class Scalar>
249
250
256template<class Scalar>
257void Vp_StVtV( const Ptr<VectorBase<Scalar> > &y, const Scalar& alpha,
258 const VectorBase<Scalar>& x, const VectorBase<Scalar>& v);
259
260
266template<class Scalar>
267void ele_wise_prod_update( const Scalar& alpha, const VectorBase<Scalar>& x,
268 const Ptr<VectorBase<Scalar> > &y );
269
270
276template<class Scalar>
277void pair_wise_max_update( const Scalar& alpha, const VectorBase<Scalar>& x,
278 const Ptr<VectorBase<Scalar> > &y );
279
285template<class Scalar>
286void Vt_StV( const Ptr<VectorBase<Scalar> > &y, const Scalar& alpha,
287 const VectorBase<Scalar> &x );
288
289
295template<class Scalar>
296void ele_wise_divide( const Scalar& alpha, const VectorBase<Scalar>& x,
297 const VectorBase<Scalar>& v, const Ptr<VectorBase<Scalar> > &y );
298
299
322template<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
340template<class Scalar>
341void seed_randomize( unsigned int s );
342
343
354template<class Scalar>
355void randomize( Scalar l, Scalar u, const Ptr<VectorBase<Scalar> > &v );
356
357
363template<class Scalar>
364void assign( const Ptr<VectorBase<Scalar> > &y, const Scalar& alpha );
365
366
372template<class Scalar>
373void assign( const Ptr<VectorBase<Scalar> > &y, const VectorBase<Scalar>& x );
374
375
381template<class Scalar>
382void Vp_S( const Ptr<VectorBase<Scalar> > &y, const Scalar& alpha );
383
384
394template<class Scalar>
395void Vt_S( const Ptr<VectorBase<Scalar> > &y, const Scalar& alpha );
396
397
403template<class Scalar>
404void V_StV( const Ptr<VectorBase<Scalar> > &y, const Scalar& alpha,
405 const VectorBase<Scalar> &x );
406
407
413template<class Scalar>
414void Vp_StV( const Ptr<VectorBase<Scalar> > &y, const Scalar& alpha,
415 const VectorBase<Scalar>& x );
416
417
422template<class Scalar>
423void Vp_V(
424 const Ptr<VectorBase<Scalar> > &y, const VectorBase<Scalar>& x,
425 const Scalar& beta = static_cast<Scalar>(1.0)
426 );
427
428
433template<class Scalar>
434void V_V( const Ptr<VectorBase<Scalar> > &y, const VectorBase<Scalar>& x );
435
436
441template<class Scalar>
442void V_S( const Ptr<VectorBase<Scalar> > &y, const Scalar& alpha );
443
444
449template<class Scalar>
451 const VectorBase<Scalar>& y );
452
453
458template<class Scalar>
460 const VectorBase<Scalar>& y );
461
462
467template<class Scalar>
468void V_StVpV( const Ptr<VectorBase<Scalar> > &z, const Scalar &alpha,
469 const VectorBase<Scalar>& x, const VectorBase<Scalar>& y );
470
471
476template<class Scalar>
478 const VectorBase<Scalar>& x,
479 const Scalar &alpha, const VectorBase<Scalar>& y );
480
481
486template<class Scalar>
487void V_StVpStV( const Ptr<VectorBase<Scalar> > &z, const Scalar &alpha,
488 const VectorBase<Scalar>& x, const Scalar &beta, const VectorBase<Scalar>& y );
489
490
495template<class Scalar>
496Scalar min( const VectorBase<Scalar>& x );
497
498
518template<class Scalar>
519void min( const VectorBase<Scalar>& x,
520 const Ptr<Scalar> &maxEle, const Ptr<Ordinal> &maxIndex );
521
522
552template<class Scalar>
553void minGreaterThanBound( const VectorBase<Scalar>& x, const Scalar &bound,
554 const Ptr<Scalar> &minEle, const Ptr<Ordinal> &minIndex );
555
556
561template<class Scalar>
562Scalar max( const VectorBase<Scalar>& x );
563
564
584template<class Scalar>
585void max( const VectorBase<Scalar>& x,
586 const Ptr<Scalar> &maxEle, const Ptr<Ordinal> &maxIndex );
587
588
617template<class Scalar>
618void 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
631template<class Scalar>
632inline
633Scalar Thyra::scalarProd( const VectorBase<Scalar>& x, const VectorBase<Scalar>& y )
634{
635 return x.space()->scalarProd(x, y);
636}
637
638
639template<class Scalar>
640inline
641Scalar Thyra::inner( const VectorBase<Scalar>& x, const VectorBase<Scalar>& y )
642{
643 return x.space()->scalarProd(x, y);
644}
645
646
647template<class Scalar>
648inline
650Thyra::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.
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.
virtual RCP< const VectorSpaceBase< Scalar > > space() const =0
Return a smart pointer to the vector space that this vector belongs to.
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. `*.