STK++ 1.0

STK::Array2D< Real > Class Template Reference

Specialization of the Array2D class for Real values. More...

#include <STK_Matrix.h>

Inheritance diagram for STK::Array2D< Real >:

List of all members.

Public Types

typedef IArray2D< Real,
Array2D< Real > > 
_IArray2DType
 Type for the Interface base Class.

Public Member Functions

 Array2D (Range const &I=Range(), Range const &J=Range())
 Default constructor.
 Array2D (Range const &I, Range const &J, Real const &v)
 constructor with rbeg, rend, cbeg and cend specified, initialization with a constant.
 Array2D (const Array2D &T, bool ref=false)
 Copy constructor.
 Array2D (const Array2D &T, Range const &I, Range const &J)
 constructor by reference, ref_=1.
 Array2D (Real **q, Range const &I, Range const &J)
 Wrapper constructor Contruct a reference container.
virtual ~Array2D ()
 virtual destructor.
Realelt (Integer i, Integer j)
 access to one element.
Real const & elt (Integer i, Integer j) const
 access to one element const.
Array2D get2D (Range const &I, Range const &J) const
 access to a sub-array.
Vector col (Integer j) const
 access to a column.
Vector col (Range const &I, Integer j) const
 access to a sub-col.
Point row (Integer const &i) const
 access to a row.
Point row (Integer i, Range const &J) const
 access to a sub-row.
Range compRangeVe (Integer const &icol) const
 pseudo virtual method required by IArray2D.
void swapRows (Integer const &pos1, Integer pos2)
 Swapping the pos1 row and the pos2 row.
Array2Doperator= (const Array2D &T)
 operator = : overwrite the Array2D with T.
Array2Doperator= (Real const &v)
 operator= : set the container to a constant value.
Array2Doperator+= (Real const &v)
 operator += : add to the container a constant value.
Array2Doperator-= (Real const &v)
 operator -= : Subtract to the container a constant value.
Array2Doperator*= (Real const &v)
 operator *= : multiply to the container a constant value.
Array2Doperator/= (Real const &v)
 operator /= : divide to the container a constant value.
template<class Exp >
Array2Doperator= (const Exp &rhs)
 operator = overwriting a Array2D with An Expression.
template<class Exp >
Array2Doperator+= (const Exp &rhs)
 operator += Adding an Expression.
template<class Exp >
Array2Doperator-= (const Exp &rhs)
 operator -= decreasing an Expression.
template<class Exp >
Array2Doperator/= (const Exp &rhs)
 operator /= Dividing an Expression.
template<class Exp >
Array2Doperator*= (const Exp &rhs)
 operator *= Multiplying an Expression.

Detailed Description

template<>
class STK::Array2D< Real >

Specialization of the Array2D class for Real values.

The Matrix class (Array2D<Real> specialization) is a final class. It would not possible to derive this class and to use the method

as the curious recursive template paradigm would be break.

Definition at line 67 of file STK_Matrix.h.


Member Typedef Documentation

Type for the Interface base Class.

Definition at line 71 of file STK_Matrix.h.


Constructor & Destructor Documentation

STK::Array2D< Real >::Array2D ( Range const &  I = Range(),
Range const &  J = Range() 
) [inline]

Default constructor.

Parameters:
Irange of the Rows
Jrange of the Cols

Definition at line 77 of file STK_Matrix.h.

References STK::IArray2D< TYPE, Array2D< TYPE > >::initializeCols().

           : _IArray2DType(I, J)
    {
      // initialize vertically the container
      this->initializeCols(J);
    }
STK::Array2D< Real >::Array2D ( Range const &  I,
Range const &  J,
Real const &  v 
) [inline]

constructor with rbeg, rend, cbeg and cend specified, initialization with a constant.

Parameters:
Irange of the Rows
Jrange of the Cols
vinitial value of the container

Definition at line 90 of file STK_Matrix.h.

