20 #ifndef SELDON_FILE_BLAS_1_CXX
29 #ifndef SELDON_WITH_COMPILED_LIBRARY
34 void GenRot(
float& a,
float& b,
float& c,
float& d)
36 cblas_srotg(&a, &b, &c, &d);
40 void GenRot(
double& a,
double& b,
double& c,
double& d)
42 cblas_drotg(&a, &b, &c, &d);
55 void GenModifRot(
float& d1,
float& d2,
56 float& x1,
const float& y1,
59 cblas_srotmg(&d1, &d2, &x1, y1, param);
63 void GenModifRot(
double& d1,
double& d2,
64 double& x1,
const double& y1,
67 cblas_drotmg(&d1, &d2, &x1, y1, param);
81 template <
class Allocator>
82 void ApplyRot(Vector<float, VectFull, Allocator>& X,
83 Vector<float, VectFull, Allocator>& Y,
84 const float& c,
const float& s)
86 cblas_srot(X.GetLength(), X.GetData(), 1,
87 Y.GetData(), 1, c, s);
91 template <
class Allocator>
92 void ApplyRot(Vector<double, VectFull, Allocator>& X,
93 Vector<double, VectFull, Allocator>& Y,
94 const double& c,
const double& s)
96 cblas_drot(X.GetLength(), X.GetData(), 1,
97 Y.GetData(), 1, c, s);
110 template <
class Allocator>
111 void ApplyModifRot(Vector<float, VectFull, Allocator>& X,
112 Vector<float, VectFull, Allocator>& Y,
115 cblas_srotm(X.GetLength(), X.GetData(), 1,
116 Y.GetData(), 1, param);
120 template <
class Allocator>
121 void ApplyModifRot(Vector<double, VectFull, Allocator>& X,
122 Vector<double, VectFull, Allocator>& Y,
125 cblas_drotm(X.GetLength(), X.GetData(), 1,
126 Y.GetData(), 1, param);
139 template <
class Allocator>
140 void Swap(Vector<float, VectFull, Allocator>& X,
141 Vector<float, VectFull, Allocator>& Y)
144 #ifdef SELDON_CHECK_DIMENSIONS
145 CheckDim(X, Y,
"Swap(X, Y)",
"X <-> Y");
148 cblas_sswap(X.GetLength(), X.GetData(), 1,
153 template <
class Allocator>
154 void Swap(Vector<double, VectFull, Allocator>& X,
155 Vector<double, VectFull, Allocator>& Y)
158 #ifdef SELDON_CHECK_DIMENSIONS
159 CheckDim(X, Y,
"Swap(X, Y)",
"X <-> Y");
162 cblas_dswap(X.GetLength(), X.GetData(), 1,
167 template <
class Allocator>
168 void Swap(Vector<complex<float>, VectFull, Allocator>& X,
169 Vector<complex<float>, VectFull, Allocator>& Y)
172 #ifdef SELDON_CHECK_DIMENSIONS
173 CheckDim(X, Y,
"Swap(X, Y)",
"X <-> Y");
176 cblas_cswap(X.GetLength(),
reinterpret_cast<void*
>(X.GetData()), 1,
177 reinterpret_cast<void*
>(Y.GetData()), 1);
181 template <
class Allocator>
182 void Swap(Vector<complex<double>, VectFull, Allocator>& X,
183 Vector<complex<double>, VectFull, Allocator>& Y)
186 #ifdef SELDON_CHECK_DIMENSIONS
187 CheckDim(X, Y,
"Swap(X, Y)",
"X <-> Y");
190 cblas_zswap(X.GetLength(),
reinterpret_cast<void*
>(X.GetData()), 1,
191 reinterpret_cast<void*
>(Y.GetData()), 1);
204 template <
class Allocator>
206 Vector<float, VectFull, Allocator>& X)
208 cblas_sscal(X.GetLength(), alpha, X.GetData(), 1);
212 template <
class Allocator>
214 Vector<double, VectFull, Allocator>& X)
216 cblas_dscal(X.GetLength(), alpha, X.GetData(), 1);
220 template <
class Allocator>
222 Vector<complex<float>, VectFull, Allocator>& X)
224 cblas_csscal(X.GetLength(), alpha,
225 reinterpret_cast<void*
>(X.GetData()), 1);
229 template <
class Allocator>
231 Vector<complex<double>, VectFull, Allocator>& X)
233 cblas_zdscal(X.GetLength(), alpha,
234 reinterpret_cast<void*
>(X.GetData()), 1);
238 template <
class Allocator>
239 void MltScalar(
const complex<float>& alpha,
240 Vector<complex<float>, VectFull, Allocator>& X)
242 cblas_cscal(X.GetLength(),
243 reinterpret_cast<const void*
>(&alpha),
244 reinterpret_cast<void*
>(X.GetData()), 1);
248 template <
class Allocator>
249 void MltScalar(
const complex<double>& alpha,
250 Vector<complex<double>, VectFull, Allocator>& X)
252 cblas_zscal(X.GetLength(),
253 reinterpret_cast<const void*
>(&alpha),
254 reinterpret_cast<void*
>(X.GetData()), 1);
267 template <
class Allocator0,
class Allocator1>
268 void CopyVector(
const Vector<float, VectFull, Allocator0>& X,
269 Vector<float, VectFull, Allocator1>& Y)
272 #ifdef SELDON_CHECK_DIMENSIONS
273 CheckDim(X, Y,
"Copy(X, Y)",
"X -> Y");
276 cblas_scopy(Y.GetLength(),
277 reinterpret_cast<const float*
>(X.GetData()), 1,
278 reinterpret_cast<float*
>(Y.GetData()), 1);
282 template <
class Allocator0,
class Allocator1>
283 void CopyVector(
const Vector<double, VectFull, Allocator0>& X,
284 Vector<double, VectFull, Allocator1>& Y)
287 #ifdef SELDON_CHECK_DIMENSIONS
288 CheckDim(X, Y,
"Copy(X, Y)",
"X -> Y");
291 cblas_dcopy(Y.GetLength(),
292 reinterpret_cast<const double*
>(X.GetData()), 1,
293 reinterpret_cast<double*
>(Y.GetData()), 1);
297 template <
class Allocator0,
class Allocator1>
298 void CopyVector(
const Vector<complex<float>, VectFull, Allocator0>& X,
299 Vector<complex<float>, VectFull, Allocator1>& Y)
302 #ifdef SELDON_CHECK_DIMENSIONS
303 CheckDim(X, Y,
"Copy(X, Y)",
"X -> Y");
306 cblas_ccopy(Y.GetLength(),
307 reinterpret_cast<const void*
>(X.GetData()), 1,
308 reinterpret_cast<void*
>(Y.GetData()), 1);
312 template <
class Allocator0,
class Allocator1>
313 void CopyVector(
const Vector<complex<double>, VectFull, Allocator0>& X,
314 Vector<complex<double>, VectFull, Allocator1>& Y)
317 #ifdef SELDON_CHECK_DIMENSIONS
318 CheckDim(X, Y,
"Copy(X, Y)",
"X -> Y");
321 cblas_zcopy(Y.GetLength(),
322 reinterpret_cast<const void*
>(X.GetData()), 1,
323 reinterpret_cast<void*
>(Y.GetData()), 1);
336 template <
class Allocator0,
class Allocator1>
338 const Vector<float, VectFull, Allocator0>& X,
339 Vector<float, VectFull, Allocator1>& Y)
342 #ifdef SELDON_CHECK_DIMENSIONS
346 cblas_saxpy(Y.GetLength(),
348 reinterpret_cast<const float*
>(X.GetData()), 1,
349 reinterpret_cast<float*
>(Y.GetData()), 1);
353 template <
class Allocator0,
class Allocator1>
355 const Vector<double, VectFull, Allocator0>& X,
356 Vector<double, VectFull, Allocator1>& Y)
359 #ifdef SELDON_CHECK_DIMENSIONS
363 cblas_daxpy(Y.GetLength(),
365 reinterpret_cast<const double*
>(X.GetData()), 1,
366 reinterpret_cast<double*
>(Y.GetData()), 1);
370 template <
class Allocator0,
class Allocator1>
371 void AddVector(
const complex<float>& alpha,
372 const Vector<complex<float>, VectFull, Allocator0>& X,
373 Vector<complex<float>, VectFull, Allocator1>& Y)
376 #ifdef SELDON_CHECK_DIMENSIONS
380 cblas_caxpy(Y.GetLength(),
381 reinterpret_cast<const void*
>(&alpha),
382 reinterpret_cast<const void*
>(X.GetData()), 1,
383 reinterpret_cast<float*
>(Y.GetData()), 1);
387 template <
class Allocator0,
class Allocator1>
388 void AddVector(
const complex<double>& alpha,
389 const Vector<complex<double>, VectFull, Allocator0>& X,
390 Vector<complex<double>, VectFull, Allocator1>& Y)
393 #ifdef SELDON_CHECK_DIMENSIONS
397 cblas_zaxpy(Y.GetLength(),
398 reinterpret_cast<const void*
>(&alpha),
399 reinterpret_cast<const void*
>(X.GetData()), 1,
400 reinterpret_cast<double*
>(Y.GetData()), 1);
413 template <
class Allocator0,
class Allocator1>
414 float DotProdVector(
const Vector<float, VectFull, Allocator0>& X,
415 const Vector<float, VectFull, Allocator1>& Y)
418 #ifdef SELDON_CHECK_DIMENSIONS
419 CheckDim(X, Y,
"DotProd(X, Y)",
"dot(X, Y)");
422 return cblas_sdot(Y.GetLength(),
423 reinterpret_cast<const float*
>(X.GetData()), 1,
424 reinterpret_cast<const float*
>(Y.GetData()), 1);
428 template <
class Allocator0,
class Allocator1>
429 double DotProdVector(
const Vector<double, VectFull, Allocator0>& X,
430 const Vector<double, VectFull, Allocator1>& Y)
433 #ifdef SELDON_CHECK_DIMENSIONS
434 CheckDim(X, Y,
"DotProd(X, Y)",
"dot(X, Y)");
437 return cblas_ddot(Y.GetLength(),
438 reinterpret_cast<const double*
>(X.GetData()), 1,
439 reinterpret_cast<const double*
>(Y.GetData()), 1);
443 template <
class Allocator0,
class Allocator1>
445 DotProdVector(
const Vector<complex<float>, VectFull, Allocator0>& X,
446 const Vector<complex<float>, VectFull, Allocator1>& Y)
449 #ifdef SELDON_CHECK_DIMENSIONS
450 CheckDim(X, Y,
"DotProd(X, Y)",
"dot(X, Y)");
454 #ifdef SELDON_WITHOUT_CBLAS_LIB
456 cblas_cdotu_sub(Y.GetLength(),
457 reinterpret_cast<const void*
>(X.GetData()), 1,
458 reinterpret_cast<const void*
>(Y.GetData()), 1,
459 reinterpret_cast<void*
>(&dotu));
462 int n = Y.GetLength(), inc = 1;
464 reinterpret_cast<const void*
>(X.GetData()), &inc,
465 reinterpret_cast<const void*
>(Y.GetData()), &inc,
466 reinterpret_cast<void*
>(&dotu));
473 template <
class Allocator0,
class Allocator1>
475 DotProdVector(
const Vector<complex<double>, VectFull, Allocator0>& X,
476 const Vector<complex<double>, VectFull, Allocator1>& Y)
479 #ifdef SELDON_CHECK_DIMENSIONS
480 CheckDim(X, Y,
"DotProd(X, Y)",
"dot(X, Y)");
484 #ifdef SELDON_WITHOUT_CBLAS_LIB
485 complex<double> dotu;
486 cblas_zdotu_sub(Y.GetLength(),
487 reinterpret_cast<const void*
>(X.GetData()), 1,
488 reinterpret_cast<const void*
>(Y.GetData()), 1,
489 reinterpret_cast<void*
>(&dotu));
491 complex<double> dotu;
492 int n = Y.GetLength(), inc = 1;
494 reinterpret_cast<const void*
>(X.GetData()), &inc,
495 reinterpret_cast<const void*
>(Y.GetData()), &inc,
496 reinterpret_cast<void*
>(&dotu));
512 template <
class Allocator0,
class Allocator1>
513 float ScaledDotProd(
const float& alpha,
514 const Vector<float, VectFull, Allocator0>& X,
515 const Vector<float, VectFull, Allocator1>& Y)
518 #ifdef SELDON_CHECK_DIMENSIONS
519 CheckDim(X, Y,
"ScaledDotProd(X, Y)",
"dot(X, Y)");
522 return cblas_sdsdot(Y.GetLength(), alpha,
523 reinterpret_cast<const float*
>(X.GetData()), 1,
524 reinterpret_cast<const float*
>(Y.GetData()), 1);
537 template <
class Allocator0,
class Allocator1>
540 const Vector<complex<float>, VectFull, Allocator1>& Y)
543 #ifdef SELDON_CHECK_DIMENSIONS
544 CheckDim(X, Y,
"DotProdConj(X, Y)",
"dot(X, Y)");
548 #ifdef SELDON_WITHOUT_CBLAS_LIB
550 cblas_cdotc_sub(Y.GetLength(),
551 reinterpret_cast<const void*
>(X.GetData()), 1,
552 reinterpret_cast<const void*
>(Y.GetData()), 1,
553 reinterpret_cast<void*
>(&dotc));
556 int n = Y.GetLength(), inc = 1;
558 reinterpret_cast<const void*
>(X.GetData()), &inc,
559 reinterpret_cast<const void*
>(Y.GetData()), &inc,
560 reinterpret_cast<void*
>(&dotc));
567 template <
class Allocator0,
class Allocator1>
570 const Vector<complex<double>, VectFull, Allocator1>& Y)
573 #ifdef SELDON_CHECK_DIMENSIONS
574 CheckDim(X, Y,
"DotProdConj(X, Y)",
"dot(X, Y)");
578 #ifdef SELDON_WITHOUT_CBLAS_LIB
579 complex<double> dotc;
580 cblas_zdotc_sub(Y.GetLength(),
581 reinterpret_cast<const void*
>(X.GetData()), 1,
582 reinterpret_cast<const void*
>(Y.GetData()), 1,
583 reinterpret_cast<void*
>(&dotc));
585 complex<double> dotc;
586 int n = Y.GetLength(), inc = 1;
588 reinterpret_cast<const void*
>(X.GetData()), &inc,
589 reinterpret_cast<const void*
>(Y.GetData()), &inc,
590 reinterpret_cast<void*
>(&dotc));
606 template <
class Allocator>
607 float Norm1(
const Vector<float, VectFull, Allocator>& X)
609 return cblas_sasum(X.GetLength(),
610 reinterpret_cast<const float*
>(X.GetData()), 1);
614 template <
class Allocator>
615 double Norm1(
const Vector<double, VectFull, Allocator>& X)
617 return cblas_dasum(X.GetLength(),
618 reinterpret_cast<const double*
>(X.GetData()), 1);
622 template <
class Allocator>
623 float Norm1(
const Vector<complex<float>, VectFull, Allocator>& X)
625 #ifdef SELDON_WITH_LAPACK
627 int n = X.GetLength(), incx = 1;
629 reinterpret_cast<const void*
>(X.GetData()), &incx);
631 return cblas_scasum(X.GetLength(),
632 reinterpret_cast<const void*
>(X.GetData()), 1);
637 template <
class Allocator>
638 double Norm1(
const Vector<complex<double>, VectFull, Allocator>& X)
640 #ifdef SELDON_WITH_LAPACK
642 int n = X.GetLength(), incx = 1;
644 reinterpret_cast<const void*
>(X.GetData()), &incx);
646 return cblas_dzasum(X.GetLength(),
647 reinterpret_cast<const void*
>(X.GetData()), 1);
661 template <
class Allocator>
662 float Norm2(
const Vector<float, VectFull, Allocator>& X)
664 return cblas_snrm2(X.GetLength(),
665 reinterpret_cast<const float*
>(X.GetData()), 1);
669 template <
class Allocator>
670 double Norm2(
const Vector<double, VectFull, Allocator>& X)
672 return cblas_dnrm2(X.GetLength(),
673 reinterpret_cast<const double*
>(X.GetData()), 1);
677 template <
class Allocator>
678 float Norm2(
const Vector<complex<float>, VectFull, Allocator>& X)
680 return cblas_scnrm2(X.GetLength(),
681 reinterpret_cast<const void*
>(X.GetData()), 1);
685 template <
class Allocator>
686 double Norm2(
const Vector<complex<double>, VectFull, Allocator>& X)
688 return cblas_dznrm2(X.GetLength(),
689 reinterpret_cast<const void*
>(X.GetData()), 1);
702 template <
class Allocator>
703 size_t GetMaxAbsIndex(
const Vector<float, VectFull, Allocator>& X)
705 return cblas_isamax(X.GetLength(),
706 reinterpret_cast<const float*
>(X.GetData()), 1);
710 template <
class Allocator>
711 size_t GetMaxAbsIndex(
const Vector<double, VectFull, Allocator>& X)
713 return cblas_idamax(X.GetLength(),
714 reinterpret_cast<const double*
>(X.GetData()), 1);
718 template <
class Allocator>
719 size_t GetMaxAbsIndex(
const Vector<complex<float>, VectFull, Allocator>& X)
721 #ifdef SELDON_WITH_LAPACK
722 int n = X.GetLength(), incx = 1;
723 size_t p = icmax1_(&n,
724 reinterpret_cast<void*
>(X.GetData()), &incx);
728 return cblas_icamax(X.GetLength(),
729 reinterpret_cast<const void*
>(X.GetData()), 1);
734 template <
class Allocator>
736 GetMaxAbsIndex(
const Vector<complex<double>, VectFull, Allocator>& X)
738 #ifdef SELDON_WITH_LAPACK
739 int n = X.GetLength(), incx = 1;
740 size_t p = izmax1_(&n,
741 reinterpret_cast<void*
>(X.GetData()), &incx);
744 return cblas_izamax(X.GetLength(),
745 reinterpret_cast<const void*
>(X.GetData()), 1);
756 #define SELDON_FILE_BLAS_1_CXX