STK::Inx Class Reference
[Subproject STKernel::Tcontainer]

Index sub-vector region. More...

#include <STK_Inx.h>

List of all members.

Public Member Functions

 Inx (const Integer &last=0)
 Default Ctor.
 Inx (const Integer &first, const Integer &last)
 Complete Ctor.
 Inx (const Inx &I)
 Copy Ctor.
 ~Inx ()
Integer first () const
 Return the beginning of the Inx.
Integer last () const
 Return the end ot the Inx.
Integer size () const
 Return the size of the Inx.
bool empty () const
 Return true if n<=0.
Integer begin () const
 STL compatibility : Return the beginning of the Inx.
Integer end () const
 STL compatibility : Return the strict end of the Inx.
bool isIncludeIn (const Inx &I) const
bool isContaining (const Inx &I) const
bool isContaining (const Integer &i) const
bool operator== (const Inx &I) const
bool operator!= (const Inx &I) const
Inxset (const Integer &first=1, const Integer &last=0)
 Set dimensions of the Index.
Inxshift (const Integer &first=1)
 create the Inx [first, first+size_].
Inxinc (const Integer &inc=1)
 create the Inx [first_+inc, last_+inc_].
InxincFirst (const Integer &inc=1)
 create the Inx [first_+inc, last_].
InxincLast (const Integer &inc=1)
 create the Inx [first_, last_+inc].
Inxdec (const Integer &dec=1)
 create the Inx [first_-dec, last_-dec].
InxdecFirst (const Integer &dec=1)
 create the Inx [first_-dec, last_].
InxdecLast (const Integer &dec=1)
 create the Inx [first_, last_-dec].
Inxsup (const Inx &I)
 compute sup(this,J)
Inxinf (const Inx &I)
 compute inf(this,J)
Inxoperator+= (const Integer &inc)
 same as inc()
Inxoperator-= (const Integer &dec)
 same as dec()
Inx operator+ (const Integer &inc) const
 return an Index applying inc() to this
Inx operator- (const Integer &dec) const
 return an Index applying dec() to this

Static Public Member Functions

static Inx sup (const Inx &I, const Inx &J)
 compute sup(I,J)
static Inx inf (const Inx &I, const Inx &J)
 compute inf(I,J)I

Private Attributes

Integer first_
 First index.
Integer last_
 Last index.
Integer size_
 Theoretic Dimension size_ = last_- first_ +1.

Friends

ostreamoperator<< (ostream &s, const Inx &I)
 Print a Inx.

Detailed Description

An Inx is an ordered pair [first,last] denoting a sub-vector region, similar to a Fortran 90 or Matlab colon notation. For example :

  Vector<Real> A(10), B(0,20);

  Inx I(2,4);

  A(I) = B(Inx(0,2));

overwrite the elements 2, 3 and 4 of A by the elements 0, 1 and 2 of B. There is no stride argument, only contiguous regions are allowed.

Definition at line 68 of file STK_Inx.h.


Constructor & Destructor Documentation

STK::Inx::Inx ( const Integer last = 0  ) 

The Default Ctor. Assume the beginning of the sub-region is 1.

Parameters:
last the end of the sub-region.

Definition at line 51 of file STK_Inx.cpp.

Referenced by inf(), operator+(), operator-(), and sup().

00052         : first_(1)
00053         , last_(last)
00054         , size_(last)
00055 { ;}

STK::Inx::Inx ( const Integer first,
const Integer last 
)
Parameters:
first is the beginning of the sub-region
last is the end of the sub-region.

Complete Ctor. We have to give the beginning and the end of the sub-region.

Parameters:
first the beginning of the sub-region
last the end of the sub-region.

Definition at line 62 of file STK_Inx.cpp.

00063         : first_(first)
00064         , last_(last)
00065         , size_(last-first+1)
00066 { ;}

STK::Inx::Inx ( const Inx I  ) 
Parameters:
I The index to copy

Copy Ctor. Create a copy of an existing Inx.

Parameters:
I The index to copy

Definition at line 72 of file STK_Inx.cpp.

00073         : first_(I.first())
00074         , last_(I.last())
00075         , size_(I.size())
00076 { ;}

STK::Inx::~Inx (  ) 

Dtor.

Definition at line 78 of file STK_Inx.cpp.

00078 { ;}


Member Function Documentation

Integer STK::Inx::first (  )  const [inline]
Integer STK::Inx::last (  )  const [inline]
Integer STK::Inx::size (  )  const [inline]
bool STK::Inx::empty (  )  const [inline]

Definition at line 107 of file STK_Inx.h.

References size_.

Referenced by STK::ITContainer1D< TYPE, TContainer1D >::empty(), and STK::IContainer2D< DataFrame >::empty().

00107 { return size_<=0;};

Integer STK::Inx::begin (  )  const [inline]