References STK::IArrayBase< TYPE * >::data(), STK::Range::first(), STK::IArray2D< TYPE, Array2D< TYPE > >::initializeCols(), and STK::Range::last().

           : _IArray2DType(I, J)
    {
      // initialize vertically the container
      this->initializeCols(J);
      // initialize with v
      for (Integer j=J.first(); j<=J.last(); j++)
      {
        Real* p(this->data(j));
        for (Integer i=I.first(); i<=I.last(); i++) p[i]= v;
      }
    }
STK::Array2D< Real >::Array2D ( const Array2D< Real > &  T,
bool  ref = false 
) [inline]

Copy constructor.

Parameters:
Tthe container to copy
reftrue if T is wrapped

Definition at line 107 of file STK_Matrix.h.

References STK::IArrayBase< DATA >::data(), STK::IArrayBase< TYPE * >::data(), STK::IContainer2D::firstCol(), STK::IContainer2D::firstRow(), STK::IArray2D< TYPE, Array2D< TYPE > >::initializeCols(), STK::IContainer2D::lastCol(), STK::IContainer2D::lastRow(), pt(), and STK::IContainer2D::rangeHo().

           : _IArray2DType(T, ref)
    { 
      if (!ref)
      {
        // initialize the Cols and Rows
        this->initializeCols(T.rangeHo());
        for (Integer j=T.firstCol(); j<=T.lastCol(); j++)
        {
          // ptr on the rows
          Real* p = this->data(j);
          Real* pt= T.data(j);
          for (Integer i=T.firstRow(); i<=T.lastRow(); i++) p[i]=pt[i];
        }
      }
    }
STK::Array2D< Real >::Array2D ( const Array2D< Real > &  T,
Range const &  I,
Range const &  J 
) [inline]

constructor by reference, ref_=1.

Parameters:
Tthe container to wrap
Irange of the Rows to wrap
Jrange of the Cols to wrap

Definition at line 129 of file STK_Matrix.h.

           : _IArray2DType(T, I, J)
    { ;}
STK::Array2D< Real >::Array2D ( Real **  q,
Range const &  I,
Range const &  J 
) [inline]

Wrapper constructor Contruct a reference container.

Parameters:
qpointer on the data
Irange of the Rows to wrap
Jrange of the Cols to wrap

Definition at line 138 of file STK_Matrix.h.

           : _IArray2DType(q, I, J)
    { ;}
virtual STK::Array2D< Real >::~Array2D ( ) [inline, virtual]

virtual destructor.

Definition at line 143 of file STK_Matrix.h.

    { ;}

Member Function Documentation

Real& STK::Array2D< Real >::elt ( Integer  i,
Integer  j 
) [inline]

access to one element.

Definition at line 147 of file STK_Matrix.h.

References STK::IArrayBase< TYPE * >::data().

    { return this->data(j)[i];}
Real const& STK::Array2D< Real >::elt ( Integer  i,
Integer  j 
) const [inline]

access to one element const.

Definition at line 151 of file STK_Matrix.h.

References STK::IArrayBase< TYPE * >::data().

    { return this->data(j)[i];}
Array2D STK::Array2D< Real >::get2D ( Range const &  I,
Range const &  J 
) const [inline]

access to a sub-array.

Definition at line 155 of file STK_Matrix.h.

References STK::Array2D< TYPE >::Array2D().

    { return Array2D(*this, I, J);} 
Vector STK::Array2D< Real >::col ( Integer  j) const [inline]

access to a column.

Reimplemented from STK::ITContainer2D< Real, ArrayHo< Real >, Array1D< Real >, Array2D< Real > >.

Definition at line 159 of file STK_Matrix.h.

References STK::IArrayBase< TYPE * >::data(), and STK::IContainer2D::rangeVe().

    { return Vector(this->data(j), this->rangeVe(), j);}
Vector STK::Array2D< Real >::col ( Range const &  I,
Integer  j 
) const [inline]

access to a sub-col.

Definition at line 163 of file STK_Matrix.h.

References STK::IArrayBase< TYPE * >::data().

    { return Vector(this->data(j), I, j);}
Point STK::Array2D< Real >::row ( Integer const &  i) const [inline]

access to a row.

Parameters:
iindex of the row
Returns:
A reference on the row i

