Subproject STKAlgebra::Algebra


Classes

class  STK::EigenValues
 The class EigenValues compute the eigenvalue Decomposition of a symetric Matrix. More...
class  STK::Qr
 The class Qr perform the QR decomposition of a Matrix. More...
class  STK::Svd
 The class Svd compute the Singular Value Decomposition of a Matrix with the Golub-Reinsch Algorithm. More...

Functions

Real STK::compGivens (const Real &y, const Real &z, Real &cosinus, Real &sinus)
 Compute Givens rotation.
template<class TContainerHo , class TContainerVe , class TContainer2D >
void STK::rightGivens (const ITContainer2D< Real, TContainerHo, TContainerVe, TContainer2D > &M, const Integer &col1, const Integer &col2, const Real &cosinus, const Real &sinus)
 Apply Givens rotation.
template<class TContainerHo , class TContainerVe , class TContainer2D >
void STK::leftGivens (const ITContainer2D< Real, TContainerHo, TContainerVe, TContainer2D > &M, const Integer &row1, const Integer &row2, const Real &cosinus, const Real &sinus)
 left multiplication by a Givens Matrix.
template<class TContainer1D >
Real STK::house (ITContainer1D< Real, TContainer1D > &x)
 Compute the Householder vector v of a vector x.
template<class TContainer1D_1 , class TContainer1D_2 >
Real STK::dotHouse (const ITContainer1D< Real, TContainer1D_1 > &x, const ITContainer1D< Real, TContainer1D_2 > &v)
 dot product with a Householder vector.
template<class TContainerHo , class TContainerVe , class TContainer2D , class TContainer1D >
void STK::leftHouseholder (const ITContainer2D< Real, TContainerHo, TContainerVe, TContainer2D > &M, const ITContainer1D< Real, TContainer1D > &v)
 left multiplication by a Householder vector.
template<class TContainerHo , class TContainerVe , class TContainer2D , class TContainer1D >
void STK::rightHouseholder (const ITContainer2D< Real, TContainerHo, TContainerVe, TContainer2D > &M, const ITContainer1D< Real, TContainer1D > &v)
 right multiplication by a Householder vector.
template<class TContainerHo , class TContainerVe , class TContainer2D >
void STK::leftHouseholder (const ITContainer2D< Real, TContainerHo, TContainerVe, TContainer2D > &M, const Matrix &H)
 left multiplication by a Householder Matrix.
template<class TContainerHo , class TContainerVe , class TContainer2D >
void STK::rightHouseholder (const ITContainer2D< Real, TContainerHo, TContainerVe, TContainer2D > &M, const Matrix &H)
 left multiplication by a Householder Matrix.
template<class Container1D >
Real STK::sum (const ITContainer1D< Real, Container1D > &x)
 Sum the element of the container.
template<class Container1D >
Real STK::normInf (const ITContainer1D< Real, Container1D > &x)
 Compute the infinite norm.
template<class Container1D >
Real STK::normTwo2 (const ITContainer1D< Real, Container1D > &x)
 Compute the squared norm two.
template<class Container1D_1 , class Container1D_2 >
Real STK::dot (const ITContainer1D< Real, Container1D_1 > &x, const ITContainer1D< Real, Container1D_2 > &y)
 Compute the dot product.
template<class Container1D_1 , class Container1D_2 >
Real STK::dist (const ITContainer1D< Real, Container1D_1 > &x, const ITContainer1D< Real, Container1D_2 > &y)
 Compute the distance between two vectors.
template<class TContainerHo , class TContainerVe , class TContainer2D >
Real STK::normInf (ITContainer2D< Real, TContainerHo, TContainerVe, TContainer2D > const &A)
 Compute the infinity norm of a Matrix.
template<class TContainerHo_1 , class TContainerVe_1 , class TContainer2D_1 , class TContainerHo_2 , class TContainerVe_2 , class TContainer2D_2 >
void STK::transpose (ITContainer2D< Real, TContainerHo_1, TContainerVe_1, TContainer2D_1 > const &A, ITContainer2D< Real, TContainerHo_2, TContainerVe_2, TContainer2D_2 > &At)
 transpose a matrix