Definition at line 110 of file STK_Inx.h.

References first_.

00110 { return first_;};

Integer STK::Inx::end (  )  const [inline]

Definition at line 113 of file STK_Inx.h.

References last_.

Referenced by STK::ITContainer1D< TYPE, TContainer1D >::end().

00113 { return last_+1;};

bool STK::Inx::isIncludeIn ( const Inx I  )  const [inline]

Return true if this is include in I

Parameters:
I the index to compare

Definition at line 118 of file STK_Inx.h.

References first_, and last_.

00119     { return ((first_>= I.first_)&&(last_<=I.last_));}

bool STK::Inx::isContaining ( const Inx I  )  const [inline]

Return true if I is include in this

Parameters:
I the index to compare

Definition at line 124 of file STK_Inx.h.

References first_, and last_.

00125     { return ((first_<= I.first_)&&(last_>=I.last_));}

bool STK::Inx::isContaining ( const Integer i  )  const [inline]

Return true if i is element of this

Parameters:
i the integer to compare

Definition at line 130 of file STK_Inx.h.

References first_, and last_.

00131     { return ((first_<=i)&&(last_>=i));}

bool STK::Inx::operator== ( const Inx I  )  const [inline]

True if I == this

Parameters:
I the Index to compare

Definition at line 136 of file STK_Inx.h.

References first(), first_, last(), and last_.

00137     { return ((first_ == I.first()) && (last_ == I.last()));}

bool STK::Inx::operator!= ( const Inx I  )  const [inline]

True if I != this

Parameters:
I the Inx to compare

Definition at line 142 of file STK_Inx.h.

References first(), first_, last(), and last_.

00143     { return ((first_ != I.first()) || (last_ != I.last()));}

Inx & STK::Inx::set ( const Integer first = 1,
const Integer last = 0 
)

Set new range for the index.

Parameters:
first first element
last last element

Definition at line 86 of file STK_Inx.cpp.

References first_, last_, and size_.

00087 {
00088   first_ = first;
00089   last_  = last;
00090   size_     = last - first + 1;
00091   return *this;
00092 }

Inx & STK::Inx::shift ( const Integer first = 1  ) 

Shift the Inx giving the first element : the size is not modified.

Parameters:
first new value of the first element

Definition at line 97 of file STK_Inx.cpp.

References first_, and inc().

Referenced by STK::IContainer2D< DataFrame >::setFirstHo(), and STK::IContainer2D< DataFrame >::setFirstVe().

00098 {
00099   return inc(first - first_); // use the inc method
00100 }

Inx & STK::Inx::inc ( const Integer inc = 1  ) 

Increase first_ and last_

Parameters:
inc the increment to apply

Definition at line 105 of file STK_Inx.cpp.

References first_, and last_.

Referenced by STK::ITContainer1D< TYPE, TContainer1D >::incRange(), STK::IContainer2D< DataFrame >::incRangeHo(), STK::IContainer2D< DataFrame >::incRangeVe(), and shift().

00106 {
00107   first_ +=inc;
00108   last_  +=inc;
00109   return *this;
00110 }

Inx & STK::Inx::incFirst ( const Integer inc = 1  ) 

Increase first_

Parameters:
inc the increment to apply

Definition at line 114 of file STK_Inx.cpp.

References first_, and size_.

Referenced by STK::Svd::bidiag(), STK::ITContainer1D< TYPE, TContainer1D >::incFirst(), STK::IContainer2D< DataFrame >::incFirstHo(), STK::IContainer2D< DataFrame >::incFirstVe(), and STK::Eigenvalues::tridiag().

00115 {
00116   first_ +=inc;
00117   size_     -=inc;
00118   return *this;
00119 }

Inx & STK::Inx::incLast ( const Integer inc = 1  ) 
Inx & STK::Inx::dec ( const Integer dec = 1  ) 

Decrease first_ and last_

Parameters:
dec the decrement to apply

Definition at line 133 of file STK_Inx.cpp.

References first_, and last_.

Referenced by STK::IContainer2D< DataFrame >::decRangeHo(), and STK::IContainer2D< DataFrame >::decRangeVe().

00134 {
00135   first_ -=dec;
00136   last_  -=dec;
00137   return *this;
00138 }

Inx & STK::Inx::decFirst ( const Integer dec = 1  ) 

Decrease first_

Parameters:
dec the decrement to apply

Definition at line 142 of file STK_Inx.cpp.

References first_, and size_.

Referenced by STK::Svd::compV(), STK::ITContainer1D< TYPE, TContainer1D >::decFirst(), STK::IContainer2D< DataFrame >::decFirstHo(), and STK::IContainer2D< DataFrame >::decFirstVe().

00143 {
00144   first_ -=dec;
00145   size_     +=dec;
00146   return *this;
00147 }

Inx & STK::Inx::decLast ( const Integer dec = 1  ) 