Reimplemented from STK::IArray2D< Real, Array2D< Real > >.

Definition at line 170 of file STK_Matrix.h.

References STK::IContainer2D::rangeHo().

    { return Point(*this, this->rangeHo(), i);}
Point STK::Array2D< Real >::row ( Integer  i,
Range const &  J 
) const [inline]

access to a sub-row.

Definition at line 174 of file STK_Matrix.h.

    { return Point(*this, J, i);}
Range STK::Array2D< Real >::compRangeVe ( Integer const &  icol) const [inline]

pseudo virtual method required by IArray2D.

compute the range of the effectively stored elements in the col icol.

Parameters:
icolthe index of the column to compute the range

Definition at line 182 of file STK_Matrix.h.

References STK::IContainer2D::rangeVe().

    { return this->rangeVe();}
void STK::Array2D< Real >::swapRows ( Integer const &  pos1,
Integer  pos2 
) [inline]

Swapping the pos1 row and the pos2 row.

Parameters:
pos1position of the first row
pos2position of the second row

Definition at line 189 of file STK_Matrix.h.

References STK::IRecursiveTemplate< Array2D< TYPE > >::asLeaf(), STK::IArray2D< TYPE, Array2D< TYPE > >::elt(), STK::IContainer2D::firstCol(), STK::IContainer2D::firstRow(), STK::IContainer2D::lastCol(), and STK::IContainer2D::lastRow().

    {
#ifdef STK_BOUNDS_CHECK
      // check conditions
      if (this->firstRow() > pos1)
      { throw std::out_of_range("Array2D::swapRows(pos1, pos2) "
                                "this->firstRow() > pos1");
      }
      if (this->lastRow() < pos1)
      { throw std::out_of_range("Array2D::swapRows(pos1, pos2) "
                                "this->lastRow() < pos1");
      }
      if (this->firstRow() > pos2)
      { throw std::out_of_range("Array2D::swapRows(pos1, pos2) "
                                "this->firstRow() > pos2");
      }
      if (this->lastRow() < pos2)
      { throw std::out_of_range("Array2D::swapRows(pos1, pos2) "
                                "this->lastRow() < pos2");
      }
#endif
      // swap
      for (Integer j=this->firstCol(); j<=this->lastCol(); j++)
      {
        Real aux(this->asLeaf().elt(pos1, j));
        this->asLeaf().elt(pos1, j) = this->asLeaf().elt(pos2, j);
        this->asLeaf().elt(pos2, j) = aux;
      }
    }
Array2D& STK::Array2D< Real >::operator= ( const Array2D< Real > &  T) [inline]

operator = : overwrite the Array2D with T.

We resize the object if this and T does not have the same size but if they have the same size, we don't modify the range of the object.

Parameters:
Tthe container to copy

Definition at line 225 of file STK_Matrix.h.

