00001 /* 00002 ------------------------------------------------------------------- 00003 00004 Copyright (C) 2006, 2007, 2008, 2009, 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 /** 00142 \brief The header macro for vector-vector addition 00143 00144 Given types \c vec1, \c vec2, and \c vec_3, this macro 00145 provides the function declaration for adding two vectors 00146 using the form 00147 \code 00148 vec1 operator+(const vec2 &x, const vec3 &y); 00149 \endcode 00150 00151 The corresponding definition is given in 00152 \ref O2SCL_OPSRC_VEC_VEC_ADD. 00153 00154 \note This used to be in a separate namespace, called 00155 <tt>o2scl_arith</tt>, but this causes problems with Koenig 00156 lookup in template classes for operator*() when defined 00157 for vector addition (for example). 00158 */ 00159 #define O2SCL_OP_VEC_VEC_ADD(vec1,vec2,vec3) vec1 operator+ \ 00160 (const vec2 &x, const vec3 &y); 00161 00162 #ifndef DOXYGENP 00163 00164 O2SCL_OP_VEC_VEC_ADD(o2scl::ovector,o2scl::ovector_const_view, 00165 o2scl::ovector_const_view) 00166 O2SCL_OP_VEC_VEC_ADD(o2scl::ovector,o2scl::ovector_const_view, 00167 o2scl::uvector_const_view) 00168 O2SCL_OP_VEC_VEC_ADD(o2scl::ovector,o2scl::uvector_const_view, 00169 o2scl::ovector_const_view) 00170 O2SCL_OP_VEC_VEC_ADD(o2scl::uvector,o2scl::uvector_const_view, 00171 o2scl::uvector_const_view) 00172 O2SCL_OP_VEC_VEC_ADD(o2scl::ovector_cx,o2scl::ovector_cx_view, 00173 o2scl::ovector_cx_view) 00174 O2SCL_OP_VEC_VEC_ADD(o2scl::ovector_cx,o2scl::ovector_cx_view, 00175 o2scl::uvector_cx_view) 00176 O2SCL_OP_VEC_VEC_ADD(o2scl::ovector_cx,o2scl::uvector_cx_view, 00177 o2scl::ovector_cx_view) 00178 O2SCL_OP_VEC_VEC_ADD(o2scl::uvector_cx,o2scl::uvector_cx_view, 00179 o2scl::uvector_cx_view) 00180 00181 #endif 00182 00183 #ifdef O2SCL_NEVER_DEFINED 00184 } 00185 { 00186 #endif 00187 00188 /** 00189 \brief The header macro for vector-vector subtraction 00190 00191 Given types \c vec1, \c vec2, and \c vec_3, this macro 00192 provides the function declaration for adding two vectors 00193 using the form 00194 \code 00195 vec1 operator-(const vec2 &x, const vec3 &y); 00196 \endcode 00197 00198 The corresponding definition is given in 00199 \ref O2SCL_OPSRC_VEC_VEC_SUB. 00200 */ 00201 #define O2SCL_OP_VEC_VEC_SUB(vec1,vec2,vec3) vec1 operator- \ 00202 (const vec2 &x, const vec3 &y); 00203 00204 #ifndef DOXYGENP 00205 00206 O2SCL_OP_VEC_VEC_SUB(o2scl::ovector,o2scl::ovector_const_view, 00207 o2scl::ovector_const_view) 00208 O2SCL_OP_VEC_VEC_SUB(o2scl::ovector,o2scl::ovector_const_view, 00209 o2scl::uvector_const_view) 00210 O2SCL_OP_VEC_VEC_SUB(o2scl::ovector,o2scl::uvector_const_view, 00211 o2scl::ovector_const_view) 00212 O2SCL_OP_VEC_VEC_SUB(o2scl::uvector,o2scl::uvector_const_view, 00213 o2scl::uvector_const_view) 00214 O2SCL_OP_VEC_VEC_SUB(o2scl::ovector_cx,o2scl::ovector_cx_view, 00215 o2scl::ovector_cx_view) 00216 O2SCL_OP_VEC_VEC_SUB(o2scl::ovector_cx,o2scl::ovector_cx_view, 00217 o2scl::uvector_cx_view) 00218 O2SCL_OP_VEC_VEC_SUB(o2scl::ovector_cx,o2scl::uvector_cx_view, 00219 o2scl::ovector_cx_view) 00220 O2SCL_OP_VEC_VEC_SUB(o2scl::uvector_cx,o2scl::uvector_cx_view, 00221 o2scl::uvector_cx_view) 00222 00223 #endif 00224 00225 #ifdef O2SCL_NEVER_DEFINED 00226 } 00227 { 00228 #endif 00229 00230 /** 00231 \brief The header macro for matrix-vector (right) multiplication 00232 00233 Given types \c vec1, \c vec2, and \c mat, this macro 00234 provides the function declaration for adding two vectors 00235 using the form 00236 \code 00237 vec1 operator*(const mat &m, const vec3 &x); 00238 \endcode 00239 00240 See also the blas version of this function \ref dgemv(). 00241 00242 The corresponding definition is given in 00243 \ref O2SCL_OPSRC_MAT_VEC_MULT. 00244 00245 */ 00246 #define O2SCL_OP_MAT_VEC_MULT(vec1,vec2,mat) vec1 operator* \ 00247 (const mat &m, const vec2 &x); 00248 00249 #ifndef DOXYGENP 00250 00251 O2SCL_OP_MAT_VEC_MULT(o2scl::ovector,o2scl::ovector_const_view, 00252 o2scl::omatrix_const_view) 00253 O2SCL_OP_MAT_VEC_MULT(o2scl::ovector,o2scl::ovector_const_view, 00254 o2scl::umatrix_const_view) 00255 O2SCL_OP_MAT_VEC_MULT(o2scl::ovector,o2scl::uvector_const_view, 00256 o2scl::omatrix_const_view) 00257 O2SCL_OP_MAT_VEC_MULT(o2scl::uvector,o2scl::uvector_const_view, 00258 o2scl::umatrix_const_view) 00259 00260 #endif 00261 00262 #ifdef O2SCL_NEVER_DEFINED 00263 } 00264 { 00265 #endif 00266 00267 /** 00268 \brief The header macro for complex matrix-vector (right) 00269 multiplication 00270 00271 Given types \c vec1, \c vec2, and \c mat, this macro 00272 provides the function declaration for adding two vectors 00273 using the form 00274 \code 00275 vec1 operator*(const mat &m, const vec3 &x); 00276 \endcode 00277 00278 The corresponding definition is given in 00279 \ref O2SCL_OPSRC_CMAT_CVEC_MULT. 00280 00281 */ 00282 #define O2SCL_OP_CMAT_CVEC_MULT(vec1,vec2,mat) vec1 operator* \ 00283 (const mat &m, const vec2 &x); 00284 00285 #ifndef DOXYGENP 00286 00287 O2SCL_OP_CMAT_CVEC_MULT(o2scl::ovector_cx,o2scl::ovector_cx_view, 00288 o2scl::omatrix_cx_view) 00289 O2SCL_OP_CMAT_CVEC_MULT(o2scl::ovector_cx,o2scl::ovector_cx_view, 00290 o2scl::umatrix_cx_view) 00291 O2SCL_OP_CMAT_CVEC_MULT(o2scl::ovector_cx,o2scl::uvector_cx_view, 00292 o2scl::omatrix_cx_view) 00293 O2SCL_OP_CMAT_CVEC_MULT(o2scl::uvector_cx,o2scl::uvector_cx_view, 00294 o2scl::umatrix_cx_view) 00295 00296 #endif 00297 00298 #ifdef O2SCL_NEVER_DEFINED 00299 } 00300 { 00301 #endif 00302 00303 /** 00304 \brief The header macro for vector-matrix (left) 00305 multiplication 00306 00307 Given types \c vec1, \c vec2, and \c mat, this macro 00308 provides the function declaration for adding two vectors 00309 using the form 00310 \code 00311 vec1 operator*(const vec3 &x, const mat &m); 00312 \endcode 00313 00314 The corresponding definition is given in 00315 \ref O2SCL_OPSRC_VEC_MAT_MULT. 00316 */ 00317 #define O2SCL_OP_VEC_MAT_MULT(vec1,vec2,mat) vec1 operator* \ 00318 (const vec2 &x, const mat &m); 00319 00320 #ifndef DOXYGENP 00321 00322 O2SCL_OP_VEC_MAT_MULT(o2scl::ovector,o2scl::ovector_const_view, 00323 o2scl::omatrix_const_view) 00324 O2SCL_OP_VEC_MAT_MULT(o2scl::ovector,o2scl::ovector_const_view, 00325 o2scl::umatrix_const_view) 00326 O2SCL_OP_VEC_MAT_MULT(o2scl::ovector,o2scl::uvector_const_view, 00327 o2scl::omatrix_const_view) 00328 O2SCL_OP_VEC_MAT_MULT(o2scl::uvector,o2scl::uvector_const_view, 00329 o2scl::umatrix_const_view) 00330 00331 #endif 00332 00333 #ifdef O2SCL_NEVER_DEFINED 00334 } 00335 { 00336 #endif 00337 00338 /// The header macro for the \c trans_mult form of vector * matrix 00339 #define O2SCL_OP_TRANS_MULT(vec1,vec2,mat) vec1 trans_mult \ 00340 (const vec2 &x, const mat &m); 00341 00342 #ifndef DOXYGENP 00343 00344 O2SCL_OP_TRANS_MULT(o2scl::ovector,o2scl::ovector_const_view, 00345 o2scl::omatrix_const_view) 00346 O2SCL_OP_TRANS_MULT(o2scl::ovector,o2scl::ovector_const_view, 00347 o2scl::umatrix_const_view) 00348 O2SCL_OP_TRANS_MULT(o2scl::ovector,o2scl::uvector_const_view, 00349 o2scl::omatrix_const_view) 00350 O2SCL_OP_TRANS_MULT(o2scl::uvector,o2scl::uvector_const_view, 00351 o2scl::umatrix_const_view) 00352 00353 #endif 00354 00355 #ifdef O2SCL_NEVER_DEFINED 00356 } 00357 { 00358 #endif 00359 00360 /** 00361 \brief The header macro for vector scalar (dot) product 00362 00363 Given types \c vec1, \c vec2, and \c dtype, this macro 00364 provides the function declaration for adding two vectors 00365 using the form 00366 \code 00367 dtype operator*(const vec1 &x, const vec2 &y); 00368 \endcode 00369 00370 The corresponding definition is given in 00371 \ref O2SCL_OPSRC_DOT_PROD. 00372 */ 00373 #define O2SCL_OP_DOT_PROD(dtype,vec1,vec2) dtype dot \ 00374 (const vec1 &x, const vec2 &y); 00375 00376 #ifndef DOXYGENP 00377 00378 O2SCL_OP_DOT_PROD(double,o2scl::ovector_const_view, 00379 o2scl::ovector_const_view) 00380 O2SCL_OP_DOT_PROD(double,o2scl::ovector_const_view, 00381 o2scl::uvector_const_view) 00382 O2SCL_OP_DOT_PROD(double,o2scl::uvector_const_view, 00383 o2scl::ovector_const_view) 00384 O2SCL_OP_DOT_PROD(double,o2scl::uvector_const_view, 00385 o2scl::uvector_const_view) 00386 00387 #endif 00388 00389 #ifdef O2SCL_NEVER_DEFINED 00390 } 00391 { 00392 #endif 00393 00394 /** 00395 \brief The header macro for complex vector scalar (dot) 00396 product 00397 00398 Given types \c vec1, \c vec2, and \c dtype, this macro 00399 provides the function declaration for adding two vectors 00400 using the form 00401 \code 00402 dtype operator*(const vec1 &x, const vec2 &y); 00403 \endcode 00404 00405 The corresponding definition is given in 00406 \ref O2SCL_OPSRC_CX_DOT_PROD. 00407 */ 00408 #define O2SCL_OP_CX_DOT_PROD(dtype,vec1,vec2) dtype dot \ 00409 (const vec1 &x, const vec2 &y); 00410 00411 #ifndef DOXYGENP 00412 00413 O2SCL_OP_CX_DOT_PROD(gsl_complex,o2scl::ovector_cx_view, 00414 o2scl::ovector_cx_view) 00415 O2SCL_OP_CX_DOT_PROD(gsl_complex,o2scl::ovector_cx_view, 00416 o2scl::uvector_cx_view) 00417 O2SCL_OP_CX_DOT_PROD(gsl_complex,o2scl::uvector_cx_view, 00418 o2scl::ovector_cx_view) 00419 O2SCL_OP_CX_DOT_PROD(gsl_complex,o2scl::uvector_cx_view, 00420 o2scl::uvector_cx_view) 00421 00422 #endif 00423 00424 #ifdef O2SCL_NEVER_DEFINED 00425 } 00426 { 00427 #endif 00428 00429 /** 00430 \brief The header macro for scalar-vector multiplication 00431 00432 Given types \c vecv, \c vec, and \c dtype, this macro 00433 provides the function declaration for adding two vectors 00434 using the form 00435 \code 00436 vec operator*(const dtype &x, const vecv &y); 00437 \endcode 00438 00439 The corresponding definition is given in 00440 \ref O2SCL_OPSRC_SCA_VEC_MULT. 00441 */ 00442 #define O2SCL_OP_SCA_VEC_MULT(dtype,vecv,vec) vec operator* \ 00443 (const dtype &x, const vecv &y); 00444 00445 #ifndef DOXYGENP 00446 00447 O2SCL_OP_SCA_VEC_MULT(double,o2scl::ovector_const_view,o2scl::ovector) 00448 O2SCL_OP_SCA_VEC_MULT(double,o2scl::uvector_const_view,o2scl::uvector) 00449 00450 #endif 00451 00452 #ifdef O2SCL_NEVER_DEFINED 00453 } 00454 { 00455 #endif 00456 00457 /** 00458 \brief The header macro for vector-scalar multiplication 00459 00460 Given types \c vecv, \c vec, and \c dtype, this macro 00461 provides the function declaration for adding two vectors 00462 using the form 00463 \code 00464 vec operator*(const vecv &x, const dtype &y); 00465 \endcode 00466 00467 The corresponding definition is given in 00468 \ref O2SCL_OPSRC_VEC_SCA_MULT. 00469 */ 00470 #define O2SCL_OP_VEC_SCA_MULT(dtype,vecv,vec) vec operator* \ 00471 (const vecv &x, const dtype &y); 00472 00473 #ifndef DOXYGENP 00474 00475 O2SCL_OP_VEC_SCA_MULT(double,o2scl::ovector_const_view,o2scl::ovector) 00476 O2SCL_OP_VEC_SCA_MULT(double,o2scl::uvector_const_view,o2scl::uvector) 00477 00478 #endif 00479 00480 #ifdef O2SCL_NEVER_DEFINED 00481 } 00482 { 00483 #endif 00484 00485 /** 00486 \brief The header macro for pairwise vector * vector (where either 00487 vector can be real or complex) 00488 00489 Given types \c vec1, \c vec2, and \c vec3, this macro 00490 provides the function declaration for adding two vectors 00491 using the form 00492 \code 00493 vec1 pair_prod(const vec2 &x, const vec3 &y); 00494 \endcode 00495 00496 The corresponding definition is given in 00497 \ref O2SCL_OPSRC_VEC_VEC_PRO. 00498 */ 00499 #define O2SCL_OP_VEC_VEC_PRO(vec1,vec2,vec3) vec1 pair_prod \ 00500 (const vec2 &x, const vec3 &y); 00501 00502 #ifndef DOXYGENP 00503 00504 O2SCL_OP_VEC_VEC_PRO(o2scl::ovector,o2scl::ovector_const_view, 00505 o2scl::ovector_const_view) 00506 O2SCL_OP_VEC_VEC_PRO(o2scl::ovector,o2scl::ovector_const_view, 00507 o2scl::uvector_const_view) 00508 O2SCL_OP_VEC_VEC_PRO(o2scl::ovector,o2scl::uvector_const_view, 00509 o2scl::ovector_const_view) 00510 O2SCL_OP_VEC_VEC_PRO(o2scl::uvector,o2scl::uvector_const_view, 00511 o2scl::uvector_const_view) 00512 O2SCL_OP_VEC_VEC_PRO(o2scl::ovector_cx,o2scl::ovector_cx_view, 00513 o2scl::ovector_const_view) 00514 O2SCL_OP_VEC_VEC_PRO(o2scl::ovector_cx,o2scl::ovector_cx_view, 00515 o2scl::uvector_const_view) 00516 O2SCL_OP_VEC_VEC_PRO(o2scl::ovector_cx,o2scl::uvector_cx_view, 00517 o2scl::ovector_const_view) 00518 O2SCL_OP_VEC_VEC_PRO(o2scl::uvector_cx,o2scl::uvector_cx_view, 00519 o2scl::uvector_const_view) 00520 O2SCL_OP_VEC_VEC_PRO(o2scl::ovector_cx,o2scl::ovector_const_view, 00521 o2scl::ovector_cx_view) 00522 O2SCL_OP_VEC_VEC_PRO(o2scl::ovector_cx,o2scl::ovector_const_view, 00523 o2scl::uvector_cx_view) 00524 O2SCL_OP_VEC_VEC_PRO(o2scl::ovector_cx,o2scl::uvector_const_view, 00525 o2scl::ovector_cx_view) 00526 O2SCL_OP_VEC_VEC_PRO(o2scl::uvector_cx,o2scl::uvector_const_view, 00527 o2scl::uvector_cx_view) 00528 O2SCL_OP_VEC_VEC_PRO(o2scl::ovector_cx,o2scl::ovector_cx_view, 00529 o2scl::ovector_cx_view) 00530 O2SCL_OP_VEC_VEC_PRO(o2scl::ovector_cx,o2scl::ovector_cx_view, 00531 o2scl::uvector_cx_view) 00532 O2SCL_OP_VEC_VEC_PRO(o2scl::ovector_cx,o2scl::uvector_cx_view, 00533 o2scl::ovector_cx_view) 00534 O2SCL_OP_VEC_VEC_PRO(o2scl::uvector_cx,o2scl::uvector_cx_view, 00535 o2scl::uvector_cx_view) 00536 00537 #endif 00538 00539 /** 00540 \brief The source code macro for vector-vector addition 00541 00542 This define macro generates the function definition. See 00543 the function declaration \ref O2SCL_OP_VEC_VEC_ADD 00544 */ 00545 #define O2SCL_OPSRC_VEC_VEC_ADD(vec1,vec2,vec3) vec1 o2scl::operator+ \ 00546 (const vec2 &x, const vec3 &y) { \ 00547 size_t m=x.size(); \ 00548 if (y.size()<m) m=y.size(); \ 00549 vec1 r(m); \ 00550 for(size_t i=0;i<m;i++) { \ 00551 r[i]=x[i]+y[i]; \ 00552 } \ 00553 return r; \ 00554 } 00555 00556 /** 00557 \brief The source code macro for vector-vector subtraction 00558 00559 This define macro generates the function definition. See 00560 the function declaration \ref O2SCL_OP_VEC_VEC_SUB 00561 */ 00562 #define O2SCL_OPSRC_VEC_VEC_SUB(vec1,vec2,vec3) vec1 o2scl::operator- \ 00563 (const vec2 &x, const vec3 &y) { \ 00564 size_t m=x.size(); \ 00565 if (y.size()<m) m=y.size(); \ 00566 vec1 r(m); \ 00567 for(size_t i=0;i<m;i++) { \ 00568 r[i]=x[i]-y[i]; \ 00569 } \ 00570 return r; \ 00571 } 00572 00573 /** 00574 \brief The source code macro for matrix * vector 00575 00576 This define macro generates the function definition. See 00577 the function declaration \ref O2SCL_OP_MAT_VEC_MULT 00578 */ 00579 #define O2SCL_OPSRC_MAT_VEC_MULT(vec1,vec2,mat) vec1 o2scl::operator* \ 00580 (const mat &m, const vec2 &x) { \ 00581 size_t nr=m.rows(); \ 00582 size_t nc=m.cols(); \ 00583 vec1 res(nr); \ 00584 for(size_t i=0;i<nr;i++) { \ 00585 double r=0.0; \ 00586 for(size_t j=0;j<nc;j++) { \ 00587 r+=m[i][j]*x[j]; \ 00588 } \ 00589 res[i]=r; \ 00590 } \ 00591 return res; \ 00592 } 00593 00594 /** 00595 \brief The source code macro for complex matrix * complex vector 00596 00597 This define macro generates the function definition. See 00598 the function declaration \ref O2SCL_OP_CMAT_CVEC_MULT 00599 */ 00600 #define O2SCL_OPSRC_CMAT_CVEC_MULT(vec1,vec2,mat) vec1 o2scl::operator* \ 00601 (const mat &m, const vec2 &x) { \ 00602 size_t nr=m.rows(); \ 00603 size_t nc=m.cols(); \ 00604 vec1 res(nr); \ 00605 for(size_t i=0;i<nr;i++) { \ 00606 double re=0.0; \ 00607 double im=0.0; \ 00608 for(size_t j=0;j<nc;j++) { \ 00609 gsl_complex g=m[i][j]*x[j]; \ 00610 re+=g.dat[0]; \ 00611 im+=g.dat[1]; \ 00612 } \ 00613 res[i].dat[0]=re; \ 00614 res[i].dat[1]=im; \ 00615 } \ 00616 return res; \ 00617 } 00618 00619 /** 00620 \brief The source code macro for the operator form of vector * matrix 00621 00622 This define macro generates the function definition. See 00623 the function declaration \ref O2SCL_OP_VEC_MAT_MULT 00624 */ 00625 #define O2SCL_OPSRC_VEC_MAT_MULT(vec1,vec2,mat) vec1 o2scl::operator* \ 00626 (const vec2 &x, const mat &m) { \ 00627 size_t nr=m.rows(); \ 00628 size_t nc=m.cols(); \ 00629 vec1 res(nr); \ 00630 for(size_t j=0;j<nc;j++) { \ 00631 double r=0.0; \ 00632 for(size_t i=0;i<nr;i++) { \ 00633 r+=x[i]*m[i][j]; \ 00634 } \ 00635 res[j]=r; \ 00636 } \ 00637 return res; \ 00638 } 00639 00640 /** 00641 \brief The source code macro for the \c trans_mult form of 00642 vector * matrix 00643 00644 This define macro generates the function definition. See 00645 the function declaration \ref O2SCL_OP_TRANS_MULT 00646 */ 00647 #define O2SCL_OPSRC_TRANS_MULT(vec1,vec2,mat) vec1 o2scl::trans_mult \ 00648 (const vec2 &x, const mat &m) { \ 00649 size_t nr=m.rows(); \ 00650 size_t nc=m.cols(); \ 00651 vec1 res(nr); \ 00652 for(size_t j=0;j<nc;j++) { \ 00653 double r=0.0; \ 00654 for(size_t i=0;i<nr;i++) { \ 00655 r+=x[i]*m[i][j]; \ 00656 } \ 00657 res[j]=r; \ 00658 } \ 00659 return res; \ 00660 } 00661 00662 /** 00663 \brief The source code macro for a vector dot product 00664 00665 This define macro generates the function definition. See 00666 the function declaration \ref O2SCL_OP_DOT_PROD 00667 */ 00668 #define O2SCL_OPSRC_DOT_PROD(dtype,vec1,vec2) dtype o2scl::dot \ 00669 (const vec1 &x, const vec2 &y) { \ 00670 size_t m=x.size(); \ 00671 if (y.size()<m) m=y.size(); \ 00672 dtype r=0; \ 00673 for(size_t i=0;i<m;i++) { \ 00674 r+=x[i]*y[i]; \ 00675 } \ 00676 return r; \ 00677 } 00678 00679 /** 00680 \brief The source code macro for a complex vector dot product 00681 00682 This define macro generates the function definition. See 00683 the function declaration \ref O2SCL_OP_CX_DOT_PROD 00684 */ 00685 #define O2SCL_OPSRC_CX_DOT_PROD(dtype,vec1,vec2) dtype o2scl::dot \ 00686 (const vec1 &x, const vec2 &y) { \ 00687 size_t m=x.size(); \ 00688 if (y.size()<m) m=y.size(); \ 00689 dtype r={{0.0,0.0}}; \ 00690 for(size_t i=0;i<m;i++) { \ 00691 r+=x[i]*y[i]; \ 00692 } \ 00693 return r; \ 00694 } 00695 00696 /** 00697 \brief The source code macro for vector=scalar*vector 00698 00699 This define macro generates the function definition. See 00700 the function declaration \ref O2SCL_OP_SCA_VEC_MULT 00701 */ 00702 #define O2SCL_OPSRC_SCA_VEC_MULT(dtype,vecv,vec) vec o2scl::operator* \ 00703 (const dtype &x, const vecv &y) { \ 00704 size_t m=y.size(); \ 00705 vec r(m); \ 00706 for(size_t i=0;i<m;i++) { \ 00707 r[i]=x*y[i]; \ 00708 } \ 00709 return r; \ 00710 } 00711 00712 /** 00713 \brief The source code macro for vector=vector*scalar 00714 00715 This define macro generates the function definition. See 00716 the function declaration \ref O2SCL_OP_VEC_SCA_MULT 00717 */ 00718 #define O2SCL_OPSRC_VEC_SCA_MULT(dtype,vecv,vec) vec o2scl::operator* \ 00719 (const vecv &x, const dtype &y) { \ 00720 size_t m=x.size(); \ 00721 vec r(m); \ 00722 for(size_t i=0;i<m;i++) { \ 00723 r[i]=x[i]*y; \ 00724 } \ 00725 return r; \ 00726 } 00727 00728 /** 00729 \brief The source code macro for pairwise vector * vector (where 00730 either vector can be real or complex) 00731 00732 This define macro generates the function definition. See 00733 the function declaration \ref O2SCL_OP_VEC_VEC_PRO 00734 */ 00735 #define O2SCL_OPSRC_VEC_VEC_PRO(vec1,vec2,vec3) vec1 o2scl::pair_prod \ 00736 (const vec2 &x, const vec3 &y) { \ 00737 size_t m=x.size(); \ 00738 if (y.size()<m) m=y.size(); \ 00739 vec1 r(m); \ 00740 for(size_t i=0;i<m;i++) { \ 00741 r[i]=x[i]*y[i]; \ 00742 } \ 00743 return r; \ 00744 } 00745 00746 /** 00747 \brief The header macro for vector==vector 00748 00749 Given types \c vec1 and \c vec2, this macro provides the 00750 function declaration for vector equality comparisons using 00751 \code 00752 bool operator==(const vec1 &x, const vec2 &y); 00753 \endcode 00754 00755 \note Two vectors with different sizes are defined to 00756 be not equal, no matter what their contents. 00757 00758 The corresponding definition is given in 00759 \ref O2SCL_OPSRC_VEC_VEC_EQUAL. 00760 */ 00761 #define O2SCL_OP_VEC_VEC_EQUAL(vec1,vec2) bool operator== \ 00762 (const vec1 &x, const vec2 &y); 00763 00764 #ifndef DOXYGENP 00765 00766 O2SCL_OP_VEC_VEC_EQUAL(o2scl::ovector_const_view, 00767 o2scl::ovector_const_view) 00768 O2SCL_OP_VEC_VEC_EQUAL(o2scl::ovector_const_view, 00769 o2scl::uvector_const_view) 00770 O2SCL_OP_VEC_VEC_EQUAL(o2scl::uvector_const_view, 00771 o2scl::ovector_const_view) 00772 O2SCL_OP_VEC_VEC_EQUAL(o2scl::uvector_const_view, 00773 o2scl::uvector_const_view) 00774 /* 00775 O2SCL_OP_VEC_VEC_EQUAL(o2scl::ovector_cx_view, 00776 o2scl::ovector_const_view) 00777 O2SCL_OP_VEC_VEC_EQUAL(o2scl::ovector_cx_view, 00778 o2scl::uvector_const_view) 00779 O2SCL_OP_VEC_VEC_EQUAL(o2scl::uvector_cx_view, 00780 o2scl::ovector_const_view) 00781 O2SCL_OP_VEC_VEC_EQUAL(o2scl::uvector_cx_view, 00782 o2scl::uvector_const_view) 00783 O2SCL_OP_VEC_VEC_EQUAL(o2scl::ovector_const_view, 00784 o2scl::ovector_cx_view) 00785 O2SCL_OP_VEC_VEC_EQUAL(o2scl::ovector_const_view, 00786 o2scl::uvector_cx_view) 00787 O2SCL_OP_VEC_VEC_EQUAL(o2scl::uvector_const_view, 00788 o2scl::ovector_cx_view) 00789 O2SCL_OP_VEC_VEC_EQUAL(o2scl::uvector_const_view, 00790 o2scl::uvector_cx_view) 00791 O2SCL_OP_VEC_VEC_EQUAL(o2scl::ovector_cx_view, 00792 o2scl::ovector_cx_view) 00793 O2SCL_OP_VEC_VEC_EQUAL(o2scl::ovector_cx_view, 00794 o2scl::uvector_cx_view) 00795 O2SCL_OP_VEC_VEC_EQUAL(o2scl::uvector_cx_view, 00796 o2scl::ovector_cx_view) 00797 O2SCL_OP_VEC_VEC_EQUAL(o2scl::uvector_cx_view, 00798 o2scl::uvector_cx_view) 00799 */ 00800 00801 #endif 00802 00803 #ifdef O2SCL_NEVER_DEFINED 00804 } 00805 { 00806 #endif 00807 00808 /** 00809 \brief The source code macro vector==vector 00810 00811 \note Two vectors with different sizes are defined to 00812 be not equal, no matter what their contents. 00813 00814 This define macro generates the function definition. See 00815 the function declaration \ref O2SCL_OP_VEC_VEC_EQUAL 00816 */ 00817 #define O2SCL_OPSRC_VEC_VEC_EQUAL(vec1,vec2) bool o2scl::operator== \ 00818 (const vec1 &x, const vec2 &y) { \ 00819 size_t m=x.size(); \ 00820 size_t n=y.size(); \ 00821 if (m!=n) return false; \ 00822 for(size_t i=0;i<m;i++) { \ 00823 if (x[i]!=y[i]) return false; \ 00824 } \ 00825 return true; \ 00826 } 00827 00828 /** 00829 \brief The header macro for vector!=vector 00830 00831 Given types \c vec1 and \c vec2, this macro provides the 00832 function declaration for vector inequality comparisons using 00833 \code 00834 bool operator==(const vec1 &x, const vec2 &y); 00835 \endcode 00836 00837 \note Two vectors with different sizes are defined to 00838 be not equal, no matter what their contents. 00839 00840 The corresponding definition is given in 00841 \ref O2SCL_OPSRC_VEC_VEC_NEQUAL. 00842 */ 00843 #define O2SCL_OP_VEC_VEC_NEQUAL(vec1,vec2) bool operator!= \ 00844 (const vec1 &x, const vec2 &y); 00845 00846 #ifndef DOXYGENP 00847 00848 O2SCL_OP_VEC_VEC_NEQUAL(o2scl::ovector_const_view, 00849 o2scl::ovector_const_view) 00850 O2SCL_OP_VEC_VEC_NEQUAL(o2scl::ovector_const_view, 00851 o2scl::uvector_const_view) 00852 O2SCL_OP_VEC_VEC_NEQUAL(o2scl::uvector_const_view, 00853 o2scl::ovector_const_view) 00854 O2SCL_OP_VEC_VEC_NEQUAL(o2scl::uvector_const_view, 00855 o2scl::uvector_const_view) 00856 /* 00857 O2SCL_OP_VEC_VEC_NEQUAL(o2scl::ovector_cx_view, 00858 o2scl::ovector_const_view) 00859 O2SCL_OP_VEC_VEC_NEQUAL(o2scl::ovector_cx_view, 00860 o2scl::uvector_const_view) 00861 O2SCL_OP_VEC_VEC_NEQUAL(o2scl::uvector_cx_view, 00862 o2scl::ovector_const_view) 00863 O2SCL_OP_VEC_VEC_NEQUAL(o2scl::uvector_cx_view, 00864 o2scl::uvector_const_view) 00865 O2SCL_OP_VEC_VEC_NEQUAL(o2scl::ovector_const_view, 00866 o2scl::ovector_cx_view) 00867 O2SCL_OP_VEC_VEC_NEQUAL(o2scl::ovector_const_view, 00868 o2scl::uvector_cx_view) 00869 O2SCL_OP_VEC_VEC_NEQUAL(o2scl::uvector_const_view, 00870 o2scl::ovector_cx_view) 00871 O2SCL_OP_VEC_VEC_NEQUAL(o2scl::uvector_const_view, 00872 o2scl::uvector_cx_view) 00873 O2SCL_OP_VEC_VEC_NEQUAL(o2scl::ovector_cx_view, 00874 o2scl::ovector_cx_view) 00875 O2SCL_OP_VEC_VEC_NEQUAL(o2scl::ovector_cx_view, 00876 o2scl::uvector_cx_view) 00877 O2SCL_OP_VEC_VEC_NEQUAL(o2scl::uvector_cx_view, 00878 o2scl::ovector_cx_view) 00879 O2SCL_OP_VEC_VEC_NEQUAL(o2scl::uvector_cx_view, 00880 o2scl::uvector_cx_view) 00881 */ 00882 00883 #endif 00884 00885 #ifdef O2SCL_NEVER_DEFINED 00886 } 00887 { 00888 #endif 00889 00890 /** 00891 \brief The source code macro vector!=vector 00892 00893 \note Two vectors with different sizes are defined to 00894 be not equal, no matter what their contents. 00895 00896 This define macro generates the function definition. See 00897 the function declaration \ref O2SCL_OP_VEC_VEC_NEQUAL 00898 */ 00899 #define O2SCL_OPSRC_VEC_VEC_NEQUAL(vec1,vec2) bool o2scl::operator!= \ 00900 (const vec1 &x, const vec2 &y) { \ 00901 size_t m=x.size(); \ 00902 size_t n=y.size(); \ 00903 if (m!=n) return true; \ 00904 for(size_t i=0;i<m;i++) { \ 00905 if (x[i]!=y[i]) return true; \ 00906 } \ 00907 return false; \ 00908 } 00909 00910 #ifndef DOXYGENP 00911 // end of o2scl namespace 00912 } 00913 #endif 00914 00915 #endif
Documentation generated with Doxygen and provided under the GNU Free Documentation License. See License Information for details.
Project hosting provided by
,
O2scl Sourceforge Project Page