template<class TContainerHo , class TContainerVe , class TContainer2D >
ITContainer2D< Real,
TContainerHo, TContainerVe,
TContainer2D > & 
STK::transpose (ITContainer2D< Real, TContainerHo, TContainerVe, TContainer2D > &Q)
 Transpose a Matrix.
template<class LEAF >
void STK::mult (Vector &U, const IArray2D< Real, LEAF > &A, const Vector &V)
 Right mulitplication of a Matrix by a vector.
template<class LEAF >
void STK::mult (Point &U, const Point &V, const IArray2D< Real, LEAF > &A)
 Left multiplication of a Matrix with a Point.
template<class LEAF_1 , class LEAF_2 , class LEAF_3 >
void STK::mult (IArray2D< Real, LEAF_1 > &C, const IArray2D< Real, LEAF_2 > &A, const IArray2D< Real, LEAF_3 > &B)
 Matrix multiplication.

Function Documentation

Real STK::compGivens ( const Real &  y,
const Real &  z,
Real &  cosinus,
Real &  sinus 
)

Compute the Givens rotation

\[ \begin{bmatrix} c & s \\ -s & c \end{bmatrix} \begin{bmatrix} a \\ b \end{bmatrix} = \begin{bmatrix} r \\ 0 \end{bmatrix}. \]

in order to eliminate the coefficient z and return the value r of the rotated element.

See also:
http://en.wikipedia.org/wiki/Givens_rotation
Parameters:
y The coefficient to rotate (input)
z the coefficient to eliminate (input)
cosinus the cosinus of the Givens rotation (output)
sinus the sinus of the Givens rotation rotation (output)

Definition at line 52 of file STK_Givens.cpp.

References STK::abs(), and STK::sign().

Referenced by STK::Qr::eraseCol(), STK::Qr::insertCol(), and STK::Qr::pushBackCol().

00057 {
00058   // trivial case
00059   if (z == 0)
00060   { 
00061     sinus   = 0.0;
00062     cosinus = 1.0;
00063     return y;
00064   }
00065   // compute Givens rotation avoiding underflow and overflow
00066   if (abs(z) > abs(y))
00067   { 
00068     Real aux = y/z;
00069     Real t   = sign(z, sqrt(1.0+aux*aux)); 
00070     sinus    = 1.0/t;
00071     cosinus  = sinus * aux;
00072     return t*z;
00073   }        
00074   else
00075   {
00076     Real aux = z/y;
00077     Real t   = sign(y, sqrt(1.0+aux*aux));
00078     cosinus  = 1.0/t;
00079     sinus    = cosinus * aux;
00080     return t*y;
00081   }
00082 }

template<class TContainerHo , class TContainerVe , class TContainer2D >
void STK::rightGivens ( const ITContainer2D< Real, TContainerHo, TContainerVe, TContainer2D > &  M,
const Integer &  col1,
const Integer &  col2,
const Real &  cosinus,
const Real &  sinus 
) [inline]

Perform a right multiplication of the Container M with a Givens Matrix on the col1 and col2. col1 should be less than col2. The Matrix M is passed as const as we are using reference on the two cols we want to rotate.

See also:
http://en.wikipedia.org/wiki/Givens_rotation
Parameters:
M the Container to multiply
col1 the first col
col2 the second col
cosinus the cosinus of the givens rotation
sinus the sinus of the givens rotation

Definition at line 117 of file STK_Givens.h.

Referenced by STK::Svd::diag(), STK::EigenValues::diag(), STK::Qr::eraseCol(), STK::Qr::insertCol(), STK::Svd::leftEliminate(), STK::Qr::pushBackCol(), and STK::Svd::rightEliminate().

