STK++ 1.0
STK::Range Class Reference

Index sub-vector region. More...

#include <STK_Range.h>

Collaboration diagram for STK::Range:

List of all members.

Public Member Functions

 Range (Integer const &last=0)
 Default constructor.
 Range (Integer const &first, Integer const &last)
 Complete constructor.
 Range (Range const &I)
 Copy constructor.
 ~Range ()
 destructor.
Integer const & first () const
 get the first index of the Range
Integer const & last () const
 get the last index of the Range
Integer const & size () const
 get the size of the Range (the number of elements)
bool empty () const
 check if the range is empty or not
bool isIn (Range const &I) const
 check if this Range in include in an other Range
bool isContaining (Range const &I) const
 check if the Range I is include in the this Range
bool isContaining (Integer const &i) const
 Return true if i is in this Range.
bool operator== (Range const &I) const
 compare this range with range I
bool operator!= (Range const &I) const
 compare this range with range I
Rangeset (Integer const &first=1, Integer const &last=0)
 Set dimensions of the Index.
Rangeshift (Integer const &first=1)
 create the Range [first, first+size_].
Rangeinc (Integer const &inc=1)
 create the Range [first_+inc, last_+inc_].
RangeincFirst (Integer const &inc=1)
 create the Range [first_+inc, last_].
RangeincLast (Integer const &inc=1)
 create the Range [first_, last_+inc].
Rangedec (Integer const &dec=1)
 create the Range [first_-dec, last_-dec].
RangedecFirst (Integer const &dec=1)
 create the Range [first_-dec, last_].
RangedecLast (Integer const &dec=1)
 create the Range [first_, last_-dec].
Rangesup (Range const &I)
 compute sup(this,J)
Rangeinf (Range const &I)
 compute inf(this,J)
Rangeoperator+= (Integer const &inc)
 same as Range::inc()
Rangeoperator-= (Integer const &dec)
 same as Range::dec()
Range plus (Integer const &inc=1)
 create the Range [first_+inc, last_+inc_].
Range minus (Integer const &dec=1)
 create the Range [first_-dec, last_-dec].

Static Public Member Functions

static Range sup (Range const &I, Range const &J)
 compute sup(I,J)
static Range inf (Range const &I, Range const &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, Range const &I)
 Write a Range in the form first:last (MATLAB-like form) in an output stream.
istreamoperator>> (istream &s, Range &I)
 Read a Range in the form first:last (MATLAB-like form) from an input stream.

Detailed Description

