STK++ 1.0
STK_MatrixLowerTriangular.cpp
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:  Algebra
00027  * Purpose:  Define the MatrixLowerTriangular class.
00028  * Author:   Serge Iovleff, serge.iovleff@stkpp.org
00029  *
00030  **/
00031 
00036 #include "../include/STK_MatrixLowerTriangular.h"
00037 
00038 namespace STK
00039 {
00040 /* Default constructor
00041  * @param I range of the Rows
00042  * @param J range of the Cols
00043  **/
00044 MatrixLowerTriangular::MatrixLowerTriangular( Range const& I, Range const& J)
00045                                             : _ITArray2DType(I, J)
00046                                             , defaultConst_(Real())
00047 {
00048   // initialize vertically the container
00049   this->initializeCols(J);
00050 }
00051 
00052 /* constructor with rbeg, rend, cbeg and cend specified,
00053  *  initialization with a constant.
00054  *  @param I range of the Rows
00055  *  @param J range of the Cols
00056  *  @param v initial value of the container
00057  **/
00058 MatrixLowerTriangular::MatrixLowerTriangular( Range const& I
00059                                             , Range const& J
00060                                             , Real const& v
00061                                             )
00062                                             : _ITArray2DType(I, J)
00063                                             , defaultConst_(Real())
00064 {
00065   // initialize vertically the container
00066   this->initializeCols(J);
00067   // initialize with v
00068   for (Integer j = J.first(); j <= J.last(); j++)
00069   {
00070     Real* p(this->data(j));
00071     Integer beg(this->rangeCols_[j].first());
00072     Integer end(this->rangeCols_[j].last());
00073 
00074     for (Integer i = beg; i <= end; i++) p[i] = v;
00075   }
00076 }
00077 
00078 /* Copy constructor
00079  *  @param T the container to copy
00080  *  @param ref true if T is wrapped
00081  **/
00082 MatrixLowerTriangular::MatrixLowerTriangular( const MatrixLowerTriangular &T
00083                                             , bool ref
00084                                             )
00085                                             : _ITArray2DType(T, ref)
00086                                             , defaultConst_(Real())
00087 {
00088   if (!ref)
00089   {
00090     // initialize vertically the container
00091     this->initializeCols(T.rangeHo());
00092     // initialize with T
00093     for (Integer j=T.firstCol(); j<=T.lastCol(); j++)
00094     {
00095       Real* p(this->data(j));
00096       const Real* pt= T.data(j);
00097 
00098       for (Integer i=T.firstRow(); i<=T.lastRow(); i++) p[i]= pt[i];
00099     }
00100   }
00101 }
00102 
00103 /* constructor by reference, ref_=1.
00104  *  @param T the container to wrap
00105  *  @param I range of the Rows to wrap
00106  *  @param J range of the Cols to wrap
00107  **/
00108 MatrixLowerTriangular::MatrixLowerTriangular( const _ITArray2DType& T
00109                                             , Range const& I
00110                                             , Range const& J
00111                                             )
00112                                             : _ITArray2DType(T, I, J)
00113                                             , defaultConst_(Real())
00114 { ;}
00115 
00116 /* Wrapper constructor Contruct a reference container.
00117  *  @param q pointer on the data
00118  *  @param I range of the  Rows to wrap
00119  *  @param J range of the Cols to wrap
00120  **/
00121 MatrixLowerTriangular::MatrixLowerTriangular( Real** q
00122                                             , Range const& I
00123                                             , Range const& J
00124                                             )
00125                                             : _ITArray2DType(q, I, J)
00126                                             , defaultConst_(Real())
00127 { ;}
00128 
00129 
00130 /* virtual destructor : use destructor of Array2D.                            */
00131 MatrixLowerTriangular::~MatrixLowerTriangular()
00132 { ;}
00133 
00134 
00141 MatrixLowerTriangular& MatrixLowerTriangular::operator=(const MatrixLowerTriangular &T)
00142 {
00143   // Resize if necessary.
00144   if ( (this->sizeVe() != T.sizeVe())||(this->sizeHo() != T.sizeHo()))
00145   {
00146     this->initialize(T.rangeVe(), T.rangeHo());
00147   }
00148   // coopy without overlapping
00149   if (T.firstCol()>=this->firstCol())
00150   {
00151     for ( Integer jt=T.firstCol(), j=this->firstCol()
00152         ; jt<=T.lastCol()
00153         ; j++, jt++)
00154     {
00155       Real* p(this->data(j));
00156       const Real* pt= T.data(jt);
00157       Integer beg(this->rangeCols_[j].first());
00158       Integer end(this->rangeCols_[j].last());
00159       Integer tbeg(T.rangeCols_[j].first());
00160 
00161       for (Integer i=beg, it=tbeg; i<=end; i++, it++)
00162         p[i]= pt[it];
00163     }
00164     return *this;
00165   }
00166   // T.firstCol()<this->firstCol()
00167   for ( Integer jt=T.lastCol(), j=this->lastCol()
00168       ; jt>=T.firstCol()
00169       ; j--, jt--)
00170   {
00171     Real* p(this->data(j));
00172     const Real* pt= T.data(jt);
00173     Integer beg(this->rangeCols_[j].first());
00174     Integer end(this->rangeCols_[j].last());
00175     Integer tbeg(T.rangeCols_[j].first());
00176 
00177     for (Integer i=beg, it=tbeg; i<=end; i++, it++)
00178       p[i]= pt[it];
00179   }
00180   return *this;
00181 }
00182 
00183 /* @ingroup Arrays
00184  *  ostream for MatrixLowerTriangular.
00185  *  @param s the output stream
00186  *  @param V the MatrixLowerTriangular to write
00187  **/
00188 ostream& operator<<(ostream& s, MatrixLowerTriangular const& V)
00189 { return out2D(s,V);}
00190 } // namespace STK