00127 {
00128   // A ref on the col1 of M
00129   TContainerVe Mcol1(M.asLeaf(), M.getRangeVe(), col1);
00130   // A ref on the col2 of M
00131   TContainerVe Mcol2(M.asLeaf(), M.getRangeVe(), col2);
00132   // Apply givens rotation
00133   for (Integer i = M.firstRow(); i <=M.lastRow(); i++)
00134   {
00135     Real aux1 = Mcol1[i], aux2 = Mcol2[i];
00136     Mcol1[i] = cosinus * aux1 + sinus * aux2;
00137     Mcol2[i] = cosinus * aux2 - sinus * aux1;
00138   }
00139 }

template<class TContainerHo , class TContainerVe , class TContainer2D >
void STK::leftGivens ( const ITContainer2D< Real, TContainerHo, TContainerVe, TContainer2D > &  M,
const Integer &  row1,
const Integer &  row2,
const Real &  cosinus,
const Real &  sinus 
) [inline]

Perform a left multiplication of the matrix M with a Givens Matrix on the row1 and row2. row1 should be less than row2. The Matrix M is passed as const as we are using reference on the two rows we want to rotate.

See also:
http://en.wikipedia.org/wiki/Givens_rotation
Parameters:
M the matix to multiply
row1 the first row
row2 the second row
cosinus the cosinus of the givens rotation
sinus the sinus of the givens rotation

Definition at line 161 of file STK_Givens.h.

Referenced by STK::Qr::eraseCol(), and STK::Qr::insertCol().

00171 {
00172   // A ref on the row iter of R_
00173   TContainerHo Mrow1(M.asLeaf(), M.getRangeHo(), row1);
00174   // A ref on the row iter1 of R_
00175   TContainerHo Mrow2(M.asLeaf(), M.getRangeHo(), row2);
00176   // apply right Givens rotation
00177   for (Integer j = M.firstCol(); j<= M.lastCol(); j++)
00178   {
00179     Real aux1 = Mrow1[j], aux2 = Mrow2[j];
00180     Mrow1[j] = cosinus * aux1 + sinus * aux2;
00181     Mrow2[j] = cosinus * aux2 - sinus * aux1;
00182   }
00183 }

template<class TContainer1D >
Real STK::house ( ITContainer1D< Real, TContainer1D > &  x  )  [inline]

Given a vector x, compute the vector v of the matrix of Householder $ P=I-2vv'/(v'v) $ such that $ Px = v1 e_1 $. The vector v is of the form : $ (1,x_2/s,...,x_n/s)' $ and is stored in x. The value 1 is skipped and $ \beta = -2/(v'v) $ is stored in front of v. The method return the value v1.

Parameters:
x the vector to rotate, it is overwritten by v

Definition at line 83 of file STK_Householder.h.

References STK::ITContainer1D< TYPE, TContainer1D >::first(), STK::ITContainer1D< TYPE, TContainer1D >::front(), STK::ITContainer1D< TYPE, TContainer1D >::last(), STK::normInf(), and STK::sign().

Referenced by STK::Svd::bidiag(), STK::Qr::qr(), and STK::EigenValues::tridiag().

00084 {
00085   // compute L^{\infty} norm of X
00086   Real scale  = normInf(x);
00087   // first and last index fo the essential Householder vector
00088   Integer first = x.first()+1, last = x.last();
00089   // result and norm2 of X
00090   Real v1, norm2 = 0.0;
00091   // normalize the vector 
00092   if (scale)  // if not 0.0
00093   {
00094     for (Integer i=first; i<=last; i++)
00095     { x[i] /= scale; norm2 += x[i]*x[i];}
00096   }
00097   // check if the lower part is significative
00098   if (norm2 < Arithmetic<Real>::epsilon())
00099   {
00100     v1 = x.front(); x.front() = 0.0; // beta = 0.0
00101   }
00102   else
00103   {
00104     Real s, aux1 = x.front() / scale;
00105     // compute v1 = P_v X and beta of the Householder vector
00106     v1 =  (norm2 = sign(aux1, sqrt(aux1*aux1+norm2))) * scale;
00107     // compute and save beta
00108     x.front() = (s = aux1-norm2)/norm2;
00109     // comp v and save it
00110     for (Integer i=first; i<=last; i++) x[i] /= s;
00111   }
00112   return v1;
00113 }