Index sub-vector region.

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

  Vector A(10), B(0,20);

  Range I(2,4);

  A(I) = B(Range(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 62 of file STK_Range.h.


Constructor & Destructor Documentation

STK::Range::Range ( Integer const &  last = 0)

Default constructor.

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

The first index is 1.

Parameters:
lastthe last index of the range
lastthe end of the sub-region.

Definition at line 48 of file STK_Range.cpp.

Referenced by inf(), and sup().

        : first_(1)
        , last_(last)
        , size_(last)
{ ;}
STK::Range::Range ( Integer const &  first,
Integer const &  last 
)

Complete constructor.

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

Parameters:
firstis the beginning of the sub-region
lastis the end of the sub-region.
firstthe beginning of the sub-region
lastthe end of the sub-region.

Definition at line 59 of file STK_Range.cpp.

        : first_(first)
        , last_(last)
        , size_(last-first+1)
{ ;}
STK::Range::Range ( Range const &  I)

Copy constructor.

Copy constructor Create a copy of an existing Range.

Parameters:
IThe index to copy

Definition at line 69 of file STK_Range.cpp.

        : first_(I.first())
        , last_(I.last())
        , size_(I.size())
{ ;}
STK::Range::~Range ( )

destructor.

Definition at line 75 of file STK_Range.cpp.

{ ;}

Member Function Documentation

Integer const& STK::Range::first ( ) const [inline]

get the first index of the Range

Returns:
the first index of the range

Definition at line 92 of file STK_Range.h.

References first_.

Referenced by STK::Array2D< Real >::Array2D(), STK::Array2D< Integer >::Array2D(), STK::ITContainer2D< Integer, Array2D< Integer > >::at(), STK::ITContainer2D< Integer, Array2D< Integer > >::atCol(), STK::ITContainer2D< Integer, Array2D< Integer > >::atRow(), STK::CArray2D< TYPE >::CArray2D(), STK::Stat::Bivariate< Real, Real, TContainer1D >::compCovariance(), STK::CArray2D< TYPE >::compFirstData(), STK::LocalVariance::computeAxis(), STK::Stat::Bivariate< Real, Real, TContainer1D >::compWeightedCovariance(), STK::Stat::covariance(), STK::Stat::covarianceWithFixedMean(), STK::Array1D< Real >::elt(), STK::Variable< String >::elt(), STK::List1D< IVariable * >::elt(), STK::Array1D< Variable< String > >::elt(), STK::ITArray2D< Integer, Array2D< Integer > >::eraseRowsToCol(), STK::ITContainer1D< TYPE, List1D< TYPE > >::first(), STK::IContainer2D::firstCol(), STK::AllocatorBase< TYPE * >::firstData(), STK::IContainer2D::firstRow(), STK::ITArray2D< Integer, Array2D< Integer > >::freeCols(), STK::ArrayHo< Real >::freeElts(), STK::ArrayHo< TYPE >::freeElts(), STK::IArray1DBase< Range, Range, Array1D< Range > >::IArray1DBase(), STK::IArray1DBase< Range, Range, Array1D< Range > >::init1D(), STK::ArrayHo< Real >::initElts(), STK::ArrayHo< TYPE >::initElts(), STK::ITArray2D< Integer, Array2D< Integer > >::initializeCol(), STK::ITArray2D< Integer, Array2D< Integer > >::initializeCols(), STK::List1D< IVariable * >::insert(), STK::IArray1DBase< Range, Range, Array1D< Range > >::insert(), STK::ITArray2D< Integer, Array2D< Integer > >::insertRowsToCol(), STK::ITArray2DBase< TYPE, TYPE *, TArray2D >::ITArray2DBase(), STK::ITArray2DBase< TYPE, TYPE *, TArray2D >::mallocHo(), STK::MatrixLowerTriangular::MatrixLowerTriangular(), STK::MatrixUpperTriangular::MatrixUpperTriangular(), operator!=(), STK::operator+(), STK::operator-(), operator==(), STK::ITArray2D< Integer, Array2D< Integer > >::pushBackRowsToCol(), STK::ITArray2DBase< TYPE, TYPE *, TArray2D >::reallocHo(), STK::RecursiveArray2D< TYPE, Container2D >::RecursiveArray2D(), STK::IContainer2D::resize(), STK::IContainer1D::resize(), STK::ITArray2D< Integer, Array2D< Integer > >::resizeCol(), set(), and STK::ITArray2D< Integer, Array2D< Integer > >::update().

{ return first_;};
Integer const& STK::Range::last ( ) const [inline]

get the last index of the Range

Returns:
the last index of the range

Definition at line 96 of file STK_Range.h.

References last_.

Referenced by STK::Array2D< Real >::Array2D(), STK::Array2D< Integer >::Array2D(), STK::ITContainer2D< Integer, Array2D< Integer > >::at(), STK::ITContainer2D< Integer, Array2D< Integer > >::atCol(), STK::ITContainer2D< Integer, Array2D< Integer > >::atRow(), STK::CArray2D< TYPE >::CArray2D(), STK::Stat::Bivariate< Real, Real, TContainer1D >::compCovariance(), STK::LocalVariance::computeAxis(), STK::Stat::Bivariate< Real, Real, TContainer1D >::compWeightedCovariance(), STK::Stat::covariance(), STK::Stat::covarianceWithFixedMean(), STK::Array1D< Real >::elt(), STK::Variable< String >::elt(), STK::List1D< IVariable * >::elt(), STK::Array1D< Variable< String > >::elt(), STK::ITArray2D< Integer, Array2D< Integer > >::eraseRowsToCol(), STK::ITArray2D< Integer, Array2D< Integer > >::freeCols(), STK::ArrayHo< Real >::freeElts(), STK::ArrayHo< TYPE >::freeElts(), STK::IArray1DBase< Range, Range, Array1D< Range > >::IArray1DBase(), STK::ArrayHo< Real >::initElts(), STK::ArrayHo< TYPE >::initElts(), STK::ITArray2D< Integer, Array2D< Integer > >::initializeCols(), STK::List1D< IVariable * >::insert(), STK::IArray1DBase< Range, Range, Array1D< Range > >::insert(), STK::ITArray2D< Integer, Array2D< Integer > >::insertRowsToCol(), STK::ITArray2DBase< TYPE, TYPE *, TArray2D >::ITArray2DBase(), STK::ITContainer1D< TYPE, List1D< TYPE > >::last(), STK::IContainer2D::lastCol(), STK::AllocatorBase< TYPE * >::lastData(), STK::IContainer2D::lastRow(), STK::MatrixLowerTriangular::MatrixLowerTriangular(), STK::MatrixUpperTriangular::MatrixUpperTriangular(), operator!=(), STK::operator+(), STK::operator-(), operator==(), STK::ITArray2DBase< TYPE, TYPE *, TArray2D >::pushBackByTransfer(), STK::ITArray2D< Integer, Array2D< Integer > >::pushBackRows(), STK::ITArray2D< Integer, Array2D< Integer > >::pushBackRowsToCol(), STK::RecursiveArray2D< TYPE, Container2D >::RecursiveArray2D(), STK::IContainer2D::resize(), STK::IContainer1D::resize(), set(), and STK::ITArray2D< Integer, Array2D< Integer > >::update().

{ return last_;};
bool STK::Range::empty ( ) const [inline]

check if the range is empty or not

Returns:
true if size <=0, false otherwise

Definition at line 104 of file STK_Range.h.

References size_.

Referenced by STK::Stat::covariance(), STK::Stat::covarianceWithFixedMean(), STK::IContainer2D::empty(), and STK::IContainer1D::empty().

{ return size_<=0;};
bool STK::Range::isIn ( Range const &  I) const [inline]

check if this Range in include in an other Range

Parameters:
Ithe index to compare
Returns:
true if this is include in I, false otherwise

Definition at line 109 of file STK_Range.h.

References first_, and last_.

Referenced by STK::Stat::center(), STK::Stat::covariance(), STK::Stat::covarianceWithFixedMean(), STK::weightedDist(), STK::weightedDot(), STK::weightedNormInf(), STK::weightedNormTwo(), STK::weightedNormTwo2(), and STK::weightedSum().

    { return ((first_>= I.first_)&&(last_<=I.last_));}
bool STK::Range::isContaining ( Range const &  I) const [inline]

check if the Range I is include in the this Range

Parameters:
Ithe index to compare
Returns:
true if this contain I, false otherwise

Definition at line 115 of file STK_Range.h.

References first_, and last_.

    { return ((first_<= I.first_)&&(last_>=I.last_));}
bool STK::Range::isContaining ( Integer const &  i) const [inline]

Return true if i is in this Range.

Parameters:
ithe integer to compare
Returns:
true if i is in this, false otherwise

Definition at line 121 of file STK_Range.h.

References first_, and last_.

    { return ((first_<=i)&&(last_>=i));}
bool STK::Range::operator== ( Range const &  I) const [inline]

compare this range with range I

Parameters:
Ithe Index to compare
Returns:
true if the range are equals, false otherwise

Definition at line 127 of file STK_Range.h.

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

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

Here is the call graph for this function:

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

compare this range with range I

Parameters:
Ithe Index to compare
Returns:
true if the range are different, false otherwise

Definition at line 133 of file STK_Range.h.

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

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

Here is the call graph for this function:

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

Set dimensions of the Index.

Set new range for the index.

Parameters:
firstfirst element
lastlast element

Definition at line 83 of file STK_Range.cpp.

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

{
  first_ = first;
  last_  = last;
  size_     = last - first + 1;
  return *this;
}

Here is the call graph for this function:

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

create the Range [first, first+size_].

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

Parameters:
firstnew value of the first element

Definition at line 94 of file STK_Range.cpp.

References first_, and inc().

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

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

Here is the call graph for this function:

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

create the Range [first_+inc, last_+inc_].

Increase first_ and last_.

Parameters:
incthe increment to apply

Definition at line 102 of file STK_Range.cpp.

References first_, and last_.

Referenced by STK::AllocatorBase< TYPE * >::decPtrData(), incFirst(), incLast(), STK::ITContainer1D< TYPE, List1D< TYPE > >::incRange(), STK::IContainer2D::incRangeHo(), STK::IContainer2D::incRangeVe(), operator+=(), plus(), and shift().

{
  first_ +=inc;
  last_  +=inc;
  return *this;
}
Range & STK::Range::incFirst ( Integer const &  inc = 1)

create the Range [first_+inc, last_].

Increase first_.

Parameters:
incthe increment to apply

Definition at line 111 of file STK_Range.cpp.

References first_, inc(), and size_.

Referenced by STK::Svd::bidiag(), STK::ITContainer1D< TYPE, List1D< TYPE > >::incFirst(), STK::IContainer2D::incFirstHo(), STK::IContainer2D::incFirstVe(), and STK::EigenvaluesSymmetric::tridiagonalize().

{
  first_ +=inc;
  size_     -=inc;
  return *this;
}

Here is the call graph for this function:

Range & STK::Range::dec ( Integer const &  dec = 1)

create the Range [first_-dec, last_-dec].

Decrease first_ and last_.

Parameters:
decthe decrement to apply

Definition at line 130 of file STK_Range.cpp.

References first_, and last_.

Referenced by decFirst(), decLast(), STK::IContainer2D::decRangeHo(), STK::IContainer2D::decRangeVe(), STK::AllocatorBase< TYPE * >::incPtrData(), minus(), and operator-=().

{
  first_ -=dec;
  last_  -=dec;
  return *this;
}
Range & STK::Range::decFirst ( Integer const &  dec = 1)

create the Range [first_-dec, last_].

Decrease first_.

Parameters:
decthe decrement to apply

Definition at line 139 of file STK_Range.cpp.

References dec(), first_, and size_.

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

{
  first_ -=dec;
  size_     +=dec;
  return *this;
}

Here is the call graph for this function:

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

create the Range [first_, last_-dec].

Decrease last_.

Parameters:
decthe decrement to apply

Definition at line 148 of file STK_Range.cpp.

References dec(), last_, and size_.

Referenced by STK::ITContainer1D< TYPE, List1D< TYPE > >::decLast(), STK::IContainer2D::decLastHo(), STK::IContainer2D::decLastVe(), and STK::ITArray2D< Integer, Array2D< Integer > >::eraseRowsToCol().

{
  last_ -=dec;
  size_    -=dec;
  return *this;
}

Here is the call graph for this function:

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

compute sup(this,J)

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

Parameters:
Ithe index to apply

Definition at line 159 of file STK_Range.cpp.

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

{
  first_ = min(first_, I.first_);
  last_  = max(last_, I.last_);
  size_     = last_ - first_ +1;
  return *this;
}

Here is the call graph for this function:

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

compute inf(this,J)

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

Parameters:
Ithe index to apply

Definition at line 171 of file STK_Range.cpp.

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

Referenced by STK::MatrixUpperTriangular::col(), STK::MatrixLowerTriangular::col(), STK::Stat::Bivariate< Real, Real, TContainer1D >::compCovariance(), STK::Stat::Bivariate< Real, Real, TContainer1D >::compWeightedCovariance(), STK::Stat::covariance(), STK::Stat::covarianceWithFixedMean(), STK::ITArray2DBase< TYPE, TYPE *, TArray2D >::ITArray2DBase(), STK::MatrixUpperTriangular::row(), and STK::MatrixLowerTriangular::row().

{
  first_ = max(first_, I.first_);
  last_  = min(last_, I.last_);
  size_     = last_ - first_ +1;
  return *this;
}

Here is the call graph for this function:

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

same as Range::inc()

Increase first_ and last_.

Parameters:
incthe increment to apply

Definition at line 213 of file STK_Range.cpp.

References first_, inc(), and last_.

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

Here is the call graph for this function:

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

same as Range::dec()

Decrease first_ and last_.

Parameters:
decthe decrement to apply

Definition at line 219 of file STK_Range.cpp.

References dec(), first_, and last_.

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

Here is the call graph for this function:

Range STK::Range::plus ( Integer const &  inc = 1)

create the Range [first_+inc, last_+inc_].

Definition at line 199 of file STK_Range.cpp.

References inc().

{
  return *this+inc;
}

Here is the call graph for this function:

Range STK::Range::minus ( Integer const &  dec = 1)

create the Range [first_-dec, last_-dec].

Definition at line 204 of file STK_Range.cpp.

References dec().

{
  return *this-dec;
;
}

Here is the call graph for this function:

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

compute sup(I,J)

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:
Ifirst the index to apply
Jsecond the index to apply

Definition at line 183 of file STK_Range.cpp.

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

{
  return Range(min(I.first_, J.first_), max(I.last_, J.last_));
}

Here is the call graph for this function:

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

compute inf(I,J)I

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:
Ifirst the index to apply
Jsecond the index to apply

Definition at line 193 of file STK_Range.cpp.

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

{
  return Range(max(I.first_, J.first_), min(I.last_, J.last_));
}

Here is the call graph for this function:


Friends And Related Function Documentation

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

Write a Range in the form first:last (MATLAB-like form) in an output stream.

Parameters:
soutput stream
Ithe Range to write

Definition at line 226 of file STK_Range.cpp.

{
  s << I.first_ << _T(":") << I.last_;
  return s;
}
istream& operator>> ( istream s,
Range I 
) [friend]

Read a Range in the form first:last (MATLAB-like form) from an input stream.

The input stream can also be a number (say n). In this case the range will be 1:n. If the range cannot be read the method return the default range 1:0. FIXME? should be NA value, but NA value is not defined for Range.

Parameters:
sthe input stream
Ithe range to set

Definition at line 240 of file STK_Range.cpp.

{
  String num;
  s >> std::skipws;
  // get first number
  std::getline(s, num, _T(':'));
  // check if the istream is exhausted
  if (s.eof())
  {
    I.first_ = 1;
    if (!stringToType(I.last_, num)) I.last_ =0;
    return s;
  }
  // otherwise we encounter a ":", thus skip the current char
  if (!stringToType(I.first_, num)) I.first_ =1;
  s.peek();
  if ((s >> I.last_).fail())
  {
    I.first_ =1; I.last_ =0;
  }
  return s;
}

Member Data Documentation

Theoretic Dimension size_ = last_- first_ +1.

Definition at line 67 of file STK_Range.h.

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


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