Decrease last_

Parameters:
dec the decrement to apply

Definition at line 151 of file STK_Inx.cpp.

References last_, and size_.

Referenced by STK::ITContainer1D< TYPE, TContainer1D >::decLast(), STK::IContainer2D< DataFrame >::decLastHo(), and STK::IContainer2D< DataFrame >::decLastVe().

00152 {
00153   last_ -=dec;
00154   size_    -=dec;
00155   return *this;
00156 }

Inx & STK::Inx::sup ( const Inx I  ) 

Take the lowest value of first_ and I.first_ for first_ and the largest value of last_ and I.last_ for last_.

Parameters:
I the index to apply

Definition at line 162 of file STK_Inx.cpp.

References first_, last_, STK::max(), STK::min(), and size_.

Referenced by STK::IContainer2D< DataFrame >::supHo(), and STK::IContainer2D< DataFrame >::supve().

00163 {
00164   first_ = min(first_, I.first_);
00165   last_  = max(last_, I.last_);
00166   size_     = last_ - first_ +1;
00167   return *this;
00168 }

Inx & STK::Inx::inf ( const Inx I  ) 

Take the largest value of first_ and I.first_ for first_ and the lowest value of last_ and I.last_ for last_.

Parameters:
I the index to apply

Definition at line 174 of file STK_Inx.cpp.

References first_, last_, STK::max(), STK::min(), and size_.

Referenced by STK::MatrixUpperTriangular::getCol(), STK::MatrixLowerTriangular::getCol(), STK::MatrixUpperTriangular::getRow(), STK::MatrixLowerTriangular::getRow(), STK::IArray2DBase< Real, Real *, ArrayHo< Real >, Array1D< Real >, MatrixUpperTriangular >::IArray2DBase(), STK::IContainer2D< DataFrame >::infHo(), and STK::IContainer2D< DataFrame >::infVe().

00175 {
00176   first_ = max(first_, I.first_);
00177   last_  = min(last_, I.last_);
00178   size_     = last_ - first_ +1;
00179   return *this;
00180 }

Inx STK::Inx::sup ( const Inx I,
const Inx J 
) [static]

Take the lowest value of I.first_ and J.first_ for first_ and the largest value of I.last_ and J.last_ for last_.

Parameters:
I first the index to apply
J second the index to apply

Definition at line 186 of file STK_Inx.cpp.

References first_, Inx(), last_, STK::max(), and STK::min().

00187 {
00188   return Inx(min(I.first_, J.first_), max(I.last_, J.last_));
00189 }

Inx STK::Inx::inf ( const Inx I,
const Inx J 
) [static]

Take the largest value of I.first_ and J.first_ for first_ and the lowest value of I.last_ and J.last_ for last_.

Parameters:
I first the index to apply
J second the index to apply

Definition at line 196 of file STK_Inx.cpp.

References first_, Inx(), last_, STK::max(), and STK::min().

00197 {
00198   return Inx(max(I.first_, J.first_), min(I.last_, J.last_));
00199 }

Inx & STK::Inx::operator+= ( const Integer inc  ) 

Increase first_ and last_

Parameters:
inc the increment to apply

Definition at line 206 of file STK_Inx.cpp.

References first_, and last_.

00207 { first_ += inc; last_ += inc; return *this;}

Inx & STK::Inx::operator-= ( const Integer dec  ) 

Decrease first_ and last_

Parameters:
dec the decrement to apply

Definition at line 212 of file STK_Inx.cpp.

References first_, and last_.

00213 { first_ -= dec; last_ -= dec; return *this;}

Inx STK::Inx::operator+ ( const Integer inc  )  const

Increase first_ and last_ and return a new index

Parameters:
inc the increment to apply

Definition at line 219 of file STK_Inx.cpp.

References first_, Inx(), and last_.

00220 {return Inx(first_+inc, last_+inc);}

Inx STK::Inx::operator- ( const Integer dec  )  const

Decrease first_ and last_ and return a new index

Parameters:
dec the decrement to apply

Definition at line 225 of file STK_Inx.cpp.

References first_, Inx(), and last_.

00226 {return Inx(first_-dec, last_-dec);}


Friends And Related Function Documentation

ostream& operator<< ( ostream s,
const Inx I 
) [friend]

Print a Inx using the colon notation.

Parameters:
s output stream
I the Inx to write

Definition at line 232 of file STK_Inx.cpp.

00233 {
00234   s << I.first_ << ":" << I.last_;
00235   return s;
00236 }


Member Data Documentation

Definition at line 73 of file STK_Inx.h.

Referenced by decFirst(), decLast(), empty(), incFirst(), incLast(), inf(), set(), size(), and sup().


The documentation for this class was generated from the following files:
Generated on Sat Sep 18 17:27:08 2010 for STK++ by  doxygen 1.6.3