References STK::IArrayBase< DATA >::data(), STK::IArrayBase< TYPE * >::data(), STK::IContainer2D::firstCol(), STK::IContainer2D::firstRow(), STK::IContainer2D::lastCol(), STK::IContainer2D::lastRow(), pt(), STK::IContainer2D::rangeHo(), STK::IContainer2D::rangeVe(), STK::IContainer2D::resize(), STK::IContainer2D::sizeHo(), and STK::IContainer2D::sizeVe().

    {
      // Resize if necessary.
      if ( (this->sizeVe() != T.sizeVe())
         ||(this->sizeHo() != T.sizeHo())
         )
        this->resize(T.rangeVe(), T.rangeHo());
      // Copy without overlapping
      if (T.firstRow()>=this->firstRow())
      {
        if (T.firstCol()>=this->firstCol())
        {
          for ( Integer jt=T.firstCol(), j=this->firstCol()
              ; jt<=T.lastCol()
              ; j++, jt++
              )
          {
            Real *p =this->data(j), *pt =T.data(jt);
            for ( Integer it=T.firstRow(), i=this->firstRow()
                ; it<=T.lastRow()
                ; i++, it++
                )
              p[i] = pt[it];
          }
          return *this;
        }
        // T.firstCol()<this->firstCol()
        for ( Integer jt=T.lastCol(), j=this->lastCol()
            ; jt>=T.firstCol()
            ; j--, jt--
            )
        {
          Real *p =this->data(j), *pt =T.data(jt);
          for ( Integer it=T.firstRow(), i=this->firstRow()
              ; it<=T.lastRow()
              ; i++, it++
              )
            p[i] = pt[it];
        }
        return *this;
      }
      // T.firstRow()<this->firstRow()
      if (T.firstCol()>=this->firstCol())
      {
        for ( Integer jt=T.firstCol(), j=this->firstCol()
            ; jt<=T.lastCol()
            ; j++, jt++
            )
        {
          Real *p =this->data(j), *pt =T.data(jt);
          for ( Integer it=T.lastRow(), i=this->lastRow()
              ; it>=T.firstRow()
              ; i--, it--
              )
            p[i] = pt[it] ;
        }
        return *this;
      }
      // T.firstCol()<this->firstCol()
      for ( Integer jt=T.lastCol(), j=this->lastCol()
          ; jt>=T.firstCol()
          ; j--, jt--
          )
      {
        Real *p =this->data(j), *pt =T.data(jt);
        for ( Integer it=T.lastRow(), i=this->lastRow()
            ; it>=T.firstRow()
            ; i--, it--
            )
          p[i] = pt[it];
      }
      return *this;
    }
Array2D& STK::Array2D< Real >::operator= ( Real const &  v) [inline]

operator= : set the container to a constant value.

Parameters:
vthe value to set

Reimplemented in STK::MatrixSquare.

Definition at line 302 of file STK_Matrix.h.

References STK::IArrayBase< TYPE * >::data(), STK::IContainer2D::firstCol(), STK::IContainer2D::firstRow(), STK::IContainer2D::lastCol(), and STK::IContainer2D::lastRow().

    {
      for (Integer j=this->firstCol(); j<=this->lastCol(); j++)
      { Real *p =this->data(j);
        for (Integer i=this->firstRow(); i<=this->lastRow(); i++)
          p[i] = v;
      }
      return *this;
    }
Array2D& STK::Array2D< Real >::operator+= ( Real const &  v) [inline]

operator += : add to the container a constant value.

Parameters:
vthe value to set

Definition at line 315 of file STK_Matrix.h.

References STK::IArrayBase< TYPE * >::data(), STK::IContainer2D::firstCol(), STK::IContainer2D::firstRow(), STK::IContainer2D::lastCol(), and STK::IContainer2D::lastRow().

    {
      for (Integer j=this->firstCol(); j<=this->lastCol(); j++)
      { Real *p =this->data(j);
        for (Integer i=this->firstRow(); i<=this->lastRow(); i++)
          p[i] += v;
      }
      return *this;
    }
Array2D& STK::Array2D< Real >::operator-= ( Real const &  v) [inline]

operator -= : Subtract to the container a constant value.

Parameters:
vthe value to set

Definition at line 328 of file STK_Matrix.h.

References STK::IArrayBase< TYPE * >::data(), STK::IContainer2D::firstCol(), STK::IContainer2D::firstRow(), STK::IContainer2D::lastCol(), and STK::IContainer2D::lastRow().

    {
      for (Integer j=this->firstCol(); j<=this->lastCol(); j++)
      { Real *p =this->data(j);
        for (Integer i=this->firstRow(); i<=this->lastRow(); i++)
          p[i] += v;
      }
      return *this;
    }
Array2D& STK::Array2D< Real >::operator*= ( Real const &  v) [inline]

operator *= : multiply to the container a constant value.

Parameters:
vthe value to set

Definition at line 341 of file STK_Matrix.h.

References STK::IArrayBase< TYPE * >::data(), STK::IContainer2D::firstCol(), STK::IContainer2D::firstRow(), STK::IContainer2D::lastCol(), and STK::IContainer2D::lastRow().

    {
      for (Integer j=this->firstCol(); j<=this->lastCol(); j++)
      { Real *p =this->data(j);
        for (Integer i=this->firstRow(); i<=this->lastRow(); i++)
          p[i] += v;
      }
      return *this;
    }