template<class TContainer1D_1 , class TContainer1D_2 >
Real STK::dotHouse ( const ITContainer1D< Real, TContainer1D_1 > &  x,
const ITContainer1D< Real, TContainer1D_2 > &  v 
) [inline]

Scalar product of a TContainer1D with a Householder vector d = < x,v>. The first composant of a Householder vector is 1.0

Parameters:
x first vector
v the Householder vector

Definition at line 126 of file STK_Householder.h.

References STK::ITContainer1D< TYPE, TContainer1D >::first(), STK::ITContainer1D< TYPE, TContainer1D >::last(), and STK::sum().

Referenced by STK::leftHouseholder(), and STK::rightHouseholder().

00129 {
00130   // first and last index fo the essential Householder vector
00131   const Integer first = v.first()+1, last = v.last();
00132   // compute the product
00133   Real sum = x[first-1] /* *1.0 */;
00134   for (Integer i=first; i<=last; i++) sum += x[i] * v[i];
00135   // return <x,v>
00136   return(sum);
00137 }

template<class TContainerHo , class TContainerVe , class TContainer2D , class TContainer1D >
void STK::leftHouseholder ( const ITContainer2D< Real, TContainerHo, TContainerVe, TContainer2D > &  M,
const ITContainer1D< Real, TContainer1D > &  v 
) [inline]

Perform a left multiplication of the matrix M with a Householder matrix $ H=I+beta vv' $. Overwrite M with HM.

Parameters:
M the matrix to multiply (input/output)
v the Householder vector (input)

Definition at line 152 of file STK_Householder.h.

References beta(), and STK::dotHouse().

Referenced by STK::Svd::bidiag(), and STK::leftHouseholder().

00161 {
00162   // get beta
00163   Real beta = v.front();
00164   if (beta)
00165   {
00166     // get range of the Householder vector
00167     Inx range_ve = v.getRange();
00168     // Multiplication of the cols by P=I+beta vv'
00169     for (Integer j=M.firstCol(); j<=M.lastCol(); j++)
00170     {
00171       // a ref on the jth column of M
00172       TContainerVe Mj(M.asLeaf(), range_ve, j);
00173       // Computation of aux=beta* <v,M^j>
00174       Real aux =  dotHouse( Mj, v) * beta;
00175       // updating row X.first()
00176       Mj.front() += aux;
00177       // essential range of v
00178       const Integer first =  v.first()+1, last = v.last();
00179       // Computation of M^j + beta <v,M^j>  v = M^j + aux v
00180       for (Integer i=first; i<=last; i++)
00181         Mj[i] +=  v[i] * aux;
00182     }
00183   }
00184 }

template<class TContainerHo , class TContainerVe , class TContainer2D , class TContainer1D >
void STK::rightHouseholder ( const ITContainer2D< Real, TContainerHo, TContainerVe, TContainer2D > &  M,
const ITContainer1D< Real, TContainer1D > &  v 
) [inline]

Perform a right multiplication of the matrix M with a Householder matrix $ H=I+beta vv' $. Overwrite M with MH.

Parameters:
M the matrix to multiply (input/output)
v the Householder vector (input)

Definition at line 200 of file STK_Householder.h.

References beta(), and STK::dotHouse().

Referenced by STK::Svd::bidiag(), and STK::rightHouseholder().

00209 {
00210   // get beta
00211   Real beta = v.front();
00212   if (beta)
00213   {
00214     // Multiplication of the cols by P=I+beta vv'
00215     for (Integer i=M.firstRow(); i<=M.lastRow(); i++)
00216     {
00217       // a ref on the ith row of M
00218       TContainerHo Mi(M.asLeaf(), v.getRange(), i);
00219       // Computation of aux=beta* <v,M_i>
00220       Real aux =  dotHouse( Mi, v) * beta;
00221       // updating col X.first()
00222       Mi.front() += aux;
00223       // essential range of v
00224       const Integer first =  v.first()+1, last = v.last();
00225       // Computation of M_i + beta <v,M_i>  v = M_i + aux v'
00226       for (Integer i=first; i<=last; i++)
00227         Mi[i] +=  v[i] * aux;
00228     }
00229   }
00230 }

