STK++ 1.0
STK_MatrixLowerTriangular.h
Go to the documentation of this file.
00001 /*--------------------------------------------------------------------*/
00002 /*     Copyright (C) 2004-2007  Serge Iovleff
00003 
00004     This program is free software; you can redistribute it and/or modify
00005     it under the terms of the GNU Lesser General Public License as
00006     published by the Free Software Foundation; either version 2 of the
00007     License, or (at your option) any later version.
00008 
00009     This program is distributed in the hope that it will be useful,
00010     but WITHOUT ANY WARRANTY; without even the implied warranty of
00011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012     GNU Lesser General Public License for more details.
00013 
00014     You should have received a copy of the GNU Lesser General Public
00015     License along with this program; if not, write to the
00016     Free Software Foundation, Inc.,
00017     59 Temple Place,
00018     Suite 330,
00019     Boston, MA 02111-1307
00020     USA
00021 
00022     Contact : Serge.Iovleff@stkpp.org
00023 */
00024 
00025 /*
00026  * Project:  stkpp::Arrays
00027  * Purpose:  Define the MatrixLowerTriangular class.
00028  * Author:   Serge Iovleff, serge.iovleff@stkpp.org
00029  *
00030  **/
00031 
00036 #ifndef STK_MATRIXLOWERTRIANGULAR_H
00037 #define STK_MATRIXLOWERTRIANGULAR_H
00038 
00039 #include "STK_Vector.h"
00040 #include "STK_Point.h"
00041 
00042 #include "STK_ITArray2D.h"
00043 #include "STK_Display2D.h"
00044 
00045 #include "../../Sdk/include/STK_ContainerTraits.h"
00046 
00047 namespace STK
00048 {
00049 class MatrixLowerTriangular;
00054 template<>
00055 struct ContainerTraits<Real, MatrixLowerTriangular>
00056 {
00057    typedef Point TContainerHo;
00058    typedef Vector TContainerVe;
00059 };
00060 
00061 
00071 class MatrixLowerTriangular : public ITArray2D< Real, MatrixLowerTriangular>
00072 {
00073   private:
00075     const Real defaultConst_;
00076 
00078     Real default_;
00079 
00080   public:
00082     typedef ITArray2D<Real, MatrixLowerTriangular> _ITArray2DType;
00083 
00088     MatrixLowerTriangular( Range const& I = Range(), Range const& J = Range());
00089 
00096     MatrixLowerTriangular( Range const& I, Range const& J, Real const& v);
00097 
00102     MatrixLowerTriangular( const MatrixLowerTriangular &T, bool ref=false);
00103 
00109     MatrixLowerTriangular( const _ITArray2DType& T, Range const& I, Range const& J);
00110 
00116     MatrixLowerTriangular( Real** q, Range const& I, Range const& J);
00117 
00119     virtual ~MatrixLowerTriangular();
00120 
00125     inline Integer compFirstVe( Integer const& icol) const
00126     {
00127       return max( this->firstRow()+ icol - this->firstCol(), this->firstRow());
00128     }
00129 
00134     inline Integer compLastVe( Integer const& icol) const
00135     {
00136       return this->lastRow();
00137     }
00138 
00142     inline Integer compSizeVe( Integer const& icol) const
00143     {
00144       return max(this->lastRow()-compFirstVe(icol)+1, Integer(0));
00145     }
00146 
00151     inline Range compRangeVe( Integer const& icol) const
00152     {
00153       return Range(compFirstVe(icol), this->lastRow());
00154     }
00155 
00159     inline Integer compFirstHo( Integer const& irow) const
00160     {
00161       return this->firstCol();
00162     }
00163 
00167     inline Integer compLastHo( Integer const& irow) const
00168     {
00169       return min( this->firstCol()+ irow - this->firstRow(),
00170                  this->lastCol());
00171     }
00172 
00176     inline Integer compSizeHo( Integer const& irow) const
00177     {
00178       return max(compLastHo(irow)-this->firstCol()+1, Integer(0));
00179     }
00180 
00185     inline Range compRangeHo( Integer const& irow) const
00186     {
00187       return Range(this->firstCol(), this->compLastHo(irow));
00188     }
00189 
00195     inline bool isInside(Integer const& i, Integer const& j) const
00196     {
00197       return (i>=compFirstVe(j));
00198     }
00199 
00204     inline Real& elt(Integer i, Integer j)
00205     {
00206       return isInside(i, j) ? this->data(j)[i] : default_;
00207     }
00208 
00213     inline Real const& elt(Integer i, Integer j) const
00214     {
00215       // we dont use ? : operator in order to avoid a message from the compiler:
00216       // return reference to temporary (???)
00217       if (isInside(i, j))
00218       {
00219         return this->data(j)[i];
00220       }
00221       else
00222       {
00223         return defaultConst_;
00224       }
00225     }
00226 
00231     inline MatrixLowerTriangular sub(Range const& I, Range const& J) const
00232     {
00233       return MatrixLowerTriangular(*this, I, J);
00234     }
00235 
00241     inline Vector col(Range const& I, Integer j) const
00242     {
00243       return Vector( this->data(j), Range::inf(I, compRangeVe(j)), j);
00244     }
00245 
00250     inline Vector col( Integer j) const
00251     {
00252       return Vector( this->data(j), compRangeVe(j), j);
00253     }
00254 
00260     inline Point row(Integer i, Range const& J) const
00261     {
00262       return Point(*this, Range::inf(J, compRangeHo(i)), i);
00263     }
00264 
00269     inline Point row( Integer i) const
00270     {
00271       return Point(*this, compRangeHo(i), i);
00272     }
00273 
00280     MatrixLowerTriangular& operator=( MatrixLowerTriangular const& T);
00281 
00285     inline MatrixLowerTriangular& operator=(Real const& v)
00286     {
00287       for (Integer j=this->firstCol(); j<=this->lastCol(); j++)
00288       {
00289         Real* p(this->data(j));
00290         Integer beg(this->rangeCols_[j].first());
00291         Integer end(this->rangeCols_[j].last());
00292 
00293         for (Integer i=beg; i<=end; i++) p[i]= v;
00294       }
00295       return *this;
00296     }
00297 };
00298 
00304 ostream& operator<<(ostream& s, MatrixLowerTriangular const& V);
00305 
00306 } // namespace STK
00307 
00308 #endif
00309 // STK_MATRIXLOWERTRIANGULAR_H