Array2D& STK::Array2D< Real >::operator/= ( Real const &  v) [inline]

operator /= : divide to the container a constant value.

Parameters:
vthe value to set

Definition at line 354 of file STK_Matrix.h.

References STK::IArrayBase< TYPE * >::data(), STK::IContainer2D::firstCol(), STK::IContainer2D::firstRow(), STK::IContainer2D::lastCol(), and STK::IContainer2D::lastRow().

    {
      for (Integer j=this->firstCol(); j<=this->lastCol(); j++)
      { Real *p =this->data(j);
        for (Integer i=this->firstRow(); i<=this->lastRow(); i++)
          p[i] /= v;
      }
      return *this;
    }
template<class Exp >
Array2D& STK::Array2D< Real >::operator= ( const Exp &  rhs) [inline]

operator = overwriting a Array2D with An Expression.

Parameters:
rhsthe right hand side expression

Definition at line 368 of file STK_Matrix.h.

References STK::IArray2D< TYPE, Array2D< TYPE > >::elt(), STK::IContainer2D::firstCol(), STK::IContainer2D::firstRow(), STK::IContainer2D::lastCol(), and STK::IContainer2D::lastRow().

    {
      for (Integer j=this->firstCol(); j<=this->lastCol(); ++j)
        for (Integer i=this->firstRow(); i<=this->lastRow(); ++i)
        {
          this->elt(i,j) = rhs(i,j);
        }
      return *this;
    }
template<class Exp >
Array2D& STK::Array2D< Real >::operator+= ( const Exp &  rhs) [inline]

operator += Adding an Expression.

Parameters:
rhsthe right hand side expression

Definition at line 382 of file STK_Matrix.h.

References STK::IArray2D< TYPE, Array2D< TYPE > >::col(), STK::IContainer2D::firstCol(), STK::IContainer2D::lastCol(), and STK::IContainer2D::rangeVe().

    {
      for (Integer i=this->firstCol(); i<=this->lastCol(); i++)
        this->col(this->rangeVe(),i) += rhs[i];
      return *this;
    }
template<class Exp >
Array2D& STK::Array2D< Real >::operator-= ( const Exp &  rhs) [inline]

operator -= decreasing an Expression.

Parameters:
rhsthe right hand side expression

Definition at line 393 of file STK_Matrix.h.

References STK::IArray2D< TYPE, Array2D< TYPE > >::col(), STK::IContainer2D::firstCol(), STK::IContainer2D::lastCol(), and STK::IContainer2D::rangeVe().

    {
      for (Integer i=this->firstCol(); i<=this->lastCol(); i++)
        this->col(this->rangeVe(),i) -= rhs[i];
      return *this;
    }
template<class Exp >
Array2D& STK::Array2D< Real >::operator/= ( const Exp &  rhs) [inline]

operator /= Dividing an Expression.

Parameters:
rhsthe right hand side expression

Definition at line 404 of file STK_Matrix.h.

References STK::IArray2D< TYPE, Array2D< TYPE > >::col(), STK::IContainer2D::firstCol(), STK::IContainer2D::lastCol(), and STK::IContainer2D::rangeVe().

    {
      for (Integer i=this->firstCol(); i<=this->lastCol(); i++)
        this->col(this->rangeVe(),i) /= rhs[i];
      return *this;
    }
template<class Exp >
Array2D& STK::Array2D< Real >::operator*= ( const Exp &  rhs) [inline]

operator *= Multiplying an Expression.

Parameters:
rhsthe right hand side expression

Definition at line 415 of file STK_Matrix.h.

References STK::IArray2D< TYPE, Array2D< TYPE > >::col(), STK::IContainer2D::firstCol(), STK::IContainer2D::lastCol(), and STK::IContainer2D::rangeVe().

    {
      for (Integer i=this->firstCol(); i<=this->lastCol(); i++)
        this->col(this->rangeVe(),i) *= rhs[i];
      return *this;
    }

The documentation for this class was generated from the following file: