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