template<class TContainerHo , class TContainerVe , class TContainer2D >
void STK::leftHouseholder ( const ITContainer2D< Real, TContainerHo, TContainerVe, TContainer2D > &  M,
const Matrix &  H 
) [inline]

Perform a left multiplication of the Matrix M with a Householder Marix H. M <- HM with H = I + WZ'. The Householder vectors are stored in the columns of H.

Parameters:
M the matrix to multiply
H the Householder Matrix

Definition at line 246 of file STK_Householder.h.

References STK::ITContainer2D< TYPE, TContainerHo, TContainerVe, TContainer2D >::firstCol(), STK::ITContainer2D< TYPE, TContainerHo, TContainerVe, TContainer2D >::lastCol(), STK::ITContainer2D< TYPE, TContainerHo, TContainerVe, TContainer2D >::lastRow(), STK::leftHouseholder(), and STK::min().

00253 {
00254   // compute the number of iterations
00255   Integer first = H.firstCol()
00256         , last = min( H.lastCol(), H.lastRow());
00257   // get range of the first Householder vector
00258   Inx range_ve(last, H.lastRow());
00259   // iterations
00260   for (Integer j=last; j>=first; j--)
00261   {
00262     // apply left Householder vector to M
00263     leftHouseholder(M, H(range_ve, j));
00264     // decrease range of the Householder vector
00265     range_ve.decFirst();
00266   }
00267 }

template<class TContainerHo , class TContainerVe , class TContainer2D >
void STK::rightHouseholder ( const ITContainer2D< Real, TContainerHo, TContainerVe, TContainer2D > &  M,
const Matrix &  H 
) [inline]

Perform a right multiplication of the matrix M with a Householder Marix H. M <- MP with H = I + WZ'. The Householder vectors are stored in the rows of H.

Parameters:
M the Matrix to multiply
H the Householder Matrix

Definition at line 283 of file STK_Householder.h.

References STK::ITContainer2D< TYPE, TContainerHo, TContainerVe, TContainer2D >::firstCol(), STK::ITContainer2D< TYPE, TContainerHo, TContainerVe, TContainer2D >::lastCol(), STK::ITContainer2D< TYPE, TContainerHo, TContainerVe, TContainer2D >::lastRow(), STK::min(), and STK::rightHouseholder().

00290 {
00291   // compute the number of iterations
00292   Integer first = H.firstCol()
00293         , last = min( H.lastCol(), H.lastRow());
00294   // get range of the first Householder vector
00295   Inx range_ve(last, H.lastRow());
00296   // iterations
00297   for (Integer j=last; j>=first; j--)
00298   {
00299     // apply left Householder vector to M
00300     rightHouseholder(M, H(range_ve, j));
00301     // decrease range of the Householder vector
00302     range_ve.decFirst();
00303   }
00304 }

template<class Container1D >
Real STK::sum ( const ITContainer1D< Real, Container1D > &  x  )  [inline]

template<class Container1D >
Real STK::normInf ( const ITContainer1D< Real, Container1D > &  x  )  [inline]

Compute the maximal absolute value of the Container1D x

\[ s= \max_{i=1}^n x_i \]

Parameters:
[in] x vector to treat

Definition at line 82 of file STK_LinAlgebra1D.h.

References STK::abs(), STK::ITContainer1D< TYPE, TContainer1D >::first(), STK::ITContainer1D< TYPE, TContainer1D >::last(), and STK::max().

Referenced by STK::house(), and STK::normTwo2().

00083 {
00084   Real scale = 0.0;
00085   for (Integer i=x.first(); i<=x.last(); i++)
00086     scale = max(scale, abs(x[i]));
00087   return (scale);
00088 }

template<class Container1D >
Real STK::normTwo2 ( const ITContainer1D< Real, Container1D > &  x  )  [inline]

