C-XSC - A C++ Class Library for Extended Scientific Computing  2.5.4
lx_civector.inl
00001 /*
00002 **  CXSC is a C++ library for eXtended Scientific Computing (V 2.5.4)
00003 **
00004 **  Copyright (C) 1990-2000 Institut fuer Angewandte Mathematik,
00005 **                          Universitaet Karlsruhe, Germany
00006 **            (C) 2000-2014 Wiss. Rechnen/Softwaretechnologie
00007 **                          Universitaet Wuppertal, Germany   
00008 **
00009 **  This library is free software; you can redistribute it and/or
00010 **  modify it under the terms of the GNU Library General Public
00011 **  License as published by the Free Software Foundation; either
00012 **  version 2 of the License, or (at your option) any later version.
00013 **
00014 **  This library is distributed in the hope that it will be useful,
00015 **  but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017 **  Library General Public License for more details.
00018 **
00019 **  You should have received a copy of the GNU Library General Public
00020 **  License along with this library; if not, write to the Free
00021 **  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00022 */
00023 
00024 namespace cxsc {
00025         
00029         inline lx_civector::lx_civector () throw():dat(NULL),l(1),u(0),size(0)
00030         { }
00031         
00037         inline lx_civector::lx_civector(int i) throw():l(1),u(i),size(i)
00038         {
00039                 dat=new lx_cinterval[i];
00040         }
00041         
00048         inline lx_civector::lx_civector(int i1, int i2)
00049 #if(CXSC_INDEX_CHECK)
00050                 throw(ERROR_IVECTOR_WRONG_BOUNDARIES,ERROR_IVECTOR_NO_MORE_MEMORY):
00051                                                                     l(i1),u(i2),size(i2-i1+1)
00052 #else
00053                 throw():l(i1),u(i2),size(i2-i1+1)
00054 #endif
00055         {
00056 #if(CXSC_INDEX_CHECK)
00057                 if(i1>i2) cxscthrow(ERROR_IVECTOR_WRONG_BOUNDARIES(
00058                                         "lx_civector(const int &i1,const int &i2)"));
00059 #endif
00060                 dat=new lx_cinterval[size];
00061         }
00062                         
00063         inline lx_civector::lx_civector(const lx_cinterval &r) throw():l(1),u(1),size(1)
00064         {
00065                 dat=new lx_cinterval[1];
00066                 *dat=r;
00067         }
00068 
00069         inline lx_civector::lx_civector(const l_cinterval &r) throw():l(1),u(1),size(1)
00070         {
00071                 dat=new lx_cinterval[1];
00072                 *dat=r;
00073         }
00074         
00075         inline lx_civector::lx_civector(const cinterval &r) throw():l(1),u(1),size(1)
00076         {
00077                 dat=new lx_cinterval[1];
00078                 *dat=r;
00079         }
00080         
00081         inline lx_civector::lx_civector(const lx_complex &r) throw():l(1),u(1),size(1)
00082         {
00083                 dat=new lx_cinterval[1];
00084                 *dat=r;
00085         }
00086 
00087         inline lx_civector::lx_civector(const l_complex &r) throw():l(1),u(1),size(1)
00088         {
00089                 dat=new lx_cinterval[1];
00090                 *dat=r;
00091         }
00092         
00093         inline lx_civector::lx_civector(const complex &r) throw():l(1),u(1),size(1)
00094         {
00095                 dat=new lx_cinterval[1];
00096                 *dat=r;
00097         }
00098         
00099         inline lx_civector::lx_civector(const lx_interval &r) throw():l(1),u(1),size(1)
00100         {
00101                 dat=new lx_cinterval[1];
00102                 *dat=r;
00103         }
00104         
00105         inline lx_civector::lx_civector(const l_interval &r) throw():l(1),u(1),size(1)
00106         {
00107                 dat=new lx_cinterval[1];
00108                 *dat=r;
00109         }       
00110         
00111         inline lx_civector::lx_civector(const interval &r) throw():l(1),u(1),size(1)
00112         {
00113                 dat=new lx_cinterval[1];
00114                 *dat=r;
00115         }
00116                 
00117         inline lx_civector::lx_civector(const lx_real &r) throw():l(1),u(1),size(1)
00118         {
00119                 dat=new lx_cinterval[1];
00120                 *dat=r;
00121         }
00122                 
00123         inline lx_civector::lx_civector(const l_real &r) throw():l(1),u(1),size(1)
00124         {
00125                 dat=new lx_cinterval[1];
00126                 *dat=r;
00127         }
00128                 
00129         inline lx_civector::lx_civector(const real &r) throw():l(1),u(1),size(1)
00130         {
00131                 dat=new lx_cinterval[1];
00132                 *dat=r;
00133         }       
00134 
00135         inline lx_civector::lx_civector(const lx_civector &v)
00136                                                            throw():l(v.l),u(v.u),size(v.size)
00137         {
00138                 dat=new lx_cinterval[size];
00139                 for (int i=0;i<size;i++)
00140                         dat[i]=v.dat[i];
00141         }
00142         
00143         inline lx_civector &lx_civector::operator =(const lx_civector &rv) throw()
00144         { 
00145                 l = rv.l; u = rv.u; size = rv.size;
00146                 dat=new lx_cinterval[size];
00147                 for (int i=0;i<size;i++)
00148                         dat[i]=rv.dat[i];
00149                 return *this;
00150         }
00151         
00152         inline lx_civector &lx_civector::operator =(const lx_cinterval &r) throw()
00153         {
00154                 lx_cinterval *newdat = new lx_cinterval[size];
00155                 for (int i=0;i<size;i++)
00156                         newdat[i] = r;
00157                 delete [] dat;
00158                 dat = newdat;
00159                 return *this;
00160         }
00161         
00162         inline lx_civector &lx_civector::operator =(const l_cinterval &r) throw()
00163         {
00164                 lx_cinterval *newdat = new lx_cinterval[size];
00165                 for (int i=0;i<size;i++)
00166                         newdat[i] = r;
00167                 delete [] dat;
00168                 dat = newdat;
00169                 return *this;
00170         }
00171         
00172         inline lx_civector &lx_civector::operator =(const cinterval &r) throw()
00173         {
00174                 lx_cinterval *newdat = new lx_cinterval[size];
00175                 for (int i=0;i<size;i++)
00176                         newdat[i] = r;
00177                 delete [] dat;
00178                 dat = newdat;
00179                 return *this;
00180         }
00181         
00182         inline lx_civector &lx_civector::operator =(const lx_complex &r) throw()
00183         {
00184                 lx_cinterval *newdat = new lx_cinterval[size];
00185                 for (int i=0;i<size;i++)
00186                         newdat[i] = r;
00187                 delete [] dat;
00188                 dat = newdat;
00189                 return *this;
00190         }
00191         
00192         inline lx_civector &lx_civector::operator =(const l_complex &r) throw()
00193         {
00194                 lx_cinterval *newdat = new lx_cinterval[size];
00195                 for (int i=0;i<size;i++)
00196                         newdat[i] = r;
00197                 delete [] dat;
00198                 dat = newdat;
00199                 return *this;
00200         }
00201         
00202         inline lx_civector &lx_civector::operator =(const complex &r) throw()
00203         {
00204                 lx_cinterval *newdat = new lx_cinterval[size];
00205                 for (int i=0;i<size;i++)
00206                         newdat[i] = r;
00207                 delete [] dat;
00208                 dat = newdat;
00209                 return *this;
00210         }
00211 
00212         inline lx_civector &lx_civector::operator =(const lx_interval &r) throw()
00213         {
00214                 lx_cinterval *newdat = new lx_cinterval[size];
00215                 for (int i=0;i<size;i++)
00216                         newdat[i] = r;
00217                 delete [] dat;
00218                 dat = newdat;
00219                 return *this;
00220         }
00221         
00222         inline lx_civector &lx_civector::operator =(const l_interval &r) throw()
00223         {
00224                 lx_cinterval *newdat = new lx_cinterval[size];
00225                 for (int i=0;i<size;i++)
00226                         newdat[i] = r;
00227                 delete [] dat;
00228                 dat = newdat;
00229                 return *this;
00230         }
00231         
00232         inline lx_civector &lx_civector::operator =(const interval &r) throw()
00233         {
00234                 lx_cinterval *newdat = new lx_cinterval[size];
00235                 for (int i=0;i<size;i++)
00236                         newdat[i] = r;
00237                 delete [] dat;
00238                 dat = newdat;
00239                 return *this;
00240         }
00241         
00242         inline lx_civector &lx_civector::operator =(const lx_real &r) throw()
00243         {
00244                 lx_cinterval *newdat = new lx_cinterval[size];
00245                 for (int i=0;i<size;i++)
00246                         newdat[i] = r;
00247                 delete [] dat;
00248                 dat = newdat;
00249                 return *this;
00250         }
00251         
00252         inline lx_civector &lx_civector::operator =(const l_real &r) throw()
00253         {
00254                 lx_cinterval *newdat = new lx_cinterval[size];
00255                 for (int i=0;i<size;i++)
00256                         newdat[i] = r;
00257                 delete [] dat;
00258                 dat = newdat;
00259                 return *this;
00260         }
00261         
00262         inline lx_civector &lx_civector::operator =(const real &r) throw()
00263         {
00264                 lx_cinterval *newdat = new lx_cinterval[size];
00265                 for (int i=0;i<size;i++)
00266                         newdat[i] = r;
00267                 delete [] dat;
00268                 dat = newdat;
00269                 return *this;
00270         }
00271         
00272         inline lx_cinterval & lx_civector::operator [](const int &i)
00273 #if(CXSC_INDEX_CHECK)
00274                 throw(ERROR_IVECTOR_ELEMENT_NOT_IN_VEC)
00275 #else
00276                 throw()
00277 #endif
00278         {
00279 #if(CXSC_INDEX_CHECK)
00280                 if(i<l||i>u) cxscthrow(ERROR_IVECTOR_ELEMENT_NOT_IN_VEC(
00281                                         "lx_cinterval & lx_civector::operator [](const int &i)"));
00282 #endif
00283                 return dat[i-l];
00284         }
00285                 
00286         inline const lx_cinterval & lx_civector::operator [](const int &i) const
00287 #if(CXSC_INDEX_CHECK)
00288                         throw(ERROR_IVECTOR_ELEMENT_NOT_IN_VEC)
00289 #else
00290                         throw()
00291 #endif
00292         {
00293 #if(CXSC_INDEX_CHECK)
00294                 if(i<l || i>u) cxscthrow(ERROR_IVECTOR_ELEMENT_NOT_IN_VEC(
00295                         "lx_cinterval & lx_civector::operator [](const int &i)"));
00296 #endif
00297                 return dat[i-l];
00298         }       
00299 
00300 inline void Resize(lx_civector &rv, int len)
00301 #if(CXSC_INDEX_CHECK)
00302                         throw(ERROR__WRONG_BOUNDARIES<lx_civector>);
00303 #else
00304         throw()
00305 #endif
00306         {
00307                 if (rv.size == len)
00308                         SetLb(rv,1);
00309                 else
00310                 {
00311 #if(CXSC_INDEX_CHECK)   
00312                         if (len<0) 
00313                                 cxscthrow(ERROR__WRONG_BOUNDARIES(
00314                                                          "Resize(lx_civector &rv, int len)"));
00315 #endif
00316                         lx_cinterval *ndat = new lx_cinterval[len];
00317                         int beg, end;
00318                         beg = (rv.l>1)? rv.l : 1;
00319                         end = (rv.u<len)? rv.u : len;
00320                         for(int i=beg-1;i<end;i++)
00321                                 ndat[i]=rv.dat[i-rv.l+1];
00322                         delete [] rv.dat;
00323                         rv.dat=ndat;
00324                         rv.size=rv.u=len;
00325                         rv.l=1;
00326                 }
00327         }
00328         
00329 inline void Resize(lx_civector &rv, int lb, int ub)
00330 #if(CXSC_INDEX_CHECK)
00331                         throw(ERROR__WRONG_BOUNDARIES<lx_civector>)
00332 #else
00333                         throw()
00334 #endif
00335 { 
00336         if (rv.size == ub-lb+1)
00337                 SetUb(rv,ub);
00338         else
00339         {
00340                 rv.size = ub-lb+1;
00341 #if(CXSC_INDEX_CHECK)
00342         if (rv.size<0)
00343                 cxscthrow(ERROR__WRONG_BOUNDARIES(
00344                                          "Resize(lx_civector &rv, int lb, int ub)"));
00345 #endif
00346                 lx_cinterval *ndat = new lx_cinterval[rv.size];
00347                 int beg, end;
00348                 beg = (rv.l>lb)? rv.l : lb;
00349                 end = (rv.u<ub)? rv.u : ub;
00350                 for(int i=0;i<=rv.size-1;i++)
00351                         ndat[i]=interval(0);
00352                 for(int i=beg;i<=end;i++)
00353                         ndat[i-lb]=rv.dat[i-rv.l];
00354                 delete [] rv.dat;
00355                 rv.dat=ndat;
00356                 rv.l=lb;
00357                 rv.u=ub;
00358         }
00359 }
00360 
00361 inline void DoubleSize(lx_civector& x) throw()
00362 {
00363         int n = Lb(x);
00364         Resize(x,n,2*Ub(x)-n+1);
00365 }
00366 
00367 } // namespace cxsc