/usr/include/trilinos/Thyra_VectorStdOps_decl.hpp is in libtrilinos-thyra-dev 12.4.2-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 | // @HEADER
// ***********************************************************************
//
// Thyra: Interfaces and Support for Abstract Numerical Algorithms
// Copyright (2004) Sandia Corporation
//
// Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
// license for use of this work by or on behalf of the U.S. Government.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// 3. Neither the name of the Corporation nor the names of the
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Questions? Contact Roscoe A. Bartlett (bartlettra@ornl.gov)
//
// ***********************************************************************
// @HEADER
#ifndef THYRA_VECTOR_STD_OPS_DECL_HPP
#define THYRA_VECTOR_STD_OPS_DECL_HPP
#include "Thyra_OperatorVectorTypes.hpp"
namespace Thyra {
/** \brief Sum of vector elements:
* <tt>result = sum( v(i), i = 0...v.space()->dim()-1 )</tt>.
*
* \relates VectorBase
*/
template<class Scalar>
Scalar sum( const VectorBase<Scalar>& v );
/** \brief Scalar product <tt>result = <x,y></tt>.
*
* Returns <tt>x.space()->scalarProd(x,y)</tt>.
*
* \relates VectorBase
*/
template<class Scalar>
Scalar scalarProd( const VectorBase<Scalar>& x, const VectorBase<Scalar>& y );
/** \brief Inner/Scalar product <tt>result = <x,y></tt>.
*
* Returns <tt>x.space()->scalarProd(x,y)</tt>.
*
* \relates VectorBase
*/
template<class Scalar>
Scalar inner( const VectorBase<Scalar>& x, const VectorBase<Scalar>& y );
/** \brief Natural norm: <tt>result = sqrt(<v,v>)</tt>.
*
* Returns
* <tt>Teuchos::ScalarTraits<Scalar>::squareroot(v.space()->scalarProd(v,v))</tt>.
*
* \relates VectorBase
*/
template<class Scalar>
typename Teuchos::ScalarTraits<Scalar>::magnitudeType
norm( const VectorBase<Scalar>& v );
/** \brief One (1) norm: <tt>result = ||v||1</tt>.
*
* \relates VectorBase
*/
template<class Scalar>
typename Teuchos::ScalarTraits<Scalar>::magnitudeType
norm_1( const VectorBase<Scalar>& v );
/** \brief Euclidean (2) norm: <tt>result = ||v||2</tt>.
*
* \relates VectorBase
*/
template<class Scalar>
typename Teuchos::ScalarTraits<Scalar>::magnitudeType
norm_2( const VectorBase<Scalar>& v );
/** \brief Weighted Euclidean (2) norm:
* <tt>result = sqrt( sum( w(i)*conj(v(i))*v(i)) )</tt>.
*
* \relates VectorBase
*/
template<class Scalar>
typename Teuchos::ScalarTraits<Scalar>::magnitudeType
norm_2( const VectorBase<Scalar> &w, const VectorBase<Scalar>& v );
/** \brief Infinity norm: <tt>result = ||v||inf</tt>.
*
* \relates VectorBase
*/
template<class Scalar>
typename Teuchos::ScalarTraits<Scalar>::magnitudeType
norm_inf( const VectorBase<Scalar>& v_rhs );
/** \brief Dot product: <tt>result = conj(x)'*y</tt>.
*
* \relates VectorBase
*/
template<class Scalar>
Scalar dot( const VectorBase<Scalar>& x, const VectorBase<Scalar>& y );
/** \brief Get single element: <tt>result = v(i)</tt>.
*
* \relates VectorBase
*/
template<class Scalar>
Scalar get_ele( const VectorBase<Scalar>& v, Ordinal i );
/** \brief Set single element: <tt>v(i) = alpha</tt>.
*
* \relates VectorBase
*/
template<class Scalar>
void set_ele( Ordinal i, Scalar alpha, const Ptr<VectorBase<Scalar> > &v );
/** \brief Assign all elements to a scalar:
* <tt>y(i) = alpha, i = 0...y->space()->dim()-1</tt>.
*
* \relates VectorBase
*/
template<class Scalar>
void put_scalar( const Scalar& alpha, const Ptr<VectorBase<Scalar> > &y );
/** \brief Vector assignment:
* <tt>y(i) = x(i), i = 0...y->space()->dim()-1</tt>.
*
* \relates VectorBase
*/
template<class Scalar>
void copy( const VectorBase<Scalar>& x, const Ptr<VectorBase<Scalar> > &y );
/** \brief Add a scalar to all elements:
* <tt>y(i) += alpha, i = 0...y->space()->dim()-1</tt>.
*
* \relates VectorBase
*/
template<class Scalar>
void add_scalar( const Scalar& alpha, const Ptr<VectorBase<Scalar> > &y );
/** \brief Scale all elements by a scalar:
* <tt>y(i) *= alpha, i = 0...y->space()->dim()-1</tt>.
*
* This takes care of the special cases of <tt>alpha == 0.0</tt>
* (set <tt>y = 0.0</tt>) and <tt>alpha == 1.0</tt> (don't
* do anything).
*
* \relates VectorBase
*/
template<class Scalar>
void scale( const Scalar& alpha, const Ptr<VectorBase<Scalar> > &y );
/** \brief Element-wise absolute value:
* <tt>y(i) = abs(x(i)), i = 0...y->space()->dim()-1</tt>.
*
* \relates VectorBase
*/
template<class Scalar>
void abs( const VectorBase<Scalar> &x, const Ptr<VectorBase<Scalar> > &y );
/** \brief Element-wise reciprocal:
* <tt>y(i) = 1/x(i), i = 0...y->space()->dim()-1</tt>.
*
* \relates VectorBase
*/
template<class Scalar>
void reciprocal( const VectorBase<Scalar> &x, const Ptr<VectorBase<Scalar> > &y );
/** \brief Element-wise product update:
* <tt>y(i) += alpha * x(i) * v(i), i = 0...y->space()->dim()-1</tt>.
*
* \relates VectorBase
*/
template<class Scalar>
void ele_wise_prod( const Scalar& alpha, const VectorBase<Scalar>& x,
const VectorBase<Scalar>& v, const Ptr<VectorBase<Scalar> > &y );
/** \brief Element-wise conjugate product update:
* <tt>y(i) += alpha * conj(x(i)) * v(i), i = 0...y->space()->dim()-1</tt>.
*
* \relates VectorBase
*/
template<class Scalar>
void ele_wise_conj_prod( const Scalar& alpha, const VectorBase<Scalar>& x,
const VectorBase<Scalar>& v, const Ptr<VectorBase<Scalar> > &y );
/** \brief Element-wise scaling:
* <tt>y(i) *= x(i), i = 0...y->space()->dim()-1</tt>.
*
* \relates VectorBase
*/
template<class Scalar>
void ele_wise_scale( const VectorBase<Scalar>& x, const Ptr<VectorBase<Scalar> > &y );
/** \brief Element-wise product update:
* <tt>y(i) += alpha * x(i) * v(i), i = 0...y->space()->dim()-1</tt>.
*
* \relates VectorBase
*/
template<class Scalar>
void Vp_StVtV( const Ptr<VectorBase<Scalar> > &y, const Scalar& alpha,
const VectorBase<Scalar>& x, const VectorBase<Scalar>& v);
/** \brief Element-wise product update:
* <tt>y(i) *= alpha * x(i), i = 0...y->space()->dim()-1</tt>.
*
* \relates VectorBase
*/
template<class Scalar>
void ele_wise_prod_update( const Scalar& alpha, const VectorBase<Scalar>& x,
const Ptr<VectorBase<Scalar> > &y );
/** \brief Element-wise product update:
* <tt>y(i) *= alpha * x(i), i = 0...y->space()->dim()-1</tt>.
*
* \relates VectorBase
*/
template<class Scalar>
void Vt_StV( const Ptr<VectorBase<Scalar> > &y, const Scalar& alpha,
const VectorBase<Scalar> &x );
/** \brief Element-wise division update:
* <tt>y(i) += alpha * x(i) / v(i), i = 0...y->space()->dim()-1</tt>.
*
* \relates VectorBase
*/
template<class Scalar>
void ele_wise_divide( const Scalar& alpha, const VectorBase<Scalar>& x,
const VectorBase<Scalar>& v, const Ptr<VectorBase<Scalar> > &y );
/** \brief Linear combination:
* <tt>y(i) = beta*y(i) + sum( alpha[k]*x[k](i), k=0...m-1 ), i = 0...y->space()->dim()-1</tt>.
*
* \param m [in] Number of vectors x[]
*
* \param alpha [in] Array (length <tt>m</tt>) of input scalars.
*
* \param x [in] Array (length <tt>m</tt>) of input vectors.
*
* \param beta [in] Scalar multiplier for y
*
* \param y [in/out] Target vector that is the result of the linear
* combination.
*
* This function implements a general linear combination:
\verbatim
y(i) = beta*y(i) + alpha[0]*x[0](i) + alpha[1]*x[1](i)
+ ... + alpha[m-1]*x[m-1](i), i = 0...y->space()->dim()-1
\endverbatim
*
* \relates VectorBase
*/
template<class Scalar>
void linear_combination(
const ArrayView<const Scalar> &alpha,
const ArrayView<const Ptr<const VectorBase<Scalar> > > &x,
const Scalar &beta,
const Ptr<VectorBase<Scalar> > &y
);
/** \brief Seed the random number generator used in <tt>randomize()</tt>.
*
* \param s [in] The seed for the random number generator.
*
* Note, this just calls
* <tt>Teuchos::TOpRandomize<Scalar>::set_static_seed(s)</tt>.
*
* \relates VectorBase
*/
template<class Scalar>
void seed_randomize( unsigned int s );
/** \brief Random vector generation:
* <tt>v(i) = rand(l,u), , i = 1...v->space()->dim()</tt>.
*
* The elements <tt>v->getEle(i)</tt> are randomly generated between
* <tt>[l,u]</tt>.
*
* The seed is set using the above <tt>seed_randomize()</tt> function.
*
* \relates VectorBase
*/
template<class Scalar>
void randomize( Scalar l, Scalar u, const Ptr<VectorBase<Scalar> > &v );
/** \brief Assign all elements to a scalar:
* <tt>y(i) = alpha, i = 0...y->space()->dim()-1</tt>.
*
* \relates VectorBase
*/
template<class Scalar>
void assign( const Ptr<VectorBase<Scalar> > &y, const Scalar& alpha );
/** \brief Vector assignment:
* <tt>y(i) = x(i), i = 0...y->space()->dim()-1</tt>.
*
* \relates VectorBase
*/
template<class Scalar>
void assign( const Ptr<VectorBase<Scalar> > &y, const VectorBase<Scalar>& x );
/** \brief Add a scalar to all elements:
* <tt>y(i) += alpha, i = 0...y->space()->dim()-1</tt>.
*
* \relates VectorBase
*/
template<class Scalar>
void Vp_S( const Ptr<VectorBase<Scalar> > &y, const Scalar& alpha );
/** \brief Scale all elements by a scalar:
* <tt>y(i) *= alpha, i = 0...y->space()->dim()-1</tt>.
*
* This takes care of the special cases of <tt>alpha == 0.0</tt>
* (set <tt>y = 0.0</tt>) and <tt>alpha == 1.0</tt> (don't
* do anything).
*
* \relates VectorBase
*/
template<class Scalar>
void Vt_S( const Ptr<VectorBase<Scalar> > &y, const Scalar& alpha );
/** \brief Assign scaled vector:
* <tt>y(i) = alpha * x(i), i = 0...y->space()->dim()-1</tt>.
*
* \relates VectorBase
*/
template<class Scalar>
void V_StV( const Ptr<VectorBase<Scalar> > &y, const Scalar& alpha,
const VectorBase<Scalar> &x );
/** \brief AXPY:
* <tt>y(i) = alpha * x(i) + y(i), i = 0...y->space()->dim()-1</tt>.
*
* \relates VectorBase
*/
template<class Scalar>
void Vp_StV( const Ptr<VectorBase<Scalar> > &y, const Scalar& alpha,
const VectorBase<Scalar>& x );
/** \brief <tt>y(i) = x(i) + beta*y(i), i = 0...y->space()->dim()-1</tt>.
*
* \relates VectorBase
*/
template<class Scalar>
void Vp_V(
const Ptr<VectorBase<Scalar> > &y, const VectorBase<Scalar>& x,
const Scalar& beta = static_cast<Scalar>(1.0)
);
/** \brief <tt>y(i) = x(i), i = 0...y->space()->dim()-1</tt>.
*
* \relates VectorBase
*/
template<class Scalar>
void V_V( const Ptr<VectorBase<Scalar> > &y, const VectorBase<Scalar>& x );
/** \brief <tt>y(i) = alpha, i = 0...y->space()->dim()-1</tt>.
*
* \relates VectorBase
*/
template<class Scalar>
void V_S( const Ptr<VectorBase<Scalar> > &y, const Scalar& alpha );
/** \brief <tt>z(i) = x(i) + y(i), i = 0...z->space()->dim()-1</tt>.
*
* \relates VectorBase
*/
template<class Scalar>
void V_VpV( const Ptr<VectorBase<Scalar> > &z, const VectorBase<Scalar>& x,
const VectorBase<Scalar>& y );
/** \brief <tt>z(i) = x(i) - y(i), i = 0...z->space()->dim()-1</tt>.
*
* \relates VectorBase
*/
template<class Scalar>
void V_VmV( const Ptr<VectorBase<Scalar> > &z, const VectorBase<Scalar>& x,
const VectorBase<Scalar>& y );
/** \brief <tt>z(i) = alpha*x(i) + y(i), i = 0...z->space()->dim()-1</tt>.
*
* \relates VectorBase
*/
template<class Scalar>
void V_StVpV( const Ptr<VectorBase<Scalar> > &z, const Scalar &alpha,
const VectorBase<Scalar>& x, const VectorBase<Scalar>& y );
/** \brief <tt>z(i) = x(i) + alpha*y(i), i = 0...z->space()->dim()-1</tt>.
*
* \relates VectorBase
*/
template<class Scalar>
void V_VpStV( const Ptr<VectorBase<Scalar> > &z,
const VectorBase<Scalar>& x,
const Scalar &alpha, const VectorBase<Scalar>& y );
/** \brief <tt>z(i) = alpha*x(i) + beta*y(i), i = 0...z->space()->dim()-1</tt>.
*
* \relates VectorBase
*/
template<class Scalar>
void V_StVpStV( const Ptr<VectorBase<Scalar> > &z, const Scalar &alpha,
const VectorBase<Scalar>& x, const Scalar &beta, const VectorBase<Scalar>& y );
/** \brief Min element: <tt>result = min{ x(i), i = 0...x.space()->dim()-1 } </tt>.
*
* \relates VectorBase
*/
template<class Scalar>
Scalar min( const VectorBase<Scalar>& x );
/** \brief Min element and its index: Returns <tt>maxEle = x(k)</tt>
* and <tt>maxIndex = k</tt> such that <tt>x(k) <= x(i)</tt> for all
* <tt>i = 0...x.space()->dim()-1</tt>.
*
* \param x [in] Input vector.
*
* \param minEle [out] The minimum element value.
*
* \param maxindex [out] The global index of the minimum element. If there is
* more than one element with the maximum entry then this returns the lowest
* index in order to make the output independent of the order of operations.
*
* Preconditions:<ul>
* <li><tt>minEle!=NULL</tt>
* <li><tt>minIndex!=NULL</tt>
* </ul>
*
* \relates VectorBase
*/
template<class Scalar>
void min( const VectorBase<Scalar>& x,
const Ptr<Scalar> &maxEle, const Ptr<Ordinal> &maxIndex );
/** \brief Minimum element greater than some bound and its index:
* Returns <tt>minEle = x(k)</tt> and <tt>minIndex = k</tt> such that
* <tt>x(k) <= x(i)</tt> for all <tt>i</tt> where <tt>x(i) >
* bound</tt>.
*
* \param x [in] Input vector.
*
* \param bound [in] The upper bound
*
* \param minEle [out] The minimum element value as defined above.
*
* \param minIndex [out] The global index of the maximum element. If there is
* more than one element with the minimum value then this returns the lowest
* index in order to make the output independent of the order of operations.
* If no entries are less than <tt>bound</tt> then <tt>minIndex < 0</tt> on
* return.
*
* Preconditions:<ul>
* <li><tt>minEle!=NULL</tt>
* <li><tt>minIndex!=NULL</tt>
* </ul>
*
* Postconditions:<ul>
* <li>If <tt>*minIndex > 0</tt> then such an element was found.
* <li>If <tt>*minIndex < 0</tt> then no such element was found.
* </ul>
*
* \relates VectorBase
*/
template<class Scalar>
void minGreaterThanBound( const VectorBase<Scalar>& x, const Scalar &bound,
const Ptr<Scalar> &minEle, const Ptr<Ordinal> &minIndex );
/** \brief Max element: <tt>result = max{ x(i), i = 1...n } </tt>.
*
* \relates VectorBase
*/
template<class Scalar>
Scalar max( const VectorBase<Scalar>& x );
/** \brief Max element and its index: Returns <tt>maxEle = x(k)</tt>
* and <tt>maxIndex = k</tt> such that <tt>x(k) >= x(i)</tt> for
* <tt>i = 0...x.space()->dim()-1</tt>.
*
* \param x [in] Input vector.
*
* \param maxEle [out] The maximum element value.
*
* \param maxindex [out] The global index of the maximum element. If there is
* more than one element with the maximum value then this returns the lowest
* index in order to make the output independent of the order of operations.
*
* Preconditions:<ul>
* <li><tt>maxEle!=NULL</tt>
* <li><tt>maxIndex!=NULL</tt>
* </ul>
*
* \relates VectorBase
*/
template<class Scalar>
void max( const VectorBase<Scalar>& x,
const Ptr<Scalar> &maxEle, const Ptr<Ordinal> &maxIndex );
/** \brief Max element less than bound and its index: Returns <tt>maxEle =
* x(k)</tt> and <tt>maxIndex = k</tt> such that <tt>x(k) >= x(i)</tt> for all
* <tt>i</tt> where <tt>x(i) < bound</tt>.
*
* \param x [in] Input vector.
*
* \param bound [in] The upper bound
*
* \param maxEle [out] The maximum element value as defined above.
*
* \param maxindex [out] The global index of the maximum element. If there is
* more than one element with the maximum index then this returns the lowest
* index in order to make the output independent of the order of operations.
* If no entries are less than <tt>bound</tt> then <tt>minIndex < 0</tt> on
* return.
*
* Preconditions:<ul>
* <li><tt>maxEle!=NULL</tt>
* <li><tt>maxIndex!=NULL</tt>
* </ul>
*
* Postconditions:<ul>
* <li>If <tt>*maxIndex > 0</tt> then such an element was found.
* <li>If <tt>*maxIndex < 0</tt> then no such element was found.
* </ul>
*
* \relates VectorBase
*/
template<class Scalar>
void maxLessThanBound( const VectorBase<Scalar>& x, const Scalar &bound,
const Ptr<Scalar> &maxEle, const Ptr<Ordinal> &maxIndex );
} // end namespace Thyra
// /////////////////////////
// Inline functions
template<class Scalar>
inline
Scalar Thyra::scalarProd( const VectorBase<Scalar>& x, const VectorBase<Scalar>& y )
{
return x.space()->scalarProd(x, y);
}
template<class Scalar>
inline
Scalar Thyra::inner( const VectorBase<Scalar>& x, const VectorBase<Scalar>& y )
{
return x.space()->scalarProd(x, y);
}
template<class Scalar>
inline
typename Teuchos::ScalarTraits<Scalar>::magnitudeType
Thyra::norm( const VectorBase<Scalar>& v )
{
typedef Teuchos::ScalarTraits<Scalar> ST;
return ST::magnitude(ST::squareroot(v.space()->scalarProd(v, v)));
}
#endif // THYRA_VECTOR_STD_OPS_DECL_HPP
|