Compute the square norm of the Container1D x avoiding overflow

\[ \|x\|^2 = \sum_{i=1}^n x^2_i \]

Parameters:
[in] x vector to treat

Definition at line 123 of file STK_LinAlgebra1D.h.

References STK::ITContainer1D< TYPE, TContainer1D >::first(), STK::ITContainer1D< TYPE, TContainer1D >::last(), STK::norm(), and STK::normInf().

00124 {
00125   Real scale =normInf(x), norm =0.0;
00126   if (scale)
00127   { // comp the norm
00128     for (Integer i = x.first(); i<=x.last(); i++)
00129     {
00130       Real aux = x[i]/scale;
00131       norm += aux * aux;
00132     }
00133   }
00134   // scale result
00135   return (norm*scale*scale);
00136 }

template<class Container1D_1 , class Container1D_2 >
Real STK::dot ( const ITContainer1D< Real, Container1D_1 > &  x,
const ITContainer1D< Real, Container1D_2 > &  y 
) [inline]

Dot product of the vector x and the vector y: d = <x, y>. The common range of the vectors is used.

\[ <x,y> = \sum_{i=1}^n x_i y_i \]

Parameters:
[in] x first vector
[in] y second vector

Definition at line 149 of file STK_LinAlgebra1D.h.

References STK::ITContainer1D< TYPE, TContainer1D >::first(), STK::ITContainer1D< TYPE, TContainer1D >::last(), STK::max(), STK::min(), and STK::sum().

Referenced by STK::Qr::compQ(), STK::Svd::compU(), STK::Svd::compV(), STK::Qr::insertCol(), STK::mult(), STK::Qr::pushBackCol(), and STK::Qr::qr().

00152 {
00153   // compute the valid range
00154   const Integer imin = max(x.first(), y.first())
00155               , imax = min(x.last(), y.last());
00156   // compute the sum product
00157   Real sum=0.0;
00158   for (Integer i = imin; i<=imax; i++)
00159     sum += x[i] * y[i];
00160 
00161   return (sum);
00162 }

template<class Container1D_1 , class Container1D_2 >
Real STK::dist ( const ITContainer1D< Real, Container1D_1 > &  x,
const ITContainer1D< Real, Container1D_2 > &  y 
) [inline]

Distance of a Container1D from a Container1D without overflow.

\[ d(x,y) = || x - y|| \]

The common range is used.

Parameters:
[in] x first vector
[in] y second vector

Definition at line 178 of file STK_LinAlgebra1D.h.

References STK::abs(), STK::ITContainer1D< TYPE, TContainer1D >::first(), STK::ITContainer1D< TYPE, TContainer1D >::last(), STK::max(), and STK::min().

00181 {
00182   // compute the valid range
00183   const Integer imin = max(x.first(), y.first())
00184               , imax = min(x.last(), y.last());
00185   // compute the maximal difference
00186   Real scale = 0.;
00187   for (Integer i = imin; i<=imax; i++)
00188     scale = abs(scale, x[i] - y[i]);
00189   // Compute the norm
00190   Real norm2 = 0.;
00191   if (scale)
00192   { // comp the norm^2
00193     for (Integer i = imin; i<=imax; i++)
00194     {
00195       const Real aux = (x[i]-y[i])/scale;
00196       norm2 += aux * aux;
00197     }
00198   }
00199   // rescale sum
00200   return (sqrt(norm2)*scale);
00201 }

template<class TContainerHo , class TContainerVe , class TContainer2D >
Real STK::normInf ( ITContainer2D< Real, TContainerHo, TContainerVe, TContainer2D > const &  A  )  [inline]

Return the maximal absolute value of the Container2D x

\[ s= \max_{i=1}^n |x_i| \]

Parameters:
[in] A matrix to treat

Definition at line 83 of file STK_LinAlgebra2D.h.

References STK::abs(), and STK::max().

00089 {
00090   Real scale = 0.0;
00091   for (Integer j=A.firstRow(); j<=A.lastRow(); j++)
00092     for (Integer i=A.firstCol(); i<=A.lastCol(); i++)
00093       scale = max(scale, abs(A(i,j)));
00094   return (scale);
00095 }

