|
matrix.h00001 // 00002 // matrix.h 00003 // 00004 // Copyright (C) 1996 Limit Point Systems, Inc. 00005 // 00006 // Author: Curtis Janssen <cljanss@limitpt.com> 00007 // Maintainer: LPS 00008 // 00009 // This file is part of the SC Toolkit. 00010 // 00011 // The SC Toolkit is free software; you can redistribute it and/or modify 00012 // it under the terms of the GNU Library General Public License as published by 00013 // the Free Software Foundation; either version 2, or (at your option) 00014 // any later version. 00015 // 00016 // The SC Toolkit is distributed in the hope that it will be useful, 00017 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 // GNU Library General Public License for more details. 00020 // 00021 // You should have received a copy of the GNU Library General Public License 00022 // along with the SC Toolkit; see the file COPYING.LIB. If not, write to 00023 // the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 00024 // 00025 // The U.S. Government is granted a limited license as per AL 91-7. 00026 // 00027 00028 #ifndef _math_scmat_matrix_h 00029 #define _math_scmat_matrix_h 00030 #ifdef __GNUC__ 00031 #pragma interface 00032 #endif 00033 00034 #include <iostream> 00035 #include <util/container/array.h> 00036 00037 #include <math/scmat/abstract.h> 00038 00039 namespace sc { 00040 00041 class SCVectordouble; 00042 class SCMatrixdouble; 00043 class SymmSCMatrixdouble; 00044 class DiagSCMatrixdouble; 00045 00046 class SCMatrixBlockIter; 00047 class SCMatrixRectBlock; 00048 class SCMatrixLTriBlock; 00049 class SCMatrixDiagBlock; 00050 class SCVectorSimpleBlock; 00051 00052 class RefSCMatrix; 00053 class RefSymmSCMatrix; 00056 class RefSCVector: public Ref<SCVector> { 00057 // standard overrides 00058 public: 00061 RefSCVector(); 00063 RefSCVector(const RefSCVector& v); 00065 RefSCVector(SCVector *v); 00066 // don't allow automatic conversion from any reference to a 00067 // described class 00068 ~RefSCVector(); 00070 RefSCVector& operator=(SCVector* v); 00072 RefSCVector& operator=(const RefSCVector& v); 00073 00074 // vector specific members 00075 public: 00078 RefSCVector(const RefSCDimension& dim,const Ref<SCMatrixKit>&); 00079 00081 SCVectordouble operator()(int) const; 00083 SCVectordouble operator[](int) const; 00085 RefSCVector operator+(const RefSCVector&a) const; 00087 RefSCVector operator-(const RefSCVector&a) const; 00089 RefSCVector operator*(double) const; 00091 RefSCMatrix outer_product(const RefSCVector& v) const; 00093 RefSymmSCMatrix symmetric_outer_product() const; 00094 00095 void set_element(int i,double val) const; 00096 void accumulate_element(int i,double val) const; 00097 double get_element(int) const; 00098 int n() const; 00099 RefSCDimension dim() const; 00100 Ref<SCMatrixKit> kit() const; 00101 RefSCVector clone() const; 00102 RefSCVector copy() const; 00103 double maxabs() const; 00104 double scalar_product(const RefSCVector&) const; 00105 double dot(const RefSCVector&) const; 00106 void normalize() const; 00107 void randomize() const; 00108 void assign(const RefSCVector& v) const; 00109 void assign(double val) const; 00110 void assign(const double* v) const; 00111 void convert(double*) const; 00112 void scale(double val) const; 00113 void accumulate(const RefSCVector& v) const; 00114 void accumulate_product(const RefSymmSCMatrix&, const RefSCVector&); 00115 void accumulate_product(const RefSCMatrix&, const RefSCVector&); 00116 void element_op(const Ref<SCElementOp>& op) const; 00117 void element_op(const Ref<SCElementOp2>&, 00118 const RefSCVector&) const; 00119 void element_op(const Ref<SCElementOp3>&, 00120 const RefSCVector&, 00121 const RefSCVector&) const; 00122 void print(std::ostream&out) const; 00123 void print(const char*title=0, 00124 std::ostream&out=ExEnv::out0(), int precision=10) const; 00125 void save(StateOut&); 00126 void restore(StateIn&); 00127 }; 00128 RefSCVector operator*(double,const RefSCVector&); 00129 00130 class RefSymmSCMatrix; 00131 class RefDiagSCMatrix; 00135 class RefSCMatrix: public Ref<SCMatrix> { 00136 // standard overrides 00137 public: 00140 RefSCMatrix(); 00142 RefSCMatrix(const RefSCMatrix& m); 00144 RefSCMatrix(SCMatrix* m); 00145 ~RefSCMatrix(); 00147 RefSCMatrix& operator=(SCMatrix* m); 00149 RefSCMatrix& operator=(const RefSCMatrix& m); 00150 00151 // matrix specific members 00152 public: 00155 RefSCMatrix(const RefSCDimension& d1,const RefSCDimension& d2, 00156 const Ref<SCMatrixKit>&); 00157 00159 RefSCVector operator*(const RefSCVector&) const; 00160 00162 RefSCMatrix operator*(const RefSCMatrix&) const; 00163 RefSCMatrix operator*(const RefSymmSCMatrix&) const; 00164 RefSCMatrix operator*(const RefDiagSCMatrix&) const; 00165 00167 RefSCMatrix operator*(double) const; 00168 00170 RefSCMatrix operator+(const RefSCMatrix&) const; 00172 RefSCMatrix operator-(const RefSCMatrix&) const; 00173 00175 RefSCMatrix t() const; 00177 RefSCMatrix i() const; 00179 RefSCMatrix gi() const; 00180 00183 RefSCMatrix clone() const; 00184 RefSCMatrix copy() const; 00185 00186 RefSCMatrix get_subblock(int br, int er, int bc, int ec); 00187 void assign_subblock(const RefSCMatrix&, int br, int er, int bc, int ec, 00188 int source_br = 0, int source_bc = 0); 00189 void accumulate_subblock(const RefSCMatrix&, int, int, int, int, 00190 int source_br = 0, int source_bc = 0); 00191 RefSCVector get_row(int) const; 00192 RefSCVector get_column(int) const; 00193 void assign_row(const RefSCVector&, int) const; 00194 void assign_column(const RefSCVector&, int) const; 00195 void accumulate_row(const RefSCVector&, int) const; 00196 void accumulate_column(const RefSCVector&, int) const; 00197 00198 void accumulate_outer_product(const RefSCVector&,const RefSCVector&) const; 00199 void accumulate_product(const RefSCMatrix&,const RefSCMatrix&) const; 00200 void assign(const RefSCMatrix&) const; 00201 void scale(double) const; 00202 void randomize() const; 00203 void assign(double) const; 00204 void assign(const double*) const; 00205 void assign(const double**) const; 00206 void convert(double*) const; 00207 void convert(double**) const; 00208 void accumulate(const RefSCMatrix&) const; 00209 void accumulate(const RefSymmSCMatrix&) const; 00210 void accumulate(const RefDiagSCMatrix&) const; 00211 void element_op(const Ref<SCElementOp>&) const; 00212 void element_op(const Ref<SCElementOp2>&, 00213 const RefSCMatrix&) const; 00214 void element_op(const Ref<SCElementOp3>&, 00215 const RefSCMatrix&, 00216 const RefSCMatrix&) const; 00217 int nrow() const; 00218 int ncol() const; 00219 RefSCDimension rowdim() const; 00220 RefSCDimension coldim() const; 00221 Ref<SCMatrixKit> kit() const; 00222 void set_element(int,int,double) const; 00223 void accumulate_element(int,int,double) const; 00224 double get_element(int,int) const; 00225 void print(std::ostream&) const; 00226 void print(const char*title=0, 00227 std::ostream&out=ExEnv::out0(), int =10) const; 00228 double trace() const; 00229 void save(StateOut&); 00230 void restore(StateIn&); 00231 00236 void svd(const RefSCMatrix &U, 00237 const RefDiagSCMatrix &sigma, 00238 const RefSCMatrix &V); 00240 double solve_lin(const RefSCVector& v) const; 00242 double determ() const; 00244 SCMatrixdouble operator()(int i,int j) const; 00245 }; 00247 RefSCMatrix operator*(double,const RefSCMatrix&); 00248 00251 class RefSymmSCMatrix: public Ref<SymmSCMatrix> { 00252 // standard overrides 00253 public: 00256 RefSymmSCMatrix(); 00258 RefSymmSCMatrix(const RefSymmSCMatrix& m); 00260 RefSymmSCMatrix(SymmSCMatrix *m); 00261 ~RefSymmSCMatrix(); 00263 RefSymmSCMatrix& operator=(SymmSCMatrix* m); 00265 RefSymmSCMatrix& operator=(const RefSymmSCMatrix& m); 00266 00267 // matrix specific members 00268 public: 00271 RefSymmSCMatrix(const RefSCDimension& d,const Ref<SCMatrixKit>&); 00273 RefSCMatrix operator*(const RefSCMatrix&) const; 00274 RefSCMatrix operator*(const RefSymmSCMatrix&) const; 00276 RefSCVector operator*(const RefSCVector&a) const; 00277 RefSymmSCMatrix operator*(double) const; 00279 RefSymmSCMatrix operator+(const RefSymmSCMatrix&) const; 00280 RefSymmSCMatrix operator-(const RefSymmSCMatrix&) const; 00282 RefSymmSCMatrix i() const; 00284 RefSymmSCMatrix gi() const; 00287 RefSymmSCMatrix clone() const; 00288 RefSymmSCMatrix copy() const; 00289 void set_element(int,int,double) const; 00290 void accumulate_element(int,int,double) const; 00291 double get_element(int,int) const; 00292 00293 RefSCMatrix get_subblock(int br, int er, int bc, int ec); 00294 RefSymmSCMatrix get_subblock(int br, int er); 00295 void assign_subblock(const RefSCMatrix&, int br, int er, int bc, int ec); 00296 void assign_subblock(const RefSymmSCMatrix&, int br, int er); 00297 void accumulate_subblock(const RefSCMatrix&, int, int, int, int); 00298 void accumulate_subblock(const RefSymmSCMatrix&, int, int); 00299 RefSCVector get_row(int); 00300 void assign_row(const RefSCVector&, int); 00301 void accumulate_row(const RefSCVector&, int); 00302 00303 void accumulate_symmetric_outer_product(const RefSCVector&) const; 00304 double scalar_product(const RefSCVector&) const; 00305 void accumulate_symmetric_product(const RefSCMatrix&) const; 00306 void accumulate_symmetric_sum(const RefSCMatrix&) const; 00308 void accumulate_transform(const RefSCMatrix&a,const RefSymmSCMatrix&b, 00309 SCMatrix::Transform = SCMatrix::NormalTransform) const; 00310 void accumulate_transform(const RefSCMatrix&a,const RefDiagSCMatrix&b, 00311 SCMatrix::Transform = SCMatrix::NormalTransform) const; 00312 void accumulate_transform(const RefSymmSCMatrix&a, 00313 const RefSymmSCMatrix&b) const; 00314 00315 void randomize() const; 00316 void assign(const RefSymmSCMatrix&) const; 00317 void scale(double) const; 00318 void assign(double) const; 00319 void assign(const double*) const; 00320 void assign(const double**) const; 00321 void convert(double*) const; 00322 void convert(double**) const; 00323 void accumulate(const RefSymmSCMatrix&) const; 00324 void element_op(const Ref<SCElementOp>&) const; 00325 void element_op(const Ref<SCElementOp2>&, 00326 const RefSymmSCMatrix&) const; 00327 void element_op(const Ref<SCElementOp3>&, 00328 const RefSymmSCMatrix&, 00329 const RefSymmSCMatrix&) const; 00330 double trace() const; 00331 int n() const; 00332 RefSCDimension dim() const; 00333 Ref<SCMatrixKit> kit() const; 00334 void print(std::ostream&) const; 00335 void print(const char*title=0, 00336 std::ostream&out=ExEnv::out0(), int =10) const; 00337 void save(StateOut&); 00338 void restore(StateIn&); 00339 00341 double solve_lin(const RefSCVector&) const; 00343 double determ() const; 00345 RefDiagSCMatrix eigvals() const; 00347 RefSCMatrix eigvecs() const; 00350 void diagonalize(const RefDiagSCMatrix& eigvals, 00351 const RefSCMatrix& eigvecs) const; 00353 SymmSCMatrixdouble operator()(int i,int j) const; 00354 }; 00356 RefSymmSCMatrix operator*(double,const RefSymmSCMatrix&); 00357 00360 class RefDiagSCMatrix: public Ref<DiagSCMatrix> { 00361 // standard overrides 00362 public: 00365 RefDiagSCMatrix(); 00367 RefDiagSCMatrix(const RefDiagSCMatrix& m); 00369 RefDiagSCMatrix(DiagSCMatrix *m); 00370 ~RefDiagSCMatrix(); 00372 RefDiagSCMatrix& operator=(DiagSCMatrix* m); 00374 RefDiagSCMatrix& operator=(const RefDiagSCMatrix & m); 00375 00376 // matrix specific members 00377 public: 00380 RefDiagSCMatrix(const RefSCDimension&,const Ref<SCMatrixKit>&); 00382 RefSCMatrix operator*(const RefSCMatrix&) const; 00383 RefDiagSCMatrix operator*(double) const; 00385 RefDiagSCMatrix operator+(const RefDiagSCMatrix&) const; 00386 RefDiagSCMatrix operator-(const RefDiagSCMatrix&) const; 00388 RefDiagSCMatrix i() const; 00390 RefDiagSCMatrix gi() const; 00393 RefDiagSCMatrix clone() const; 00394 RefDiagSCMatrix copy() const; 00395 void set_element(int,double) const; 00396 void accumulate_element(int,double) const; 00397 double get_element(int) const; 00398 void randomize() const; 00399 void assign(const RefDiagSCMatrix&) const; 00400 void scale(double) const; 00401 void assign(double) const; 00402 void assign(const double*) const; 00403 void convert(double*) const; 00404 void accumulate(const RefDiagSCMatrix&) const; 00405 void element_op(const Ref<SCElementOp>&) const; 00406 void element_op(const Ref<SCElementOp2>&, 00407 const RefDiagSCMatrix&) const; 00408 void element_op(const Ref<SCElementOp3>&, 00409 const RefDiagSCMatrix&, 00410 const RefDiagSCMatrix&) const; 00411 int n() const; 00412 RefSCDimension dim() const; 00413 Ref<SCMatrixKit> kit() const; 00414 double trace() const; 00415 void print(std::ostream&) const; 00416 void print(const char*title=0, 00417 std::ostream&out=ExEnv::out0(), int =10) const; 00418 void save(StateOut&); 00419 void restore(StateIn&); 00421 double determ() const; 00423 DiagSCMatrixdouble operator()(int i) const; 00424 }; 00426 RefDiagSCMatrix operator*(double,const RefDiagSCMatrix&); 00427 00428 class SCVectordouble { 00429 friend class RefSCVector; 00430 private: 00431 RefSCVector vector; 00432 int i; 00433 00434 SCVectordouble(SCVector*,int); 00435 public: 00436 SCVectordouble(const SCVectordouble&); 00437 ~SCVectordouble(); 00438 double operator=(double a); 00439 double operator=(const SCVectordouble&); 00440 operator double(); 00441 double val() const; 00442 }; 00443 00444 class SCMatrixdouble { 00445 friend class RefSCMatrix; 00446 private: 00447 RefSCMatrix matrix; 00448 int i; 00449 int j; 00450 00451 SCMatrixdouble(SCMatrix*,int,int); 00452 public: 00453 SCMatrixdouble(const SCMatrixdouble&); 00454 ~SCMatrixdouble(); 00455 double operator=(double a); 00456 double operator=(const SCMatrixdouble&); 00457 operator double(); 00458 double val() const; 00459 }; 00460 00461 class SymmSCMatrixdouble { 00462 friend class RefSymmSCMatrix; 00463 private: 00464 RefSymmSCMatrix matrix; 00465 int i; 00466 int j; 00467 00468 SymmSCMatrixdouble(SymmSCMatrix*,int,int); 00469 public: 00470 SymmSCMatrixdouble(const SCMatrixdouble&); 00471 ~SymmSCMatrixdouble(); 00472 double operator=(double a); 00473 double operator=(const SymmSCMatrixdouble&); 00474 operator double(); 00475 double val() const; 00476 }; 00477 00478 class DiagSCMatrixdouble { 00479 friend class RefDiagSCMatrix; 00480 private: 00481 RefDiagSCMatrix matrix; 00482 int i; 00483 int j; 00484 00485 DiagSCMatrixdouble(DiagSCMatrix*,int,int); 00486 public: 00487 DiagSCMatrixdouble(const SCMatrixdouble&); 00488 ~DiagSCMatrixdouble(); 00489 double operator=(double a); 00490 double operator=(const DiagSCMatrixdouble&); 00491 operator double(); 00492 double val() const; 00493 }; 00494 00495 } 00496 00497 #ifdef INLINE_FUNCTIONS 00498 #include <math/scmat/matrix_i.h> 00499 #endif 00500 00501 #endif 00502 00503 // Local Variables: 00504 // mode: c++ 00505 // c-file-style: "CLJ" 00506 // End: Generated at Fri Jan 10 08:14:09 2003 for MPQC 2.1.3 using the documentation package Doxygen 1.2.14. |