|
STK++ 1.0
|
00001 /*--------------------------------------------------------------------*/ 00002 /* Copyright (C) 2004-2011 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 * created on: 18 août 2011 00028 * Purpose: implementation of the diagonal matrix class. 00029 * Author: iovleff, serge.iovleff@stkpp.org 00030 * 00031 **/ 00032 00037 #ifndef STK_MATRIXDIAGONAL_H 00038 #define STK_MATRIXDIAGONAL_H 00039 00040 #include "../../Sdk/include/STK_ITContainer2D.h" 00041 #include "STK_Vector.h" 00042 00043 namespace STK 00044 { 00045 00050 class MatrixDiagonal: public ITContainer2D<Real, MatrixDiagonal> 00051 , protected Vector 00052 { 00053 typedef ITContainer2D<Real, MatrixDiagonal> ITContainer2DType; 00054 public: 00058 MatrixDiagonal( Range const& I = Range()) : ITContainer2DType(I, I) 00059 , Vector(I) 00060 , zero_(0.) 00061 { ;} 00062 00068 MatrixDiagonal( Range const& I, Real const& v) : ITContainer2DType(I) 00069 , Vector(I, v) 00070 , zero_(0.) 00071 { } 00072 00077 MatrixDiagonal( MatrixDiagonal const& T, bool ref=false) : ITContainer2DType(T) 00078 , Vector(T, ref) 00079 {} 00080 00085 MatrixDiagonal( MatrixDiagonal const& T, Range const& I) : ITContainer2DType(T) 00086 , Vector(T, I) 00087 {} 00088 00090 virtual ~MatrixDiagonal(); 00091 00095 inline Range const& range() const 00096 { return Vector::range();} 00097 00101 inline Integer const& first() const 00102 { return Vector::first();} 00103 00107 inline Integer const& last() const 00108 { return Vector::last();} 00109 00114 inline void resize( Range const& I) 00115 { resize(I, I);} 00116 00122 inline Real& elt( Integer const& i, Integer const& j) 00123 { 00124 (i==j) ? Vector::elt(i) : zero_; 00125 } 00126 00132 inline Real const& elt( Integer const& i, Integer const& j) const 00133 { 00134 (i==j) ? Vector::elt(i) : zero_; 00135 } 00136 00141 inline Vector col( Integer const& j) const 00142 { 00143 return Vector(Range(j,j), Vector::elt(j)); 00144 } 00145 00151 inline Vector col( Range const& I, Integer const& j) const 00152 { 00153 return (I.isContaining(j)) ? Vector(Range(j,j), Vector::elt(j)) : Vector(); 00154 } 00155 00160 inline Point row( Integer const& i) const 00161 { 00162 return Point(Range(i,i), Vector::elt(i)); 00163 } 00169 inline Point row( Integer const& i, Range const& J) const 00170 { 00171 return (J.isContaining(i)) ? Point(Range(i,i), Vector::elt(i)) : Point(); 00172 } 00173 00177 inline MatrixDiagonal sub(Range const& I) const 00178 { return MatrixDiagonal(*this, I);} 00179 00183 inline void shift(Integer const& beg) 00184 { shift(beg, beg);} 00185 00186 private: 00191 inline void resize( Range const& I, Range const& J) 00192 { 00193 if (I != J) 00194 { 00195 throw runtime_error("In MatrixDiagonal::resize(I,J), I!=J"); 00196 } 00197 Vector::resize(I); 00198 IContainer2D::resize(I, I); 00199 } 00200 00201 inline MatrixDiagonal sub( Range const& I, Range const& J) const 00202 { 00203 if (I != J) 00204 { 00205 throw runtime_error("In MatrixDiagonal::sub(I,J), I!=J"); 00206 } 00207 return MatrixDiagonal(*this, I); 00208 } 00212 virtual void pushBackCols( Integer const& n =1) 00213 { incRangeHo(n);} 00214 00218 virtual void popBackCols( Integer const& n =1) 00219 { decRangeHo(n); } 00220 00224 virtual void pushBackRows( Integer const& n =1) 00225 { incRangeVe(n);} 00226 00230 virtual void popBackRows( Integer const& n =1) 00231 { decRangeVe(n);} 00232 00238 virtual void shift( Integer const& rbeg, Integer const& cbeg) 00239 { 00240 if (rbeg != cbeg) 00241 { throw runtime_error("MatrixDiagonal::shift(rbeg, cbeg) " 00242 "rbeg != cbeg"); 00243 } 00244 Vector::shift(rbeg); 00245 incRangeHo(cbeg); 00246 incRangeVe(rbeg); 00247 } 00249 Real zero_; 00250 }; 00251 00252 } // namespace STK 00253 00254 #endif /* STK_MATRIXDIAGONAL_H */