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