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
00068 Vector<float> Gemv(Matrix<float>& A, Vector<float>& x)
00069 {
00070 if(A.Columns() != x.Length())
00071 {
00072 cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00073 Utility::RunTimeError("Matrix columns and Vector length are not the same!");
00074 }
00075 Vector<float> y(A.Rows(), 0);
00076 cblas_sgemv(CblasColMajor, CblasNoTrans, A.Rows(), A.Columns(), 1, A.Data(), A.Rows(), x.Data(), 1, 1, y.Data(), 1);
00077 return y;
00078 }
00079
00080 Vector<double> Gemv(Matrix<double>& A, Vector<double>& x)
00081 {
00082 if(A.Columns() != x.Length())
00083 {
00084 cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00085 Utility::RunTimeError("Matrix columns and Vector length are not the same!");
00086 }
00087 Vector<double> y(A.Rows(), 0);
00088 cblas_dgemv(CblasColMajor, CblasNoTrans, A.Rows(), A.Columns(), 1, A.Data(), A.Rows(), x.Data(), 1, 1, y.Data(), 1);
00089 return y;
00090 }
00091
00092 Vector<ComplexFloat> Gemv(Matrix<ComplexFloat>& A, Vector<ComplexFloat>& x)
00093 {
00094 if(A.Columns() != x.Length())
00095 {
00096 cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00097 Utility::RunTimeError("Matrix columns and Vector length are not the same!");
00098 }
00099 ComplexFloat temp(1,0);
00100 Vector<ComplexFloat> y(A.Rows(), ComplexFloat(0,0));
00101 cblas_cgemv(CblasColMajor, CblasNoTrans, A.Rows(), A.Columns(), &temp, A.Data(), A.Rows(), x.Data(), 1, &temp, y.Data(), 1);
00102 return y;
00103 }
00104
00105 Vector<ComplexDouble> Gemv(Matrix<ComplexDouble>& A, Vector<ComplexDouble>& x)
00106 {
00107 if(A.Columns() != x.Length())
00108 {
00109 cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00110 Utility::RunTimeError("Matrix columns and Vector length are not the same!");
00111 }
00112 ComplexDouble temp(1,0);
00113 Vector<ComplexDouble> y(A.Rows(), ComplexDouble(0,0));
00114 cblas_zgemv(CblasColMajor, CblasNoTrans, A.Rows(), A.Columns(), &temp, A.Data(), A.Rows(), x.Data(), 1, &temp, y.Data(), 1);
00115 return y;
00116 }
00117
00118
00122 void Ger(float alpha, Vector<float>& x, Vector<float>& y, Matrix<float>& A)
00123 {
00124 if(x.Length() != A.Rows() || y.Length() != A.Columns())
00125 {
00126 cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00127 Utility::RunTimeError("Some of the Vector lengths does not match matrix dimensions!");
00128 }
00129 cblas_sger(CblasColMajor, A.Rows(), A.Columns(), alpha, x.Data(), 1, y.Data(), 1, A.Data(), A.Rows());
00130 }
00131
00132 void Ger(double alpha, Vector<double>& x, Vector<double>& y, Matrix<double>& A)
00133 {
00134 if(x.Length() != A.Rows() || y.Length() != A.Columns())
00135 {
00136 cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00137 Utility::RunTimeError("Some of the Vector lengths does not match matrix dimensions!");
00138 }
00139 cblas_dger(CblasColMajor, A.Rows(), A.Columns(), alpha, x.Data(), 1, y.Data(), 1, A.Data(), A.Rows());
00140 }
00141
00142 void Ger(ComplexFloat alpha, Vector<ComplexFloat>& x, Vector<ComplexFloat>& y, Matrix<ComplexFloat>& A)
00143 {
00144 if(x.Length() != A.Rows() || y.Length() != A.Columns())
00145 {
00146 cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00147 Utility::RunTimeError("Some of the Vector lengths does not match matrix dimensions!");
00148 }
00149
00150 cblas_cgeru(CblasColMajor, A.Rows(), A.Columns(), &alpha, x.Data(), 1, y.Data(), 1, A.Data(), A.Rows());
00151 }
00152
00153 void Ger(ComplexDouble alpha, Vector<ComplexDouble>& x, Vector<ComplexDouble>& y, Matrix<ComplexDouble>& A)
00154 {
00155 if(x.Length() != A.Rows() || y.Length() != A.Columns())
00156 {
00157 cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00158 Utility::RunTimeError("Some of the Vector lengths does not match matrix dimensions!");
00159 }
00160
00161 cblas_zgeru(CblasColMajor, A.Rows(), A.Columns(), &alpha, x.Data(), 1, y.Data(), 1, A.Data(), A.Rows());
00162 }
00163
00164 void Ger(ComplexFloat alpha, Vector<ComplexFloat> x, Vector<ComplexFloat> y, Matrix<ComplexFloat>& A, bool conjugated)
00165 {
00166 if(x.Length() != A.Rows() || y.Length() != A.Columns())
00167 {
00168 cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00169 Utility::RunTimeError("Some of the Vector lengths does not match matrix dimensions!");
00170 }
00171
00172 if(conjugated)
00173 {
00174 cblas_cgerc(CblasColMajor, A.Rows(), A.Columns(), &alpha, x.Data(), 1, y.Data(), 1, A.Data(), A.Rows());
00175 }
00176 else
00177 {
00178 cblas_cgeru(CblasColMajor, A.Rows(), A.Columns(), &alpha, x.Data(), 1, y.Data(), 1, A.Data(), A.Rows());
00179 }
00180 }
00181
00182 void Ger(ComplexDouble alpha, Vector<ComplexDouble>& x, Vector<ComplexDouble>& y, Matrix<ComplexDouble>& A, bool conjugated)
00183 {
00184 if(x.Length() != A.Rows() || y.Length() != A.Columns())
00185 {
00186 cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00187 Utility::RunTimeError("Some of the Vector lengths does not match matrix dimensions!");
00188 }
00189
00190 if(conjugated)
00191 {
00192 cblas_zgerc(CblasColMajor, A.Rows(), A.Columns(), &alpha, x.Data(), 1, y.Data(), 1, A.Data(), A.Rows());
00193 }
00194 else
00195 {
00196 cblas_zgeru(CblasColMajor, A.Rows(), A.Columns(), &alpha, x.Data(), 1, y.Data(), 1, A.Data(), A.Rows());
00197 }
00198 }
00199
00200
00201
00203 Vector<float> Symv(Matrix<float>& A, Vector<float> x)
00204 {
00205 if(A.Columns() != A.Rows())
00206 {
00207 cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00208 Utility::RunTimeError("Matrix is not square!");
00209 }
00210 if(A.Columns() != x.Length())
00211 {
00212 cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00213 Utility::RunTimeError("Matrix columns and Vector length are not the same!");
00214 }
00215 Vector<float> y(A.Rows(), 0);
00216 cblas_ssymv(CblasColMajor, CblasUpper, A.Rows(), 1, A.Data(), A.Rows(), x.Data(), 1, 1, y.Data(), 1);
00217 return y;
00218 }
00219
00220 Vector<double> Symv(Matrix<double>& A, Vector<double> x)
00221 {
00222 if(A.Columns() != A.Rows())
00223 {
00224 cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00225 Utility::RunTimeError("Matrix is not square!");
00226 }
00227 if(A.Columns() != x.Length())
00228 {
00229 cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00230 Utility::RunTimeError("Matrix columns and Vector length are not the same!");
00231 }
00232 Vector<double> y(A.Rows(), 0);
00233 cblas_dsymv(CblasColMajor, CblasUpper, A.Rows(), 1, A.Data(), A.Rows(), x.Data(), 1, 1, y.Data(), 1);
00234 return y;
00235 }
00236
00237 Vector<ComplexFloat> Hemv(Matrix<ComplexFloat>& A, Vector<ComplexFloat>& x)
00238 {
00239 if(A.Columns() != A.Rows())
00240 {
00241 cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00242 Utility::RunTimeError("Matrix is not square!");
00243 }
00244 if(A.Columns() != x.Length())
00245 {
00246 cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00247 Utility::RunTimeError("Matrix columns and Vector length are not the same!");
00248 }
00249 ComplexFloat temp(1,0);
00250 Vector<ComplexFloat> y(A.Rows(), ComplexFloat(0,0));
00251 cblas_chemv(CblasColMajor, CblasUpper, A.Rows(), &temp, A.Data(), A.Rows(), x.Data(), 1, &temp, y.Data(), 1);
00252 return y;
00253 }
00254
00255 Vector<ComplexDouble> Hemv(Matrix<ComplexDouble>& A, Vector<ComplexDouble>& x)
00256 {
00257 if(A.Columns() != A.Rows())
00258 {
00259 cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00260 Utility::RunTimeError("Matrix is not square!");
00261 }
00262 if(A.Columns() != x.Length())
00263 {
00264 cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00265 Utility::RunTimeError("Matrix columns and Vector length are not the same!");
00266 }
00267 ComplexDouble temp(1,0);
00268 Vector<ComplexDouble> y(A.Rows(), ComplexDouble(0,0));
00269 cblas_zhemv(CblasColMajor, CblasUpper, A.Rows(), &temp, A.Data(), A.Rows(), x.Data(), 1, &temp, y.Data(), 1);
00270 return y;
00271 }
00272
00273
00274
00275
00276
00280 void Syr(float alpha, Vector<float>& x, Matrix<float>& A)
00281 {
00282 if(A.Columns() != A.Rows())
00283 {
00284 cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00285 Utility::RunTimeError("Matrix is not square!");
00286 }
00287 if(x.Length() != A.Rows())
00288 {
00289 cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00290 Utility::RunTimeError("Some of the Vector lengths does not match matrix dimensions!");
00291 }
00292 cblas_ssyr(CblasColMajor, CblasUpper, A.Rows(), alpha, x.Data(), 1, A.Data(), A.Rows());
00293 }
00294
00295
00296 void Syr(double alpha, Vector<double>& x, Matrix<double>& A)
00297 {
00298 if(A.Columns() != A.Rows())
00299 {
00300 cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00301 Utility::RunTimeError("Matrix is not square!");
00302 }
00303 if(x.Length() != A.Rows())
00304 {
00305 cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00306 Utility::RunTimeError("Some of the Vector lengths does not match matrix dimensions!");
00307 }
00308 cblas_dsyr(CblasColMajor, CblasUpper, A.Rows(), alpha, x.Data(), 1, A.Data(), A.Rows());
00309 }
00310
00311 void Her(float alpha, Vector<ComplexFloat>& x, Matrix<ComplexFloat>& A)
00312 {
00313 if(A.Columns() != A.Rows())
00314 {
00315 cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00316 Utility::RunTimeError("Matrix is not square!");
00317 }
00318 if(x.Length() != A.Rows())
00319 {
00320 cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00321 Utility::RunTimeError("Some of the Vector lengths does not match matrix dimensions!");
00322 }
00323 cblas_cher(CblasColMajor, CblasUpper, A.Rows(), alpha, x.Data(), 1, A.Data(), A.Rows());
00324 }
00325
00326 void Her(double alpha, Vector<ComplexDouble>& x, Matrix<ComplexDouble>& A)
00327 {
00328 if(A.Columns() != A.Rows())
00329 {
00330 cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00331 Utility::RunTimeError("Matrix is not square!");
00332 }
00333 if(x.Length() != A.Rows())
00334 {
00335 cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00336 Utility::RunTimeError("Some of the Vector lengths does not match matrix dimensions!");
00337 }
00338 cblas_zher(CblasColMajor, CblasUpper, A.Rows(), alpha, x.Data(), 1, A.Data(), A.Rows());
00339 }
00340
00341
00342
00343
00347 void Syr2(float alpha, Vector<float>& x, Vector<float>& y, Matrix<float>& A)
00348 {
00349 if(A.Columns() != A.Rows())
00350 {
00351 cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00352 Utility::RunTimeError("Matrix is not square!");
00353 }
00354 if(x.Length() != A.Rows() || y.Length() != A.Columns())
00355 {
00356 cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00357 Utility::RunTimeError("Some of the Vector lengths does not match matrix dimensions!");
00358 }
00359
00360 cblas_ssyr2(CblasColMajor, CblasUpper, A.Rows(), alpha, x.Data(), 1, y.Data(), 1, A.Data(), A.Rows());
00361 }
00362
00363 void Syr2(double alpha, Vector<double>& x, Vector<double>& y, Matrix<double>& A)
00364 {
00365 if(A.Columns() != A.Rows())
00366 {
00367 cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00368 Utility::RunTimeError("Matrix is not square!");
00369 }
00370 if(x.Length() != A.Rows() || y.Length() != A.Columns())
00371 {
00372 cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00373 Utility::RunTimeError("Some of the Vector lengths does not match matrix dimensions!");
00374 }
00375
00376 cblas_dsyr2(CblasColMajor, CblasUpper, A.Rows(), alpha, x.Data(), 1, y.Data(), 1, A.Data(), A.Rows());
00377 }
00378
00379 void Her2(ComplexFloat alpha, Vector<ComplexFloat>& x, Vector<ComplexFloat>& y, Matrix<ComplexFloat>& A)
00380 {
00381 if(A.Columns() != A.Rows())
00382 {
00383 cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00384 Utility::RunTimeError("Matrix is not square!");
00385 }
00386 if(x.Length() != A.Rows() || y.Length() != A.Columns())
00387 {
00388 cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00389 Utility::RunTimeError("Some of the Vector lengths does not match matrix dimensions!");
00390 }
00391
00392 cblas_cher2(CblasColMajor, CblasUpper, A.Rows(), &alpha, x.Data(), 1, y.Data(), 1, A.Data(), A.Rows());
00393 }
00394
00395 void Her2(ComplexDouble alpha, Vector<ComplexDouble>& x, Vector<ComplexDouble>& y, Matrix<ComplexDouble>& A)
00396 {
00397 if(A.Columns() != A.Rows())
00398 {
00399 cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00400 Utility::RunTimeError("Matrix is not square!");
00401 }
00402 if(x.Length() != A.Rows() || y.Length() != A.Columns())
00403 {
00404 cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00405 Utility::RunTimeError("Some of the Vector lengths does not match matrix dimensions!");
00406 }
00407
00408 cblas_zher2(CblasColMajor, CblasUpper, A.Rows(), &alpha, x.Data(), 1, y.Data(), 1, A.Data(), A.Rows());
00409 }
00410
00411
00412
00413
00415 Vector<float> Trmv(Matrix<float>& A, Vector<float>& x)
00416 {
00417 if(A.Columns() != A.Rows())
00418 {
00419 cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00420 Utility::RunTimeError("Matrix is not square!");
00421 }
00422 if(A.Columns() != x.Length())
00423 {
00424 cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00425 Utility::RunTimeError("Matrix columns and Vector length are not the same!");
00426 }
00427 Vector<float> y = x.Clone();
00428 cblas_strmv(CblasColMajor, CblasUpper, CblasNoTrans, CblasNonUnit, A.Rows(), A.Data(), A.Rows(), y.Data(), 1);
00429 return y;
00430 }
00431
00432 Vector<double> Trmv(Matrix<double>& A, Vector<double>& x)
00433 {
00434 if(A.Columns() != A.Rows())
00435 {
00436 cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00437 Utility::RunTimeError("Matrix is not square!");
00438 }
00439 if(A.Columns() != x.Length())
00440 {
00441 cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00442 Utility::RunTimeError("Matrix columns and Vector length are not the same!");
00443 }
00444 Vector<double> y = x.Clone();
00445 cblas_dtrmv(CblasColMajor, CblasUpper, CblasNoTrans, CblasNonUnit, A.Rows(), A.Data(), A.Rows(), y.Data(), 1);
00446 return y;
00447 }
00448
00449 Vector<ComplexFloat> Trmv(Matrix<ComplexFloat>& A, Vector<ComplexFloat>& x)
00450 {
00451 if(A.Columns() != A.Rows())
00452 {
00453 cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00454 Utility::RunTimeError("Matrix is not square!");
00455 }
00456 if(A.Columns() != x.Length())
00457 {
00458 cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00459 Utility::RunTimeError("Matrix columns and Vector length are not the same!");
00460 }
00461 Vector<ComplexFloat> y = x.Clone();
00462 cblas_ctrmv(CblasColMajor, CblasUpper, CblasNoTrans, CblasNonUnit, A.Rows(), A.Data(), A.Rows(), y.Data(), 1);
00463 return y;
00464 }
00465
00466 Vector<ComplexDouble> Trmv(Matrix<ComplexDouble>& A, Vector<ComplexDouble>& x)
00467 {
00468 if(A.Columns() != A.Rows())
00469 {
00470 cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00471 Utility::RunTimeError("Matrix is not square!");
00472 }
00473 if(A.Columns() != x.Length())
00474 {
00475 cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00476 Utility::RunTimeError("Matrix columns and Vector length are not the same!");
00477 }
00478 Vector<ComplexDouble> y = x.Clone();
00479 cblas_ztrmv(CblasColMajor, CblasUpper, CblasNoTrans, CblasNonUnit, A.Rows(), A.Data(), A.Rows(), y.Data(), 1);
00480 return y;
00481 }
00482
00483
00485 Vector<float> Trsv(Matrix<float>& A, Vector<float>& b)
00486 {
00487 if(A.Columns() != A.Rows())
00488 {
00489 cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00490 Utility::RunTimeError("Matrix is not square!");
00491 }
00492 if(A.Rows() != b.Length())
00493 {
00494 cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00495 Utility::RunTimeError("Matrix columns and Vector length are not the same!");
00496 }
00497 Vector<float> x = b.Clone();
00498 cblas_strsv(CblasColMajor, CblasUpper, CblasNoTrans, CblasNonUnit, A.Rows(), A.Data(), A.Rows(), x.Data(), 1);
00499 return x;
00500 }
00501
00502 Vector<double> Trsv(Matrix<double>& A, Vector<double>& b)
00503 {
00504 if(A.Columns() != A.Rows())
00505 {
00506 cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00507 Utility::RunTimeError("Matrix is not square!");
00508 }
00509 if(A.Rows() != b.Length())
00510 {
00511 cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00512 Utility::RunTimeError("Matrix columns and Vector length are not the same!");
00513 }
00514 Vector<double> x = b.Clone();
00515 cblas_dtrsv(CblasColMajor, CblasUpper, CblasNoTrans, CblasNonUnit, A.Rows(), A.Data(), A.Rows(), x.Data(), 1);
00516 return x;
00517 }
00518
00519 Vector<ComplexFloat> Trsv(Matrix<ComplexFloat>& A, Vector<ComplexFloat>& b)
00520 {
00521 if(A.Columns() != A.Rows())
00522 {
00523 cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00524 Utility::RunTimeError("Matrix is not square!");
00525 }
00526 if(A.Rows() != b.Length())
00527 {
00528 cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00529 Utility::RunTimeError("Matrix columns and Vector length are not the same!");
00530 }
00531 Vector<ComplexFloat> x = b.Clone();
00532 cblas_ctrsv(CblasColMajor, CblasUpper, CblasNoTrans, CblasNonUnit, A.Rows(), A.Data(), A.Rows(), x.Data(), 1);
00533 return x;
00534 }
00535
00536 Vector<ComplexDouble> Trsv(Matrix<ComplexDouble>& A, Vector<ComplexDouble>& b)
00537 {
00538 if(A.Columns() != A.Rows())
00539 {
00540 cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00541 Utility::RunTimeError("Matrix is not square!");
00542 }
00543 if(A.Rows() != b.Length())
00544 {
00545 cerr << "Line: " << __LINE__ << " File: " << __FILE__ << endl;
00546 Utility::RunTimeError("Matrix columns and Vector length are not the same!");
00547 }
00548 Vector<ComplexDouble> x = b.Clone();
00549 cblas_ztrsv(CblasColMajor, CblasUpper, CblasNoTrans, CblasNonUnit, A.Rows(), A.Data(), A.Rows(), x.Data(), 1);
00550 return x;
00551 }
00552
00553
00554 };
00555
00556
00557
00558
00559
00560
00561
00562
00563
00564
00565
00566
00567
00568