template<class TContainerHo_1 , class TContainerVe_1 , class TContainer2D_1 , class TContainerHo_2 , class TContainerVe_2 , class TContainer2D_2 >
void STK::transpose ( ITContainer2D< Real, TContainerHo_1, TContainerVe_1, TContainer2D_1 > const &  A,
ITContainer2D< Real, TContainerHo_2, TContainerVe_2, TContainer2D_2 > &  At 
) [inline]

Transpose the Matrix A and give the result in At.

Parameters:
[in] A the matrix to transpose
[out] At the transposed matrix

Definition at line 112 of file STK_LinAlgebra2D.h.

Referenced by STK::transpose().

00123 {
00124   // Resize At.
00125   At.resize(A.getRangeHo(), A.getRangeVe());
00126 
00127   // copy each col of Q in each row of R
00128   for (Integer j=A.firstCol(); j<=A.lastCol(); j++)
00129     At(j) = A[j];
00130 }

template<class TContainerHo , class TContainerVe , class TContainer2D >
ITContainer2D< Real , TContainerHo , TContainerVe , TContainer2D >& STK::transpose ( ITContainer2D< Real, TContainerHo, TContainerVe, TContainer2D > &  Q  )  [inline]

Transpose a matrix and overload it with the result

Parameters:
[in,out] Q the matrix to transpose

Definition at line 148 of file STK_LinAlgebra2D.h.

References STK::transpose().

00153 {
00154   // check if we have to create an auxiliary cont
00155   if (Q.sizeVe() != Q.sizeHo())
00156   {
00157     // create temporary Matrix
00158     Matrix R;
00159     transpose(R, Q);
00160     Q = R;
00161     return Q;
00162   }
00163   // Square Matrix
00164   Integer rbeg = Q.firstRow(), rend = Q.lastRow()
00165         , cbeg = Q.firstCol(), cend = Q.lastCol();
00166   // for every rows and cols
00167   for (Integer  i=rbeg, j=cbeg; j<cend; i++, j++)
00168   {
00169     // Create refs to current col and current row
00170     Vector Qcol(Q, Inx(rbeg-cbeg+1 +j, rend), j);
00171     Point  Qrow(Q, Inx(cbeg-rbeg+1 +i, cend), i);
00172     for ( Integer k1=rbeg-cbeg+1 +j, k2=cbeg-rbeg+1 +i
00173         ; k1<=rend
00174         ; k1++, k2++
00175         )
00176     {
00177       Real aux(Qcol[k1]);
00178       Qcol[k1]  = Qrow[k2];
00179       Qrow[k2] = aux;
00180     }
00181   }
00182   return Q;
00183 }

template<class LEAF >
void STK::mult ( Vector &  U,
const IArray2D< Real, LEAF > &  A,
const Vector &  V 
) [inline]

Perfform the right multiplication of the Matrix A by the Vector V, $ U = A V $.

The function dot take the common range of A(i) and V, thus this is not an error if A.getRangeHo() != V.getRange().

The range of U give the range of the iterations.

Parameters:
[out] U Vector result
[in] A Matrix to multiply
[in] V the vector which multiply

Definition at line 203 of file STK_LinAlgebra2D.h.

References STK::dot(), STK::ITContainer1D< TYPE, TContainer1D >::first(), STK::ITContainer1D< TYPE, TContainer1D >::getRange(), STK::ITContainer2D< TYPE, ArrayHo< TYPE >, Array1D< TYPE >, TArray2D >::getRangeVe(), and STK::ITContainer1D< TYPE, TContainer1D >::last().

00207 {
00208 #ifdef STK_DEBUG
00209   if (U.getRange() != A.getRangeVe())
00210     throw std::runtime_error("In mult(U, A, V "
00211                              "U.getRange() != A.getRangeVe()");
00212 #endif
00213   Integer ifirst = U.first(), ilast = U.last();
00214   // dot take the common range of A(i) and V, thus this is not
00215   // an error if A.getRangeHo() != V.getRange().
00216   for (Integer i=ifirst; i<=ilast; i++)
00217     U[i] = dot(A(i), V);
00218 }

