00001 00031 #include <itpp/fixed/fix_operators.h> 00032 00033 00034 namespace itpp { 00035 00037 // Operators for Fix and Fixed // 00039 00040 Fix operator+(const Fix &x, const Fix &y) 00041 { 00042 return Fix(x.get_re() + y.get_re(), 00043 assert_shifts(x, y), 00044 0, 0); 00045 } 00046 00047 Fix operator-(const Fix &x, const Fix &y) 00048 { 00049 return Fix(x.get_re() - y.get_re(), 00050 assert_shifts(x, y), 00051 0, 0); 00052 } 00053 00054 Fix operator*(const Fix &x, const Fix &y) 00055 { 00056 return Fix(x.get_re() * y.get_re(), 00057 x.get_shift() + y.get_shift(), 00058 0, 0); 00059 } 00060 00061 Fix operator/(const Fix &x, const Fix &y) 00062 { 00063 return Fix(x.get_re() / y.get_re(), 00064 x.get_shift() - y.get_shift(), 00065 0, 0); 00066 } 00067 00068 Fix operator+(const Fix &x, const int y) 00069 { 00070 return Fix(x.get_re() + y, 00071 assert_shifts(x, y), 00072 0, 0); 00073 } 00074 00075 Fix operator-(const Fix &x, const int y) 00076 { 00077 return Fix(x.get_re() - y, 00078 assert_shifts(x, y), 00079 0, 0); 00080 } 00081 00082 Fix operator*(const Fix &x, const int y) 00083 { 00084 return Fix(x.get_re() * y, 00085 x.get_shift(), 00086 0, 0); 00087 } 00088 00089 Fix operator/(const Fix &x, const int y) 00090 { 00091 return Fix(x.get_re() / y, 00092 x.get_shift(), 00093 0, 0); 00094 } 00095 00096 Fix operator+(const int x, const Fix &y) 00097 { 00098 return Fix(x + y.get_re(), 00099 assert_shifts(y, x), 00100 0, 0); 00101 } 00102 00103 Fix operator-(const int x, const Fix &y) 00104 { 00105 return Fix(x - y.get_re(), 00106 assert_shifts(y, x), 00107 0, 0); 00108 } 00109 00110 Fix operator*(const int x, const Fix &y) 00111 { 00112 return Fix(x * y.get_re(), 00113 y.get_shift(), 00114 0, 0); 00115 } 00116 00117 Fix operator/(const int x, const Fix &y) 00118 { 00119 return Fix(x / y.get_re(), 00120 -y.get_shift(), 00121 0, 0); 00122 } 00123 00124 00125 fixvec operator+(const fixvec &a, const ivec &b) 00126 { 00127 it_assert_debug(a.size() == b.size(), "operator+(): sizes do not match"); 00128 fixvec temp(a); 00129 for (int i=0; i<a.size(); i++) { 00130 temp(i) += b(i); 00131 } 00132 return temp; 00133 } 00134 00135 Fix operator*(const fixvec &a, const ivec &b) 00136 { 00137 it_assert_debug(a.size() == b.size(), "operator+(): sizes do not match"); 00138 Fix temp(0); 00139 for (int i=0; i<a.size(); i++) { 00140 temp += a(i) * b(i); 00141 } 00142 return temp; 00143 } 00144 00145 fixmat operator+(const fixmat &a, const imat &b) 00146 { 00147 it_assert_debug(a.cols()==b.cols() && a.rows()==b.rows(), "operator+(): sizes do not match"); 00148 fixmat temp(a); 00149 00150 for (int i=0; i<a.rows(); i++) { 00151 for (int j=0; j<a.cols(); j++) { 00152 temp(i,j) += b(i,j); 00153 } 00154 } 00155 return temp; 00156 } 00157 00158 fixmat operator*(const fixmat &a, const imat &b) 00159 { 00160 it_assert_debug(a.cols() == b.rows(), "operator*: wrong sizes"); 00161 fixmat r(a.rows(), b.cols()); 00162 00163 Fix tmp; 00164 int i, j, k; 00165 Fix *tr=r._data(); 00166 const Fix *t1; 00167 const int *t2=b._data(); 00168 00169 for (i=0; i<r.cols(); i++) { 00170 for (j=0; j<r.rows(); j++) { 00171 tmp = Fix(0); t1 = a._data()+j; 00172 for (k=a.cols(); k>0; k--) { 00173 tmp += *(t1) * *(t2++); 00174 t1 += a.rows(); 00175 } 00176 *(tr++) = tmp; t2 -= b.rows(); 00177 } 00178 t2 += b.rows(); 00179 } 00180 return r; 00181 } 00182 00184 // Operators for CFix and CFixed // 00186 00187 CFix operator+(const CFix &x, const CFix &y) 00188 { 00189 return CFix(x.get_re() + y.get_re(), 00190 x.get_im() + y.get_im(), 00191 assert_shifts(x, y), 00192 0, 0); 00193 } 00194 00195 CFix operator-(const CFix &x, const CFix &y) 00196 { 00197 return CFix(x.get_re() - y.get_re(), 00198 x.get_im() - y.get_im(), 00199 assert_shifts(x, y), 00200 0, 0); 00201 } 00202 00203 CFix operator*(const CFix &x, const CFix &y) 00204 { 00205 return CFix(x.get_re()*y.get_re() - x.get_im()*y.get_im(), 00206 x.get_re()*y.get_im() + x.get_im()*y.get_re(), 00207 x.get_shift() + y.get_shift(), 00208 0, 0); 00209 } 00210 00211 CFix operator/(const CFix &x, const CFix &y) 00212 { 00213 fixrep denominator = y.get_re()*y.get_re() + y.get_im()*y.get_im(); 00214 return CFix((x.get_re()*y.get_re() + x.get_im()*y.get_im())/denominator, 00215 (x.get_im()*y.get_re() - x.get_re()*y.get_im())/denominator, 00216 x.get_shift() - y.get_shift(), 00217 0, 0); 00218 } 00219 00220 CFix operator+(const CFix &x, const Fix &y) 00221 { 00222 return CFix(x.get_re() + y.get_re(), 00223 x.get_im(), 00224 assert_shifts(x, y), 00225 0, 0); 00226 } 00227 00228 CFix operator-(const CFix &x, const Fix &y) 00229 { 00230 return CFix(x.get_re() - y.get_re(), 00231 x.get_im(), 00232 assert_shifts(x, y), 00233 0, 0); 00234 } 00235 00236 CFix operator*(const CFix &x, const Fix &y) 00237 { 00238 return CFix(x.get_re() * y.get_re(), 00239 x.get_im() * y.get_re(), 00240 x.get_shift() + y.get_shift(), 00241 0, 0); 00242 } 00243 00244 CFix operator/(const CFix &x, const Fix &y) 00245 { 00246 return CFix(x.get_re() / y.get_re(), 00247 x.get_im() / y.get_re(), 00248 x.get_shift() - y.get_shift(), 00249 0, 0); 00250 } 00251 00252 CFix operator+(const Fix &x, const CFix &y) 00253 { 00254 return CFix(x.get_re() + y.get_re(), 00255 y.get_im(), 00256 assert_shifts(y, x), 00257 0, 0); 00258 } 00259 00260 CFix operator-(const Fix &x, const CFix &y) 00261 { 00262 return CFix(x.get_re() - y.get_re(), 00263 -y.get_im(), 00264 assert_shifts(y, x), 00265 0, 0); 00266 } 00267 00268 CFix operator*(const Fix &x, const CFix &y) 00269 { 00270 return CFix(x.get_re() * y.get_re(), 00271 x.get_re() * y.get_im(), 00272 x.get_shift() + y.get_shift(), 00273 0, 0); 00274 } 00275 00276 CFix operator/(const Fix &x, const CFix &y) 00277 { 00278 fixrep denominator = y.get_re()*y.get_re() + y.get_im()*y.get_im(); 00279 return CFix(x.get_re() * y.get_re() / denominator, 00280 -x.get_re() * y.get_im() / denominator, 00281 x.get_shift() - y.get_shift(), 00282 0, 0); 00283 } 00284 00285 CFix operator+(const CFix &x, const int y) 00286 { 00287 return CFix(x.get_re() + y, 00288 x.get_im(), 00289 assert_shifts(x, y), 00290 0, 0); 00291 } 00292 00293 CFix operator-(const CFix &x, const int y) 00294 { 00295 return CFix(x.get_re() - y, 00296 x.get_im(), 00297 assert_shifts(x, y), 00298 0, 0); 00299 } 00300 00301 CFix operator*(const CFix &x, const int y) 00302 { 00303 return CFix(x.get_re() * y, 00304 x.get_im() * y, 00305 x.get_shift(), 00306 0, 0); 00307 } 00308 00309 CFix operator/(const CFix &x, const int y) 00310 { 00311 return CFix(x.get_re() / y, 00312 x.get_im() / y, 00313 x.get_shift(), 00314 0, 0); 00315 } 00316 00317 CFix operator+(const int x, const CFix &y) 00318 { 00319 return CFix(x + y.get_re(), 00320 y.get_im(), 00321 assert_shifts(y, x), 00322 0, 0); 00323 } 00324 00325 CFix operator-(const int x, const CFix &y) 00326 { 00327 return CFix(x - y.get_re(), 00328 -y.get_im(), 00329 assert_shifts(y, x), 00330 0, 0); 00331 } 00332 00333 CFix operator*(const int x, const CFix &y) 00334 { 00335 return CFix(x * y.get_re(), 00336 x * y.get_im(), 00337 y.get_shift(), 00338 0, 0); 00339 } 00340 00341 CFix operator/(const int x, const CFix &y) 00342 { 00343 fixrep denominator = y.get_re()*y.get_re() + y.get_im()*y.get_im(); 00344 return CFix(x * y.get_re() / denominator, 00345 -x * y.get_im() / denominator, 00346 -y.get_shift(), 00347 0, 0); 00348 } 00349 00350 cfixvec operator+(const cfixvec &a, const fixvec &b) 00351 { 00352 it_assert_debug(a.size() == b.size(), "operator+(): sizes do not match"); 00353 cfixvec temp(a); 00354 for (int i=0; i<a.size(); i++) { 00355 temp(i) += b(i); 00356 } 00357 return temp; 00358 } 00359 00360 CFix operator*(const cfixvec &a, const fixvec &b) 00361 { 00362 it_assert_debug(a.size() == b.size(), "operator+(): sizes do not match"); 00363 CFix temp(0); 00364 for (int i=0; i<a.size(); i++) { 00365 temp += a(i) * b(i); 00366 } 00367 return temp; 00368 } 00369 00370 cfixmat operator+(const cfixmat &a, const fixmat &b) 00371 { 00372 it_assert_debug(a.cols()==b.cols() && a.rows()==b.rows(), "operator+(): sizes do not match"); 00373 cfixmat temp(a); 00374 00375 for (int i=0; i<a.rows(); i++) { 00376 for (int j=0; j<a.cols(); j++) { 00377 temp(i,j) += b(i,j); 00378 } 00379 } 00380 return temp; 00381 } 00382 00383 cfixmat operator*(const cfixmat &a, const fixmat &b) 00384 { 00385 it_assert_debug(a.cols() == b.rows(), "operator*: wrong sizes"); 00386 cfixmat r(a.rows(), b.cols()); 00387 00388 CFix tmp; 00389 int i, j, k; 00390 CFix *tr=r._data(); 00391 const CFix *t1; 00392 const Fix *t2=b._data(); 00393 00394 for (i=0; i<r.cols(); i++) { 00395 for (j=0; j<r.rows(); j++) { 00396 tmp = CFix(0); t1 = a._data()+j; 00397 for (k=a.cols(); k>0; k--) { 00398 tmp += *(t1) * *(t2++); 00399 t1 += a.rows(); 00400 } 00401 *(tr++) = tmp; t2 -= b.rows(); 00402 } 00403 t2 += b.rows(); 00404 } 00405 return r; 00406 } 00407 00408 cfixvec operator+(const cfixvec &a, const ivec &b) 00409 { 00410 it_assert_debug(a.size() == b.size(), "operator+(): sizes do not match"); 00411 cfixvec temp(a); 00412 for (int i=0; i<a.size(); i++) { 00413 temp(i) += b(i); 00414 } 00415 return temp; 00416 } 00417 00418 CFix operator*(const cfixvec &a, const ivec &b) 00419 { 00420 it_assert_debug(a.size() == b.size(), "operator+(): sizes do not match"); 00421 CFix temp(0); 00422 for (int i=0; i<a.size(); i++) { 00423 temp += a(i) * b(i); 00424 } 00425 return temp; 00426 } 00427 00428 cfixmat operator+(const cfixmat &a, const imat &b) 00429 { 00430 it_assert_debug(a.cols()==b.cols() && a.rows()==b.rows(), "operator+(): sizes do not match"); 00431 cfixmat temp(a); 00432 00433 for (int i=0; i<a.rows(); i++) { 00434 for (int j=0; j<a.cols(); j++) { 00435 temp(i,j) += b(i,j); 00436 } 00437 } 00438 return temp; 00439 } 00440 00441 cfixmat operator*(const cfixmat &a, const imat &b) 00442 { 00443 it_assert_debug(a.cols() == b.rows(), "operator*: wrong sizes"); 00444 cfixmat r(a.rows(), b.cols()); 00445 00446 CFix tmp; 00447 int i, j, k; 00448 CFix *tr=r._data(); 00449 const CFix *t1; 00450 const int *t2=b._data(); 00451 00452 for (i=0; i<r.cols(); i++) { 00453 for (j=0; j<r.rows(); j++) { 00454 tmp = CFix(0); t1 = a._data()+j; 00455 for (k=a.cols(); k>0; k--) { 00456 tmp += *(t1) * *(t2++); 00457 t1 += a.rows(); 00458 } 00459 *(tr++) = tmp; t2 -= b.rows(); 00460 } 00461 t2 += b.rows(); 00462 } 00463 return r; 00464 } 00465 00466 } // namespace itpp
Generated on Sun Apr 20 12:40:06 2008 for IT++ by Doxygen 1.5.5