Object-oriented Scientific Computing Library: Version 0.910
vec_arith.h
Go to the documentation of this file.
00001 /*
00002   -------------------------------------------------------------------
00003   
00004   Copyright (C) 2006-2012, Andrew W. Steiner
00005   
00006   This file is part of O2scl.
00007   
00008   O2scl is free software; you can redistribute it and/or modify
00009   it under the terms of the GNU General Public License as published by
00010   the Free Software Foundation; either version 3 of the License, or
00011   (at your option) any later version.
00012   
00013   O2scl is distributed in the hope that it will be useful,
00014   but WITHOUT ANY WARRANTY; without even the implied warranty of
00015   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016   GNU General Public License for more details.
00017   
00018   You should have received a copy of the GNU General Public License
00019   along with O2scl. If not, see <http://www.gnu.org/licenses/>.
00020 
00021   -------------------------------------------------------------------
00022 */
00023 
00024 #ifndef O2SCL_VEC_ARITH_H
00025 #define O2SCL_VEC_ARITH_H
00026 
00027 /** \file vec_arith.h
00028     \brief Vector and matrix arithmetic
00029 
00030     By default, the following operators are defined:
00031     \code
00032     ovector operator+(ovector_const_view &x, ovector_const_view &y);
00033     ovector operator+(ovector_const_view &x, uvector_const_view &y);
00034     ovector operator+(uvector_const_view &x, ovector_const_view &y);
00035     uvector operator+(uvector_const_view &x, uvector_const_view &y);
00036 
00037     ovector_cx operator+(ovector_cx_view &x, ovector_cx_view &y);
00038     ovector_cx operator+(ovector_cx_view &x, uvector_cx_view &y);
00039     ovector_cx operator+(uvector_cx_view &x, ovector_cx_view &y);
00040     uvector_cx operator+(uvector_cx_view &x, uvector_cx_view &y);
00041     
00042     ovector operator-(ovector_const_view &x, ovector_const_view &y);
00043     ovector operator-(ovector_const_view &x, uvector_const_view &y);
00044     ovector operator-(uvector_const_view &x, ovector_const_view &y);
00045     uvector operator-(uvector_const_view &x, uvector_const_view &y);
00046 
00047     ovector_cx operator-(ovector_cx_view &x, ovector_cx_view &y);
00048     ovector_cx operator-(ovector_cx_view &x, uvector_cx_view &y);
00049     ovector_cx operator-(uvector_cx_view &x, ovector_cx_view &y);
00050     uvector_cx operator-(uvector_cx_view &x, uvector_cx_view &y);
00051     
00052     ovector operator*(omatrix_const_view &x, ovector_const_view &y);
00053     ovector operator*(omatrix_const_view &x, uvector_const_view &y);
00054     ovector operator*(umatrix_const_view &x, ovector_const_view &y);
00055     uvector operator*(umatrix_const_view &x, uvector_const_view &y);
00056 
00057     ovector_cx operator*(omatrix_cx_view &x, ovector_cx_view &y);
00058     ovector_cx operator*(omatrix_cx_view &x, uvector_cx_view &y);
00059     ovector_cx operator*(umatrix_cx_view &x, ovector_cx_view &y);
00060     uvector_cx operator*(umatrix_cx_view &x, uvector_cx_view &y);
00061 
00062     ovector operator*(ovector_const_view &x, omatrix_const_view &y);
00063     ovector operator*(ovector_const_view &x, umatrix_const_view &y);
00064     ovector operator*(uvector_const_view &x, omatrix_const_view &y);
00065     uvector operator*(ovector_const_view &x, umatrix_const_view &y);
00066 
00067     ovector trans_mult(ovector_const_view &x, omatrix_const_view &y);
00068     ovector trans_mult(ovector_const_view &x, umatrix_const_view &y);
00069     ovector trans_mult(uvector_const_view &x, omatrix_const_view &y);
00070     uvector trans_mult(ovector_const_view &x, umatrix_const_view &y);
00071 
00072     double dot(ovector_const_view &x, ovector_const_view &y);
00073     double dot(ovector_const_view &x, uvector_const_view &y);
00074     double dot(uvector_const_view &x, ovector_const_view &y);
00075     double dot(uvector_const_view &x, uvector_const_view &y);
00076 
00077     double dot(ovector_cx_view &x, ovector_cx_view &y);
00078     double dot(ovector_cx_view &x, uvector_cx_view &y);
00079     double dot(uvector_cx_view &x, ovector_cx_view &y);
00080     double dot(uvector_cx_view &x, uvector_cx_view &y);
00081 
00082     ovector operator*(double x, ovector_const_view &y);
00083     uvector operator*(double x, uvector_const_view &y);
00084     ovector operator*(ovector_const_view &x, double y);
00085     uvector operator*(uvector_const_view &x, double y);
00086     
00087     ovector pair_prod(ovector_const_view &x, ovector_const_view &y);
00088     ovector pair_prod(ovector_const_view &x, uvector_const_view &y);
00089     ovector pair_prod(uvector_const_view &x, ovector_const_view &y);
00090     uvector pair_prod(uvector_const_view &x, uvector_const_view &y);
00091 
00092     ovector_cx pair_prod(ovector_cx_view &x, ovector_const_view &y);
00093     ovector_cx pair_prod(ovector_cx_view &x, uvector_const_view &y);
00094     ovector_cx pair_prod(uvector_cx_view &x, ovector_const_view &y);
00095     uvector_cx pair_prod(uvector_cx_view &x, uvector_const_view &y);
00096     ovector_cx pair_prod(ovector_const_view &x, ovector_cx_view &y);
00097     ovector_cx pair_prod(ovector_const_view &x, uvector_cx_view &y);
00098     ovector_cx pair_prod(uvector_const_view &x, ovector_cx_view &y);
00099     uvector_cx pair_prod(uvector_const_view &x, uvector_cx_view &y);
00100     ovector_cx pair_prod(ovector_cx_view &x, ovector_cx_view &y);
00101     ovector_cx pair_prod(ovector_cx_view &x, uvector_cx_view &y);
00102     ovector_cx pair_prod(uvector_cx_view &x, ovector_cx_view &y);
00103     uvector_cx pair_prod(uvector_cx_view &x, uvector_cx_view &y);
00104 
00105     bool operator==(ovector_const_view &x, ovector_const_view &y);
00106     bool operator==(ovector_const_view &x, uvector_const_view &y);
00107     bool operator==(uvector_const_view &x, ovector_const_view &y);
00108     bool operator==(uvector_const_view &x, uvector_const_view &y);
00109 
00110     bool operator!=(ovector_const_view &x, ovector_const_view &y);
00111     bool operator!=(ovector_const_view &x, uvector_const_view &y);
00112     bool operator!=(uvector_const_view &x, ovector_const_view &y);
00113     bool operator!=(uvector_const_view &x, uvector_const_view &y);
00114     \endcode      
00115     
00116     \note This used to be in a separate namespace, called 
00117     <tt>o2scl_arith</tt>, but this causes problems with Koenig
00118     lookup in template classes for operator*() when defined
00119     for vector addition (for example).
00120 
00121     \future Define operators for complex vector * real matrix
00122     \future Define == and != for complex vectors
00123     \future These should be replaced by the BLAS routines where possible?
00124 */
00125 
00126 #include <iostream>
00127 #include <complex>
00128 #include <o2scl/ovector_tlate.h>
00129 #include <o2scl/omatrix_tlate.h>
00130 #include <o2scl/uvector_tlate.h>
00131 #include <o2scl/umatrix_tlate.h>
00132 #include <o2scl/ovector_cx_tlate.h>
00133 #include <o2scl/omatrix_cx_tlate.h>
00134 #include <o2scl/uvector_cx_tlate.h>
00135 #include <o2scl/umatrix_cx_tlate.h>
00136 
00137 #ifndef DOXYGENP
00138 namespace o2scl {
00139 #endif
00140   
00141   /** \brief The header macro for vector-vector addition
00142 
00143       Given types \c vec1, \c vec2, and \c vec_3, this macro
00144       provides the function declaration for adding two vectors
00145       using the form
00146       \code
00147       vec1 operator+(const vec2 &x, const vec3 &y);
00148       \endcode
00149 
00150       The corresponding definition is given in 
00151       \ref O2SCL_OPSRC_VEC_VEC_ADD.
00152       
00153       \note This used to be in a separate namespace, called 
00154       <tt>o2scl_arith</tt>, but this causes problems with Koenig
00155       lookup in template classes for operator*() when defined
00156       for vector addition (for example).
00157   */
00158 #define O2SCL_OP_VEC_VEC_ADD(vec1,vec2,vec3) vec1 operator+     \
00159     (const vec2 &x, const vec3 &y);
00160 
00161 #ifndef DOXYGENP
00162   
00163   O2SCL_OP_VEC_VEC_ADD(o2scl::ovector,o2scl::ovector_const_view,
00164                        o2scl::ovector_const_view)
00165     O2SCL_OP_VEC_VEC_ADD(o2scl::ovector,o2scl::ovector_const_view,
00166                          o2scl::uvector_const_view)
00167     O2SCL_OP_VEC_VEC_ADD(o2scl::ovector,o2scl::uvector_const_view,
00168                          o2scl::ovector_const_view)
00169     O2SCL_OP_VEC_VEC_ADD(o2scl::uvector,o2scl::uvector_const_view,
00170                          o2scl::uvector_const_view)
00171     O2SCL_OP_VEC_VEC_ADD(o2scl::ovector_cx,o2scl::ovector_cx_view,
00172                          o2scl::ovector_cx_view)
00173     O2SCL_OP_VEC_VEC_ADD(o2scl::ovector_cx,o2scl::ovector_cx_view,
00174                          o2scl::uvector_cx_view)
00175     O2SCL_OP_VEC_VEC_ADD(o2scl::ovector_cx,o2scl::uvector_cx_view,
00176                          o2scl::ovector_cx_view)
00177     O2SCL_OP_VEC_VEC_ADD(o2scl::uvector_cx,o2scl::uvector_cx_view,
00178                          o2scl::uvector_cx_view)
00179 
00180 #endif
00181     
00182 #ifdef O2SCL_NEVER_DEFINED
00183     }
00184 {
00185 #endif
00186   
00187   /** \brief The header macro for vector-vector subtraction
00188 
00189       Given types \c vec1, \c vec2, and \c vec_3, this macro
00190       provides the function declaration for adding two vectors
00191       using the form
00192       \code
00193       vec1 operator-(const vec2 &x, const vec3 &y);
00194       \endcode
00195 
00196       The corresponding definition is given in 
00197       \ref O2SCL_OPSRC_VEC_VEC_SUB.
00198   */
00199 #define O2SCL_OP_VEC_VEC_SUB(vec1,vec2,vec3) vec1 operator-     \
00200     (const vec2 &x, const vec3 &y);
00201   
00202 #ifndef DOXYGENP
00203 
00204   O2SCL_OP_VEC_VEC_SUB(o2scl::ovector,o2scl::ovector_const_view,
00205                        o2scl::ovector_const_view)
00206     O2SCL_OP_VEC_VEC_SUB(o2scl::ovector,o2scl::ovector_const_view,
00207                          o2scl::uvector_const_view)
00208     O2SCL_OP_VEC_VEC_SUB(o2scl::ovector,o2scl::uvector_const_view,
00209                          o2scl::ovector_const_view)
00210     O2SCL_OP_VEC_VEC_SUB(o2scl::uvector,o2scl::uvector_const_view,
00211                          o2scl::uvector_const_view)
00212     O2SCL_OP_VEC_VEC_SUB(o2scl::ovector_cx,o2scl::ovector_cx_view,
00213                          o2scl::ovector_cx_view)
00214     O2SCL_OP_VEC_VEC_SUB(o2scl::ovector_cx,o2scl::ovector_cx_view,
00215                          o2scl::uvector_cx_view)
00216     O2SCL_OP_VEC_VEC_SUB(o2scl::ovector_cx,o2scl::uvector_cx_view,
00217                          o2scl::ovector_cx_view)
00218     O2SCL_OP_VEC_VEC_SUB(o2scl::uvector_cx,o2scl::uvector_cx_view,
00219                          o2scl::uvector_cx_view)
00220 
00221 #endif
00222           
00223 #ifdef O2SCL_NEVER_DEFINED
00224     }
00225 {
00226 #endif
00227 
00228   /** \brief The header macro for matrix-vector (right) multiplication
00229 
00230       Given types \c vec1, \c vec2, and \c mat, this macro
00231       provides the function declaration for adding two vectors
00232       using the form
00233       \code
00234       vec1 operator*(const mat &m, const vec3 &x);
00235       \endcode
00236       
00237       See also the blas version of this function \ref dgemv().
00238 
00239       The corresponding definition is given in 
00240       \ref O2SCL_OPSRC_MAT_VEC_MULT.
00241 
00242   */
00243 #define O2SCL_OP_MAT_VEC_MULT(vec1,vec2,mat) vec1 operator*     \
00244     (const mat &m, const vec2 &x);
00245   
00246 #ifndef DOXYGENP
00247 
00248   O2SCL_OP_MAT_VEC_MULT(o2scl::ovector,o2scl::ovector_const_view,
00249                         o2scl::omatrix_const_view)
00250     O2SCL_OP_MAT_VEC_MULT(o2scl::ovector,o2scl::ovector_const_view,
00251                           o2scl::umatrix_const_view)
00252     O2SCL_OP_MAT_VEC_MULT(o2scl::ovector,o2scl::uvector_const_view,
00253                           o2scl::omatrix_const_view)
00254     O2SCL_OP_MAT_VEC_MULT(o2scl::uvector,o2scl::uvector_const_view,
00255                           o2scl::umatrix_const_view)
00256 
00257 #endif
00258     
00259 #ifdef O2SCL_NEVER_DEFINED
00260     }
00261 {
00262 #endif
00263 
00264   /** \brief The header macro for complex matrix-vector (right) 
00265       multiplication
00266 
00267       Given types \c vec1, \c vec2, and \c mat, this macro
00268       provides the function declaration for adding two vectors
00269       using the form
00270       \code
00271       vec1 operator*(const mat &m, const vec3 &x);
00272       \endcode
00273 
00274       The corresponding definition is given in 
00275       \ref O2SCL_OPSRC_CMAT_CVEC_MULT.
00276 
00277   */
00278 #define O2SCL_OP_CMAT_CVEC_MULT(vec1,vec2,mat) vec1 operator*   \
00279     (const mat &m, const vec2 &x);
00280   
00281 #ifndef DOXYGENP
00282 
00283   O2SCL_OP_CMAT_CVEC_MULT(o2scl::ovector_cx,o2scl::ovector_cx_view,
00284                           o2scl::omatrix_cx_view)
00285     O2SCL_OP_CMAT_CVEC_MULT(o2scl::ovector_cx,o2scl::ovector_cx_view,
00286                             o2scl::umatrix_cx_view)
00287     O2SCL_OP_CMAT_CVEC_MULT(o2scl::ovector_cx,o2scl::uvector_cx_view,
00288                             o2scl::omatrix_cx_view)
00289     O2SCL_OP_CMAT_CVEC_MULT(o2scl::uvector_cx,o2scl::uvector_cx_view,
00290                             o2scl::umatrix_cx_view)
00291 
00292 #endif
00293 
00294 #ifdef O2SCL_NEVER_DEFINED
00295     }
00296 {
00297 #endif
00298 
00299   /** \brief The header macro for vector-matrix (left) 
00300       multiplication
00301 
00302       Given types \c vec1, \c vec2, and \c mat, this macro
00303       provides the function declaration for adding two vectors
00304       using the form
00305       \code
00306       vec1 operator*(const vec3 &x, const mat &m);
00307       \endcode
00308       
00309       The corresponding definition is given in 
00310       \ref O2SCL_OPSRC_VEC_MAT_MULT.
00311   */
00312 #define O2SCL_OP_VEC_MAT_MULT(vec1,vec2,mat) vec1 operator*     \
00313     (const vec2 &x, const mat &m);
00314   
00315 #ifndef DOXYGENP
00316 
00317   O2SCL_OP_VEC_MAT_MULT(o2scl::ovector,o2scl::ovector_const_view,
00318                         o2scl::omatrix_const_view)
00319     O2SCL_OP_VEC_MAT_MULT(o2scl::ovector,o2scl::ovector_const_view,
00320                           o2scl::umatrix_const_view)
00321     O2SCL_OP_VEC_MAT_MULT(o2scl::ovector,o2scl::uvector_const_view,
00322                           o2scl::omatrix_const_view)
00323     O2SCL_OP_VEC_MAT_MULT(o2scl::uvector,o2scl::uvector_const_view,
00324                           o2scl::umatrix_const_view)
00325 
00326 #endif
00327 
00328 #ifdef O2SCL_NEVER_DEFINED
00329     }
00330 {
00331 #endif
00332 
00333   /// The header macro for the \c trans_mult form of vector * matrix
00334 #define O2SCL_OP_TRANS_MULT(vec1,vec2,mat) vec1 trans_mult      \
00335     (const vec2 &x, const mat &m);
00336   
00337 #ifndef DOXYGENP
00338 
00339   O2SCL_OP_TRANS_MULT(o2scl::ovector,o2scl::ovector_const_view,
00340                       o2scl::omatrix_const_view)
00341     O2SCL_OP_TRANS_MULT(o2scl::ovector,o2scl::ovector_const_view,
00342                         o2scl::umatrix_const_view)
00343     O2SCL_OP_TRANS_MULT(o2scl::ovector,o2scl::uvector_const_view,
00344                         o2scl::omatrix_const_view)
00345     O2SCL_OP_TRANS_MULT(o2scl::uvector,o2scl::uvector_const_view,
00346                         o2scl::umatrix_const_view)
00347 
00348 #endif
00349             
00350 #ifdef O2SCL_NEVER_DEFINED
00351     }
00352 {
00353 #endif
00354 
00355   /** \brief The header macro for vector scalar (dot) product
00356 
00357       Given types \c vec1, \c vec2, and \c dtype, this macro
00358       provides the function declaration for adding two vectors
00359       using the form
00360       \code
00361       dtype operator*(const vec1 &x, const vec2 &y);
00362       \endcode
00363 
00364       The corresponding definition is given in 
00365       \ref O2SCL_OPSRC_DOT_PROD.
00366   */
00367 #define O2SCL_OP_DOT_PROD(dtype,vec1,vec2) dtype dot    \
00368     (const vec1 &x, const vec2 &y);
00369             
00370 #ifndef DOXYGENP
00371 
00372   O2SCL_OP_DOT_PROD(double,o2scl::ovector_const_view,
00373                     o2scl::ovector_const_view)
00374     O2SCL_OP_DOT_PROD(double,o2scl::ovector_const_view,
00375                       o2scl::uvector_const_view)
00376     O2SCL_OP_DOT_PROD(double,o2scl::uvector_const_view,
00377                       o2scl::ovector_const_view)
00378     O2SCL_OP_DOT_PROD(double,o2scl::uvector_const_view,
00379                       o2scl::uvector_const_view)
00380 
00381 #endif
00382 
00383 #ifdef O2SCL_NEVER_DEFINED
00384     }
00385 {
00386 #endif
00387 
00388   /** \brief The header macro for complex vector scalar (dot) 
00389       product
00390       
00391       Given types \c vec1, \c vec2, and \c dtype, this macro
00392       provides the function declaration for adding two vectors
00393       using the form
00394       \code
00395       dtype operator*(const vec1 &x, const vec2 &y);
00396       \endcode
00397 
00398       The corresponding definition is given in 
00399       \ref O2SCL_OPSRC_CX_DOT_PROD.
00400   */
00401 #define O2SCL_OP_CX_DOT_PROD(dtype,vec1,vec2) dtype dot \
00402     (const vec1 &x, const vec2 &y);
00403 
00404 #ifndef DOXYGENP
00405 
00406   O2SCL_OP_CX_DOT_PROD(gsl_complex,o2scl::ovector_cx_view,
00407                        o2scl::ovector_cx_view)
00408     O2SCL_OP_CX_DOT_PROD(gsl_complex,o2scl::ovector_cx_view,
00409                          o2scl::uvector_cx_view)
00410     O2SCL_OP_CX_DOT_PROD(gsl_complex,o2scl::uvector_cx_view,
00411                          o2scl::ovector_cx_view)
00412     O2SCL_OP_CX_DOT_PROD(gsl_complex,o2scl::uvector_cx_view,
00413                          o2scl::uvector_cx_view)
00414 
00415 #endif
00416 
00417 #ifdef O2SCL_NEVER_DEFINED
00418     }
00419 {
00420 #endif
00421 
00422   /** \brief The header macro for scalar-vector multiplication
00423       
00424       Given types \c vecv, \c vec, and \c dtype, this macro
00425       provides the function declaration for adding two vectors
00426       using the form
00427       \code
00428       vec operator*(const dtype &x, const vecv &y);
00429       \endcode
00430 
00431       The corresponding definition is given in 
00432       \ref O2SCL_OPSRC_SCA_VEC_MULT.
00433   */
00434 #define O2SCL_OP_SCA_VEC_MULT(dtype,vecv,vec) vec operator*     \
00435     (const dtype &x, const vecv &y);
00436   
00437 #ifndef DOXYGENP
00438 
00439   O2SCL_OP_SCA_VEC_MULT(double,o2scl::ovector_const_view,o2scl::ovector)
00440     O2SCL_OP_SCA_VEC_MULT(double,o2scl::uvector_const_view,o2scl::uvector)
00441 
00442 #endif
00443     
00444 #ifdef O2SCL_NEVER_DEFINED
00445     }
00446 {
00447 #endif
00448 
00449   /** \brief The header macro for vector-scalar multiplication
00450       
00451       Given types \c vecv, \c vec, and \c dtype, this macro
00452       provides the function declaration for adding two vectors
00453       using the form
00454       \code
00455       vec operator*(const vecv &x, const dtype &y);
00456       \endcode
00457 
00458       The corresponding definition is given in 
00459       \ref O2SCL_OPSRC_VEC_SCA_MULT.
00460   */
00461 #define O2SCL_OP_VEC_SCA_MULT(dtype,vecv,vec) vec operator*     \
00462     (const vecv &x, const dtype &y);
00463   
00464 #ifndef DOXYGENP
00465 
00466   O2SCL_OP_VEC_SCA_MULT(double,o2scl::ovector_const_view,o2scl::ovector)
00467     O2SCL_OP_VEC_SCA_MULT(double,o2scl::uvector_const_view,o2scl::uvector)
00468 
00469 #endif
00470 
00471 #ifdef O2SCL_NEVER_DEFINED
00472     }
00473 {
00474 #endif
00475               
00476   /** \brief The header macro for pairwise vector * vector (where either 
00477       vector can be real or complex)
00478       
00479       Given types \c vec1, \c vec2, and \c vec3, this macro
00480       provides the function declaration for adding two vectors
00481       using the form
00482       \code
00483       vec1 pair_prod(const vec2 &x, const vec3 &y);
00484       \endcode
00485 
00486       The corresponding definition is given in 
00487       \ref O2SCL_OPSRC_VEC_VEC_PRO.
00488   */
00489 #define O2SCL_OP_VEC_VEC_PRO(vec1,vec2,vec3) vec1 pair_prod     \
00490     (const vec2 &x, const vec3 &y);
00491   
00492 #ifndef DOXYGENP
00493 
00494   O2SCL_OP_VEC_VEC_PRO(o2scl::ovector,o2scl::ovector_const_view,
00495                        o2scl::ovector_const_view)
00496     O2SCL_OP_VEC_VEC_PRO(o2scl::ovector,o2scl::ovector_const_view,
00497                          o2scl::uvector_const_view)
00498     O2SCL_OP_VEC_VEC_PRO(o2scl::ovector,o2scl::uvector_const_view,
00499                          o2scl::ovector_const_view)
00500     O2SCL_OP_VEC_VEC_PRO(o2scl::uvector,o2scl::uvector_const_view,
00501                          o2scl::uvector_const_view)
00502     O2SCL_OP_VEC_VEC_PRO(o2scl::ovector_cx,o2scl::ovector_cx_view,
00503                          o2scl::ovector_const_view)
00504     O2SCL_OP_VEC_VEC_PRO(o2scl::ovector_cx,o2scl::ovector_cx_view,
00505                          o2scl::uvector_const_view)
00506     O2SCL_OP_VEC_VEC_PRO(o2scl::ovector_cx,o2scl::uvector_cx_view,
00507                          o2scl::ovector_const_view)
00508     O2SCL_OP_VEC_VEC_PRO(o2scl::uvector_cx,o2scl::uvector_cx_view,
00509                          o2scl::uvector_const_view)
00510     O2SCL_OP_VEC_VEC_PRO(o2scl::ovector_cx,o2scl::ovector_const_view,
00511                          o2scl::ovector_cx_view)
00512     O2SCL_OP_VEC_VEC_PRO(o2scl::ovector_cx,o2scl::ovector_const_view,
00513                          o2scl::uvector_cx_view)
00514     O2SCL_OP_VEC_VEC_PRO(o2scl::ovector_cx,o2scl::uvector_const_view,
00515                          o2scl::ovector_cx_view)
00516     O2SCL_OP_VEC_VEC_PRO(o2scl::uvector_cx,o2scl::uvector_const_view,
00517                          o2scl::uvector_cx_view)
00518     O2SCL_OP_VEC_VEC_PRO(o2scl::ovector_cx,o2scl::ovector_cx_view,
00519                          o2scl::ovector_cx_view)
00520     O2SCL_OP_VEC_VEC_PRO(o2scl::ovector_cx,o2scl::ovector_cx_view,
00521                          o2scl::uvector_cx_view)
00522     O2SCL_OP_VEC_VEC_PRO(o2scl::ovector_cx,o2scl::uvector_cx_view,
00523                          o2scl::ovector_cx_view)
00524     O2SCL_OP_VEC_VEC_PRO(o2scl::uvector_cx,o2scl::uvector_cx_view,
00525                          o2scl::uvector_cx_view)
00526 
00527 #endif
00528     
00529     /** \brief The source code macro for vector-vector addition
00530 
00531         This define macro generates the function definition. See
00532         the function declaration \ref O2SCL_OP_VEC_VEC_ADD
00533     */
00534 #define O2SCL_OPSRC_VEC_VEC_ADD(vec1,vec2,vec3) vec1 o2scl::operator+ \
00535       (const vec2 &x, const vec3 &y) {                                  \
00536       size_t m=x.size();                                                \
00537       if (y.size()<m) m=y.size();                                       \
00538       vec1 r(m);                                                        \
00539       for(size_t i=0;i<m;i++) {                                         \
00540         r[i]=x[i]+y[i];                                                 \
00541       }                                                                 \
00542       return r;                                                         \
00543     }
00544     
00545     /** \brief The source code macro for vector-vector subtraction
00546 
00547         This define macro generates the function definition. See
00548         the function declaration \ref O2SCL_OP_VEC_VEC_SUB
00549     */
00550 #define O2SCL_OPSRC_VEC_VEC_SUB(vec1,vec2,vec3) vec1 o2scl::operator- \
00551       (const vec2 &x, const vec3 &y) {                                  \
00552       size_t m=x.size();                                                \
00553       if (y.size()<m) m=y.size();                                       \
00554       vec1 r(m);                                                        \
00555       for(size_t i=0;i<m;i++) {                                         \
00556         r[i]=x[i]-y[i];                                                 \
00557       }                                                                 \
00558       return r;                                                         \
00559     }
00560 
00561     /** \brief The source code macro for matrix * vector
00562 
00563         This define macro generates the function definition. See
00564         the function declaration \ref O2SCL_OP_MAT_VEC_MULT
00565     */
00566 #define O2SCL_OPSRC_MAT_VEC_MULT(vec1,vec2,mat) vec1 o2scl::operator* \
00567       (const mat &m, const vec2 &x) {                                   \
00568       size_t nr=m.rows();                                               \
00569       size_t nc=m.cols();                                               \
00570       vec1 res(nr);                                                     \
00571       for(size_t i=0;i<nr;i++) {                                        \
00572         double r=0.0;                                                   \
00573         for(size_t j=0;j<nc;j++) {                                      \
00574           r+=m[i][j]*x[j];                                              \
00575         }                                                               \
00576         res[i]=r;                                                       \
00577       }                                                                 \
00578       return res;                                                       \
00579     } 
00580   
00581     /** \brief The source code macro for complex matrix * complex vector
00582 
00583         This define macro generates the function definition. See
00584         the function declaration \ref O2SCL_OP_CMAT_CVEC_MULT
00585     */
00586 #define O2SCL_OPSRC_CMAT_CVEC_MULT(vec1,vec2,mat) vec1 o2scl::operator* \
00587       (const mat &m, const vec2 &x) {                                   \
00588       size_t nr=m.rows();                                               \
00589       size_t nc=m.cols();                                               \
00590       vec1 res(nr);                                                     \
00591       for(size_t i=0;i<nr;i++) {                                        \
00592         double re=0.0;                                                  \
00593         double im=0.0;                                                  \
00594         for(size_t j=0;j<nc;j++) {                                      \
00595           gsl_complex g=m[i][j]*x[j];                                   \
00596           re+=g.dat[0];                                                 \
00597           im+=g.dat[1];                                                 \
00598         }                                                               \
00599         res[i].dat[0]=re;                                               \
00600         res[i].dat[1]=im;                                               \
00601       }                                                                 \
00602       return res;                                                       \
00603     } 
00604   
00605     /** \brief The source code macro for the operator form of vector * matrix
00606 
00607         This define macro generates the function definition. See
00608         the function declaration \ref O2SCL_OP_VEC_MAT_MULT
00609     */
00610 #define O2SCL_OPSRC_VEC_MAT_MULT(vec1,vec2,mat) vec1 o2scl::operator* \
00611       (const vec2 &x, const mat &m) {                                   \
00612       size_t nr=m.rows();                                               \
00613       size_t nc=m.cols();                                               \
00614       vec1 res(nr);                                                     \
00615       for(size_t j=0;j<nc;j++) {                                        \
00616         double r=0.0;                                                   \
00617         for(size_t i=0;i<nr;i++) {                                      \
00618           r+=x[i]*m[i][j];                                              \
00619         }                                                               \
00620         res[j]=r;                                                       \
00621       }                                                                 \
00622       return res;                                                       \
00623     } 
00624   
00625     /** \brief The source code macro for the \c trans_mult form of 
00626         vector * matrix
00627 
00628         This define macro generates the function definition. See
00629         the function declaration \ref O2SCL_OP_TRANS_MULT
00630     */
00631 #define O2SCL_OPSRC_TRANS_MULT(vec1,vec2,mat) vec1 o2scl::trans_mult \
00632       (const vec2 &x, const mat &m) {                                   \
00633       size_t nr=m.rows();                                               \
00634       size_t nc=m.cols();                                               \
00635       vec1 res(nr);                                                     \
00636       for(size_t j=0;j<nc;j++) {                                        \
00637         double r=0.0;                                                   \
00638         for(size_t i=0;i<nr;i++) {                                      \
00639           r+=x[i]*m[i][j];                                              \
00640         }                                                               \
00641         res[j]=r;                                                       \
00642       }                                                                 \
00643       return res;                                                       \
00644     } 
00645   
00646     /** \brief The source code macro for a vector dot product
00647 
00648         This define macro generates the function definition. See
00649         the function declaration \ref O2SCL_OP_DOT_PROD
00650     */
00651 #define O2SCL_OPSRC_DOT_PROD(dtype,vec1,vec2) dtype o2scl::dot  \
00652       (const vec1 &x, const vec2 &y) {                                  \
00653       size_t m=x.size();                                                \
00654       if (y.size()<m) m=y.size();                                       \
00655       dtype r=0;                                                        \
00656       for(size_t i=0;i<m;i++) {                                         \
00657         r+=x[i]*y[i];                                                   \
00658       }                                                                 \
00659       return r;                                                         \
00660     }
00661             
00662     /** \brief The source code macro for a complex vector dot product
00663 
00664         This define macro generates the function definition. See
00665         the function declaration \ref O2SCL_OP_CX_DOT_PROD
00666     */
00667 #define O2SCL_OPSRC_CX_DOT_PROD(dtype,vec1,vec2) dtype o2scl::dot       \
00668       (const vec1 &x, const vec2 &y) {                                  \
00669       size_t m=x.size();                                                \
00670       if (y.size()<m) m=y.size();                                       \
00671       dtype r={{0.0,0.0}};                                              \
00672       for(size_t i=0;i<m;i++) {                                         \
00673         r+=x[i]*y[i];                                                   \
00674       }                                                                 \
00675       return r;                                                         \
00676     }
00677 
00678     /** \brief The source code macro for vector=scalar*vector
00679 
00680         This define macro generates the function definition. See
00681         the function declaration \ref O2SCL_OP_SCA_VEC_MULT
00682     */
00683 #define O2SCL_OPSRC_SCA_VEC_MULT(dtype,vecv,vec) vec o2scl::operator* \
00684       (const dtype &x, const vecv &y) {                                 \
00685       size_t m=y.size();                                                \
00686       vec r(m);                                                         \
00687       for(size_t i=0;i<m;i++) {                                         \
00688         r[i]=x*y[i];                                                    \
00689       }                                                                 \
00690       return r;                                                         \
00691     }
00692   
00693     /** \brief The source code macro for vector=vector*scalar
00694 
00695         This define macro generates the function definition. See
00696         the function declaration \ref O2SCL_OP_VEC_SCA_MULT
00697     */
00698 #define O2SCL_OPSRC_VEC_SCA_MULT(dtype,vecv,vec) vec o2scl::operator* \
00699       (const vecv &x, const dtype &y) {                                 \
00700       size_t m=x.size();                                                \
00701       vec r(m);                                                         \
00702       for(size_t i=0;i<m;i++) {                                         \
00703         r[i]=x[i]*y;                                                    \
00704       }                                                                 \
00705       return r;                                                         \
00706     }
00707     
00708     /** \brief The source code macro for pairwise vector * vector (where
00709         either vector can be real or complex)
00710         
00711         This define macro generates the function definition. See
00712         the function declaration \ref O2SCL_OP_VEC_VEC_PRO
00713     */
00714 #define O2SCL_OPSRC_VEC_VEC_PRO(vec1,vec2,vec3) vec1 o2scl::pair_prod \
00715       (const vec2 &x, const vec3 &y) {                                  \
00716       size_t m=x.size();                                                \
00717       if (y.size()<m) m=y.size();                                       \
00718       vec1 r(m);                                                        \
00719       for(size_t i=0;i<m;i++) {                                         \
00720         r[i]=x[i]*y[i];                                                 \
00721       }                                                                 \
00722       return r;                                                         \
00723     }
00724     
00725     /** \brief The header macro for vector==vector 
00726 
00727         Given types \c vec1 and \c vec2, this macro provides the
00728         function declaration for vector equality comparisons using
00729         \code
00730         bool operator==(const vec1 &x, const vec2 &y);
00731         \endcode
00732 
00733         \note Two vectors with different sizes are defined to 
00734         be not equal, no matter what their contents.
00735 
00736         The corresponding definition is given in 
00737         \ref O2SCL_OPSRC_VEC_VEC_EQUAL.
00738     */
00739 #define O2SCL_OP_VEC_VEC_EQUAL(vec1,vec2) bool operator==       \
00740       (const vec1 &x, const vec2 &y);
00741     
00742 #ifndef DOXYGENP
00743     
00744     O2SCL_OP_VEC_VEC_EQUAL(o2scl::ovector_const_view,
00745                            o2scl::ovector_const_view)
00746       O2SCL_OP_VEC_VEC_EQUAL(o2scl::ovector_const_view,
00747                              o2scl::uvector_const_view)
00748       O2SCL_OP_VEC_VEC_EQUAL(o2scl::uvector_const_view,
00749                              o2scl::ovector_const_view)
00750       O2SCL_OP_VEC_VEC_EQUAL(o2scl::uvector_const_view,
00751                              o2scl::uvector_const_view)
00752       /*
00753       O2SCL_OP_VEC_VEC_EQUAL(o2scl::ovector_cx_view,
00754                              o2scl::ovector_const_view)
00755       O2SCL_OP_VEC_VEC_EQUAL(o2scl::ovector_cx_view,
00756                              o2scl::uvector_const_view)
00757       O2SCL_OP_VEC_VEC_EQUAL(o2scl::uvector_cx_view,
00758                              o2scl::ovector_const_view)
00759       O2SCL_OP_VEC_VEC_EQUAL(o2scl::uvector_cx_view,
00760                              o2scl::uvector_const_view)
00761       O2SCL_OP_VEC_VEC_EQUAL(o2scl::ovector_const_view,
00762                              o2scl::ovector_cx_view)
00763       O2SCL_OP_VEC_VEC_EQUAL(o2scl::ovector_const_view,
00764                              o2scl::uvector_cx_view)
00765       O2SCL_OP_VEC_VEC_EQUAL(o2scl::uvector_const_view,
00766                              o2scl::ovector_cx_view)
00767       O2SCL_OP_VEC_VEC_EQUAL(o2scl::uvector_const_view,
00768                              o2scl::uvector_cx_view)
00769       O2SCL_OP_VEC_VEC_EQUAL(o2scl::ovector_cx_view,
00770                              o2scl::ovector_cx_view)
00771       O2SCL_OP_VEC_VEC_EQUAL(o2scl::ovector_cx_view,
00772                              o2scl::uvector_cx_view)
00773       O2SCL_OP_VEC_VEC_EQUAL(o2scl::uvector_cx_view,
00774                              o2scl::ovector_cx_view)
00775       O2SCL_OP_VEC_VEC_EQUAL(o2scl::uvector_cx_view,
00776                              o2scl::uvector_cx_view)
00777       */
00778 
00779 #endif
00780 
00781 #ifdef O2SCL_NEVER_DEFINED
00782       }
00783 {
00784 #endif
00785               
00786   /** \brief The source code macro vector==vector
00787         
00788       \note Two vectors with different sizes are defined to 
00789       be not equal, no matter what their contents.
00790 
00791       This define macro generates the function definition. See
00792       the function declaration \ref O2SCL_OP_VEC_VEC_EQUAL
00793   */
00794 #define O2SCL_OPSRC_VEC_VEC_EQUAL(vec1,vec2) bool o2scl::operator== \
00795     (const vec1 &x, const vec2 &y) {                                    \
00796     size_t m=x.size();                                                  \
00797     size_t n=y.size();                                                  \
00798     if (m!=n) return false;                                             \
00799     for(size_t i=0;i<m;i++) {                                           \
00800       if (x[i]!=y[i]) return false;                                     \
00801     }                                                                   \
00802     return true;                                                        \
00803   }
00804     
00805   /** \brief The header macro for vector!=vector 
00806 
00807       Given types \c vec1 and \c vec2, this macro provides the
00808       function declaration for vector inequality comparisons using
00809       \code
00810       bool operator==(const vec1 &x, const vec2 &y);
00811       \endcode
00812 
00813       \note Two vectors with different sizes are defined to 
00814       be not equal, no matter what their contents.
00815       
00816       The corresponding definition is given in 
00817       \ref O2SCL_OPSRC_VEC_VEC_NEQUAL.
00818   */
00819 #define O2SCL_OP_VEC_VEC_NEQUAL(vec1,vec2) bool operator!=      \
00820     (const vec1 &x, const vec2 &y);
00821     
00822 #ifndef DOXYGENP
00823     
00824   O2SCL_OP_VEC_VEC_NEQUAL(o2scl::ovector_const_view,
00825                           o2scl::ovector_const_view)
00826     O2SCL_OP_VEC_VEC_NEQUAL(o2scl::ovector_const_view,
00827                             o2scl::uvector_const_view)
00828     O2SCL_OP_VEC_VEC_NEQUAL(o2scl::uvector_const_view,
00829                             o2scl::ovector_const_view)
00830     O2SCL_OP_VEC_VEC_NEQUAL(o2scl::uvector_const_view,
00831                             o2scl::uvector_const_view)
00832     /*
00833     O2SCL_OP_VEC_VEC_NEQUAL(o2scl::ovector_cx_view,
00834                             o2scl::ovector_const_view)
00835     O2SCL_OP_VEC_VEC_NEQUAL(o2scl::ovector_cx_view,
00836                             o2scl::uvector_const_view)
00837     O2SCL_OP_VEC_VEC_NEQUAL(o2scl::uvector_cx_view,
00838                             o2scl::ovector_const_view)
00839     O2SCL_OP_VEC_VEC_NEQUAL(o2scl::uvector_cx_view,
00840                             o2scl::uvector_const_view)
00841     O2SCL_OP_VEC_VEC_NEQUAL(o2scl::ovector_const_view,
00842                             o2scl::ovector_cx_view)
00843     O2SCL_OP_VEC_VEC_NEQUAL(o2scl::ovector_const_view,
00844                             o2scl::uvector_cx_view)
00845     O2SCL_OP_VEC_VEC_NEQUAL(o2scl::uvector_const_view,
00846                             o2scl::ovector_cx_view)
00847     O2SCL_OP_VEC_VEC_NEQUAL(o2scl::uvector_const_view,
00848                             o2scl::uvector_cx_view)
00849     O2SCL_OP_VEC_VEC_NEQUAL(o2scl::ovector_cx_view,
00850                             o2scl::ovector_cx_view)
00851     O2SCL_OP_VEC_VEC_NEQUAL(o2scl::ovector_cx_view,
00852                             o2scl::uvector_cx_view)
00853     O2SCL_OP_VEC_VEC_NEQUAL(o2scl::uvector_cx_view,
00854                             o2scl::ovector_cx_view)
00855     O2SCL_OP_VEC_VEC_NEQUAL(o2scl::uvector_cx_view,
00856                             o2scl::uvector_cx_view)
00857     */
00858 
00859 #endif
00860 
00861 #ifdef O2SCL_NEVER_DEFINED
00862     }
00863 {
00864 #endif
00865               
00866   /** \brief The source code macro vector!=vector
00867         
00868       \note Two vectors with different sizes are defined to 
00869       be not equal, no matter what their contents.
00870 
00871       This define macro generates the function definition. See
00872       the function declaration \ref O2SCL_OP_VEC_VEC_NEQUAL
00873   */
00874 #define O2SCL_OPSRC_VEC_VEC_NEQUAL(vec1,vec2) bool o2scl::operator!= \
00875     (const vec1 &x, const vec2 &y) {                                    \
00876     size_t m=x.size();                                                  \
00877     size_t n=y.size();                                                  \
00878     if (m!=n) return true;                                              \
00879     for(size_t i=0;i<m;i++) {                                           \
00880       if (x[i]!=y[i]) return true;                                      \
00881     }                                                                   \
00882     return false;                                                       \
00883   }
00884 
00885 #ifndef DOXYGENP
00886   // end of o2scl namespace    
00887 }
00888 #endif
00889 
00890 #endif
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Documentation generated with Doxygen. Provided under the GNU Free Documentation License (see License Information).

Get Object-oriented Scientific Computing
Lib at SourceForge.net. Fast, secure and Free Open Source software
downloads.