scaled [MTL Home] Programmers Guide
  Contents | Index |  Search 


Category:containers Component type:function
Prototype
template <class Scalable, class T>
Scalable::scaled_type scaled(const Scalable& A, const T& alpha) ;
Description
This function can be used to scale arguments in MTL functions. For example, to perform the vector addition operation z <- a x + b y one would do the following:
   mtl::add(scaled(x, alpha), scaled(y, beta), z);
   
The actual multiplication by alpha and beta is done within the algorithm, so the performance is the same as if the add() function had parameters for alpha and beta. The scaled() function can be used with any vector or matrix argument in MTL functions. Do not confuse this function with mtl::scale() which are stand-alone functions.
Definition
scaled1D.h
Requirements on types
  • T must be convertible to Scalable's value_type
  • Scalable's value_type must be a model of Ring
Preconditions
Complexity
compile time and adds a single multiplication to each element access inside of any algorithm
Example
In y_ax_y.cc:
  typedef matrix< double, 
                  rectangle<>, 
                  dense<>, 
                  row_major>::type Matrix; 
  Matrix A(3,3);
  double SCALE = - A(2,1) / A(1,1);
  add(scaled(A[0], SCALE), A[1], A[1]);  

Notes
See also

[MTL Home] Copyright © 1998,1999 University of Notre Dame. All Rights Reserved.