template<class LEAF >
void STK::mult ( Point &  U,
const Point &  V,
const IArray2D< Real, LEAF > &  A 
) [inline]

Perform the left multiplication of a the Matrix A by the Point V, $ U = VA $.

The function dot take the common range of A(i) and V, thus this is not an error if A.getRangeVe() != V.getRange().

The range of U give the range of the iterations.

Parameters:
[out] U Point result
[in] A Matrix to multiply
[in] V the Point which multiply

Definition at line 236 of file STK_LinAlgebra2D.h.

References STK::dot(), STK::ITContainer1D< TYPE, TContainer1D >::first(), STK::ITContainer1D< TYPE, TContainer1D >::getRange(), STK::ITContainer2D< TYPE, ArrayHo< TYPE >, Array1D< TYPE >, TArray2D >::getRangeHo(), and STK::ITContainer1D< TYPE, TContainer1D >::last().

00240 {
00241 #ifdef STK_DEBUG
00242   if (U.getRange() != A.getRangeHo())
00243     throw std::runtime_error("In mult(U, V, A "
00244                              "U.getRange() != A.getRangeHo()");
00245 #endif
00246   Integer ifirst = U.first(), ilast = U.last();
00247   // for all cols
00248   for (Integer j=ifirst; j<=ilast; j++)
00249     U[j] = dot(V, A[j]);
00250 }

template<class LEAF_1 , class LEAF_2 , class LEAF_3 >
void STK::mult ( IArray2D< Real, LEAF_1 > &  C,
const IArray2D< Real, LEAF_2 > &  A,
const IArray2D< Real, LEAF_3 > &  B 
) [inline]

Perform the matricial product of the Matrix A with the Matrix B $ C = AB $.

The range of C gives the range of the iterations. This method should be specialized for upper and lower triangular Matix.

Parameters:
[out] C Matrix result
[in] A Matrix to multiply
[in] B Matrix which multiply

Definition at line 267 of file STK_LinAlgebra2D.h.

References STK::dot(), STK::ITContainer2D< TYPE, ArrayHo< TYPE >, Array1D< TYPE >, TArray2D >::firstCol(), STK::ITContainer2D< TYPE, ArrayHo< TYPE >, Array1D< TYPE >, TArray2D >::firstRow(), STK::ITContainer2D< TYPE, ArrayHo< TYPE >, Array1D< TYPE >, TArray2D >::getRangeHo(), STK::ITContainer2D< TYPE, ArrayHo< TYPE >, Array1D< TYPE >, TArray2D >::getRangeVe(), STK::ITContainer2D< TYPE, ArrayHo< TYPE >, Array1D< TYPE >, TArray2D >::lastCol(), and STK::ITContainer2D< TYPE, ArrayHo< TYPE >, Array1D< TYPE >, TArray2D >::lastRow().

00271 {
00272 #ifdef STK_DEBUG
00273   if (C.getRangeVe() != A.getRangeVe())
00274     throw std::runtime_error("In mult(C, A, B "
00275                              "C.getRangeVe() != A.getRangeVe()");
00276   if (C.getRangeHo() != B.getRangeHo())
00277     throw std::runtime_error("In mult(C, A, B "
00278                              "C.getRangeHo() != B.getRangeHo()");
00279 #endif
00280   // indexes
00281   Integer ifirst_col = C.firstCol(), ilast_col = C.lastCol();
00282   Integer ifirst_row = C.firstRow(), ilast_row = C.lastRow();
00283   // for all cols
00284   for (Integer j=ifirst_col; j<=ilast_col; j++)
00285   {
00286     // for all lines
00287     for (Integer i=ifirst_row; i<=ilast_row; i++)
00288       C(i, j) = dot(A(i), B[j]);
00289   }
00290 }


Generated on Fri Sep 25 10:30:59 2009 for STK++ by  doxygen 1.5.8