00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059 #include "./Blas.h"
00060 #include "mkl.h"
00061
00062
00063 namespace Blas
00064 {
00065
00066
00067
00068
00069 float Asum(Vector<float>& x)
00070 {
00071 return cblas_sasum(x.Length(), x.DataPtr(), 1);
00072 }
00073
00074 double Asum(Vector<double>& x)
00075 {
00076 return cblas_dasum(x.Length(), x.DataPtr(), 1);
00077 }
00078
00079 float Asum(Vector<ComplexFloat>& x)
00080 {
00081 return cblas_scasum(x.Length(), x.DataPtr(), 1);
00082 }
00083
00084 double Asum(Vector<ComplexDouble>& x)
00085 {
00086 return cblas_dzasum(x.Length(), x.DataPtr(), 1);
00087 }
00088
00089
00090
00091
00092
00093 void Axpy(float alpha, Vector<float>& x, Vector<float>& y)
00094 {
00095 if(x.Length() != y.Length())
00096 {
00097 cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00098 Utility::RunTimeError("Vector lengths are not the same!");
00099 }
00100 cblas_saxpy(x.Length(), alpha, x.DataPtr(), 1, y.Data(), 1);
00101 }
00102
00103 void Axpy(double alpha, Vector<double>& x, Vector<double>& y)
00104 {
00105 if(x.Length() != y.Length())
00106 {
00107 cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00108 Utility::RunTimeError("Vector lengths are not the same!");
00109 }
00110 cblas_daxpy(x.Length(), alpha, x.DataPtr(), 1, y.Data(), 1);
00111 }
00112
00113 void Axpy(ComplexFloat alpha, Vector<ComplexFloat>& x, Vector<ComplexFloat>& y)
00114 {
00115 if(x.Length() != y.Length())
00116 {
00117 cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00118 Utility::RunTimeError("Vector lengths are not the same!");
00119 }
00120 cblas_caxpy(x.Length(), &alpha, x.DataPtr(), 1, y.Data(), 1);
00121 }
00122
00123 void Axpy(ComplexDouble alpha, Vector<ComplexDouble>& x, Vector<ComplexDouble>& y)
00124 {
00125 if(x.Length() != y.Length())
00126 {
00127 cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00128 Utility::RunTimeError("Vector lengths are not the same!");
00129 }
00130 cblas_zaxpy(x.Length(), &alpha, x.DataPtr(), 1, y.Data(), 1);
00131 }
00132
00133
00134
00135
00136
00137
00138
00139 void Copy(Vector<float>& x, Vector<float>& y)
00140 {
00141 if(x.Length() != y.Length())
00142 {
00143 cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00144 Utility::RunTimeError("Vector lengths are not the same!");
00145 }
00146 cblas_scopy(x.Length(), x.DataPtr(), 1, y.Data(), 1);
00147 }
00148
00149 void Copy(Vector<double>& x, Vector<double>& y)
00150 {
00151 if(x.Length() != y.Length())
00152 {
00153 cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00154 Utility::RunTimeError("Vector lengths are not the same!");
00155 }
00156 cblas_dcopy(x.Length(), x.DataPtr(), 1, y.Data(), 1);
00157 }
00158
00159 void Copy(Vector<ComplexFloat>& x, Vector<ComplexFloat>& y)
00160 {
00161 if(x.Length() != y.Length())
00162 {
00163 cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00164 Utility::RunTimeError("Vector lengths are not the same!");
00165 }
00166 cblas_ccopy(x.Length(), x.DataPtr(), 1, y.Data(), 1);
00167 }
00168
00169 void Copy(Vector<ComplexDouble>& x, Vector<ComplexDouble>& y)
00170 {
00171 if(x.Length() != y.Length())
00172 {
00173 cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00174 Utility::RunTimeError("Vector lengths are not the same!");
00175 }
00176 cblas_zcopy(x.Length(), x.DataPtr(), 1, y.Data(), 1);
00177 }
00178
00179
00180
00181
00182
00183 float Dot(Vector<float>& x, Vector<float>& y)
00184 {
00185 if(x.Length() != y.Length())
00186 {
00187 cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00188 Utility::RunTimeError("Vector lengths are not the same!");
00189 }
00190 return cblas_sdot(x.Length(), x.DataPtr(), 1, y.Data(), 1);
00191 }
00192
00193 double Dot(Vector<double>& x, Vector<double>& y)
00194 {
00195 if(x.Length() != y.Length())
00196 {
00197 cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00198 Utility::RunTimeError("Vector lengths are not the same!");
00199 }
00200 return cblas_ddot(x.Length(), x.DataPtr(), 1, y.Data(), 1);
00201 }
00202
00203 ComplexFloat Dot(Vector<ComplexFloat>& x, Vector<ComplexFloat>& y, bool conjugated)
00204 {
00205 if(x.Length() != y.Length())
00206 {
00207 cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00208 Utility::RunTimeError("Vector lengths are not the same!");
00209 }
00210
00211 ComplexFloat result;
00212 if(conjugated)
00213 {
00214 cblas_cdotc_sub(x.Length(), x.DataPtr(), 1, y.Data(), 1, &result);
00215 }
00216 else
00217 {
00218 cblas_cdotu_sub(x.Length(), x.DataPtr(), 1, y.Data(), 1, &result);
00219 }
00220 return result;
00221 }
00222
00223 ComplexDouble Dot(Vector<ComplexDouble>& x, Vector<ComplexDouble>& y, bool conjugated)
00224 {
00225 if(x.Length() != y.Length())
00226 {
00227 cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00228 Utility::RunTimeError("Vector lengths are not the same!");
00229 }
00230
00231 ComplexDouble result;
00232 if(conjugated)
00233 {
00234 cblas_zdotc_sub(x.Length(), x.DataPtr(), 1, y.Data(), 1, &result);
00235 }
00236 else
00237 {
00238 cblas_zdotu_sub(x.Length(), x.DataPtr(), 1, y.Data(), 1, &result);
00239 }
00240 return result;
00241 }
00242
00243 ComplexFloat Dot(Vector<ComplexFloat>& x, Vector<ComplexFloat>& y)
00244 {
00245 return Dot(x, y, false);
00246 }
00247
00248 ComplexDouble Dot(Vector<ComplexDouble>& x, Vector<ComplexDouble>& y)
00249 {
00250 return Dot(x, y, false);
00251 }
00252
00253
00254
00255
00256
00257 float Nrm2(Vector<float>& x)
00258 {
00259 return cblas_snrm2(x.Length(), x.DataPtr(), 1);
00260 }
00261
00262 double Nrm2(Vector<double>& x)
00263 {
00264 return cblas_dnrm2(x.Length(), x.DataPtr(), 1);
00265 }
00266
00267 float Nrm2(Vector<ComplexFloat>& x)
00268 {
00269 return cblas_scnrm2(x.Length(), x.DataPtr(), 1);
00270 }
00271
00272 double Nrm2(Vector<ComplexDouble>& x)
00273 {
00274 return cblas_dznrm2(x.Length(), x.DataPtr(), 1);
00275 }
00276
00277
00278
00279
00280
00281
00282
00283
00284 void Rot(Vector<float>& x, Vector<float>& y, const float c, const float s)
00285 {
00286 if(x.Length() != y.Length())
00287 {
00288 cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00289 Utility::RunTimeError("Vector lengths are not the same!");
00290 }
00291 cblas_srot(x.Length(), x.Data(), 1, y.Data(), 1, c, s);
00292 }
00293
00294 void Rot(Vector<double>& x, Vector<double>& y, const double c, const double s)
00295 {
00296 if(x.Length() != y.Length())
00297 {
00298 cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00299 Utility::RunTimeError("Vector lengths are not the same!");
00300 }
00301 cblas_drot(x.Length(), x.Data(), 1, y.Data(), 1, c, s);
00302 }
00303
00304 void Rot(Vector<ComplexFloat>& x, Vector<ComplexFloat>& y, const float c, const float s)
00305 {
00306 if(x.Length() != y.Length())
00307 {
00308 cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00309 Utility::RunTimeError("Vector lengths are not the same!");
00310 }
00311 cblas_csrot(x.Length(), x.Data(), 1, y.Data(), 1, c, s);
00312 }
00313
00314 void Rot(Vector<ComplexDouble>& x, Vector<ComplexDouble>& y, const double c, const double s)
00315 {
00316 if(x.Length() != y.Length())
00317 {
00318 cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00319 Utility::RunTimeError("Vector lengths are not the same!");
00320 }
00321 cblas_zdrot(x.Length(), x.Data(), 1, y.Data(), 1, c, s);
00322 }
00323
00324
00325
00326
00327
00328
00329
00330 void Rotg(float& a, float& b, float& c, float& s)
00331 {
00332 cblas_srotg(&a, &b, &c, &s);
00333 }
00334
00335 void Rotg(double& a, double& b, double& c, double& s)
00336 {
00337 cblas_drotg(&a, &b, &c, &s);
00338 }
00339
00340 void Rotg(ComplexFloat& a, ComplexFloat& b, float& c, ComplexFloat& s)
00341 {
00342 cblas_crotg(&a, &b, &c, &s);
00343 }
00344
00345 void Rotg(ComplexDouble& a, ComplexDouble& b, double& c, ComplexDouble& s)
00346 {
00347 cblas_zrotg(&a, &b, &c, &s);
00348 }
00349
00350
00351
00352
00353
00354
00355 void Rotm(Vector<float>& x, Vector<float>& y, float* param)
00356 {
00357 if(x.Length() != y.Length())
00358 {
00359 cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00360 Utility::RunTimeError("Vector lengths are not the same!");
00361 }
00362 cblas_srotm(x.Length(), x.Data(), 1, y.Data(), 1, param);
00363 }
00364
00365 void Rotm(Vector<double>& x, Vector<double>& y, double* param)
00366 {
00367 if(x.Length() != y.Length())
00368 {
00369 cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00370 Utility::RunTimeError("Vector lengths are not the same!");
00371 }
00372 cblas_drotm(x.Length(), x.Data(), 1, y.Data(), 1, param);
00373 }
00374
00375
00376
00377
00378
00379 void Rotmg(float& d1, float& d2, float& b1, float& b2, float* param)
00380 {
00381 cblas_srotmg(&d1, &d2, &b1, &b2, param);
00382 }
00383
00384 void Rotmg(double& d1, double& d2, double& b1, double& b2, double* param)
00385 {
00386 cblas_drotmg(&d1, &d2, &b1, &b2, param);
00387 }
00388
00389
00390
00391
00392
00393
00394 void Scal(float alpha, Vector<float>& x)
00395 {
00396 cblas_sscal(x.Length(), alpha, x.Data(), 1);
00397 }
00398
00399 void Scal(double alpha, Vector<double>& x)
00400 {
00401 cblas_dscal(x.Length(), alpha, x.Data(), 1);
00402 }
00403
00404 void Scal(float alpha, Vector<ComplexFloat>& x)
00405 {
00406 cblas_csscal(x.Length(), alpha, x.Data(), 1);
00407 }
00408
00409 void Scal(double alpha, Vector<ComplexDouble>& x)
00410 {
00411 cblas_zdscal(x.Length(), alpha, x.Data(), 1);
00412 }
00413
00414 void Scal(ComplexFloat alpha, Vector<ComplexFloat>& x)
00415 {
00416 cblas_cscal(x.Length(), &alpha, x.Data(), 1);
00417 }
00418
00419 void Scal(ComplexDouble alpha, Vector<ComplexDouble>& x)
00420 {
00421 cblas_zscal(x.Length(), &alpha, x.Data(), 1);
00422 }
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432 void Swap(Vector<float>& x, Vector<float>& y)
00433 {
00434 if(x.Length() != y.Length())
00435 {
00436 cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00437 Utility::RunTimeError("Vector lengths are not the same!");
00438 }
00439 cblas_sswap(x.Length(), x.Data(), 1, y.Data(), 1);
00440 }
00441
00442
00443 void Swap(Vector<double>& x, Vector<double>& y)
00444 {
00445 if(x.Length() != y.Length())
00446 {
00447 cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00448 Utility::RunTimeError("Vector lengths are not the same!");
00449 }
00450 cblas_dswap(x.Length(), x.Data(), 1, y.Data(), 1);
00451 }
00452
00453 void Swap(Vector<ComplexFloat>& x, Vector<ComplexFloat>& y)
00454 {
00455 if(x.Length() != y.Length())
00456 {
00457 cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00458 Utility::RunTimeError("Vector lengths are not the same!");
00459 }
00460 cblas_cswap(x.Length(), x.Data(), 1, y.Data(), 1);
00461 }
00462
00463 void Swap(Vector<ComplexDouble>& x, Vector<ComplexDouble>& y)
00464 {
00465 if(x.Length() != y.Length())
00466 {
00467 cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00468 Utility::RunTimeError("Vector lengths are not the same!");
00469 }
00470 cblas_zswap(x.Length(), x.Data(), 1, y.Data(), 1);
00471 }
00472
00473
00474
00475
00476
00477
00478
00479 int IAmax(Vector<float>& x)
00480 {
00481 return (int)cblas_isamax(x.Length(), x.DataPtr(), 1);
00482 }
00483
00484 int IAmax(Vector<double>& x)
00485 {
00486 return (int)cblas_idamax(x.Length(), x.DataPtr(), 1);
00487 }
00488
00489 int IAmax(Vector<ComplexFloat>& x)
00490 {
00491 return (int)cblas_icamax(x.Length(), x.DataPtr(), 1);
00492 }
00493
00494 int IAmax(Vector<ComplexDouble>& x)
00495 {
00496 return (int)cblas_izamax(x.Length(), x.DataPtr(), 1);
00497 }
00498
00499
00500
00501
00502
00503
00504 int IAmin(Vector<float>& x)
00505 {
00506 return (int)cblas_isamin(x.Length(), x.DataPtr(), 1);
00507 }
00508
00509 int IAmin(Vector<double>& x)
00510 {
00511 return (int)cblas_idamin(x.Length(), x.DataPtr(), 1);
00512 }
00513
00514 int IAmin(Vector<ComplexFloat>& x)
00515 {
00516 return (int)cblas_icamin(x.Length(), x.DataPtr(), 1);
00517 }
00518
00519 int IAmin(Vector<ComplexDouble>& x)
00520 {
00521 return (int)cblas_izamin(x.Length(), x.DataPtr(), 1);
00522 }
00523
00524 };
00525
00526
00527
00528