JWS C Library
C language utility library
blas_old.c
Go to the documentation of this file.
00001 /*
00002  * This work is licensed under a Creative Commons 
00003  * Attribution-Noncommercial-Share Alike 3.0 United States License.
00004  * 
00005  *    http://creativecommons.org/licenses/by-nc-sa/3.0/us/
00006  * 
00007  * You are free:
00008  * 
00009  *    to Share - to copy, distribute, display, and perform the work
00010  *    to Remix - to make derivative works
00011  * 
00012  * Under the following conditions:
00013  * 
00014  *    Attribution. You must attribute the work in the manner specified by the
00015  *    author or licensor (but not in any way that suggests that they endorse you
00016  *    or your use of the work).
00017  * 
00018  *    Noncommercial. You may not use this work for commercial purposes.
00019  * 
00020  *    Share Alike. If you alter, transform, or build upon this work, you may
00021  *    distribute the resulting work only under the same or similar license to
00022  *    this one.
00023  * 
00024  * For any reuse or distribution, you must make clear to others the license
00025  * terms of this work. The best way to do this is by including this header.
00026  * 
00027  * Any of the above conditions can be waived if you get permission from the
00028  * copyright holder.
00029  * 
00030  * Apart from the remix rights granted under this license, nothing in this
00031  * license impairs or restricts the author's moral rights.
00032  */
00033 
00034 
00053 #include <jwsc/config.h>
00054 
00055 #include <stdlib.h>
00056 #include <assert.h>
00057 
00058 #include "jwsc/math/complex.h"
00059 #include "jwsc/math/blas.h"
00060 
00061 
00062 /* ===============  LEVEL 1 EXTERNS ==============*/
00063 
00064 extern int sswap_(int*, float*, int*, float*, int*);
00065 extern int dswap_(int*, double*, int*, double*, int*);
00066 extern int cswap_(int*, Complex_f*, int*, Complex_f*, int*);
00067 extern int zswap_(int*, Complex_d*, int*, Complex_d*, int*);
00068 extern int sscal_(int*, float*, float*, int*);
00069 extern int dscal_(int*, double*, double*, int*);
00070 extern int cscal_(int*, Complex_f*, Complex_f*, int*);
00071 extern int zscal_(int*, Complex_d*, Complex_d*, int*);
00072 extern int scopy_(int*, float*, int*, float*, int*);
00073 extern int dcopy_(int*, double*, int*, double*, int*);
00074 extern int ccopy_(int*, Complex_f*, int*, Complex_f*, int*);
00075 extern int zcopy_(int*, Complex_d*, int*, Complex_d*, int*);
00076 extern int saxpy_(int*, float*, float*, int*, float*, int*);
00077 extern int daxpy_(int*, double*, double*, int*, double*, int*);
00078 extern int caxpy_(int*, Complex_f*, Complex_f*, int*, Complex_f*, int*);
00079 extern int zaxpy_(int*, Complex_d*, Complex_d*, int*, Complex_d*, int*);
00080 extern float sdot_(int*, float*, int*, float*, int*);
00081 extern double ddot_(int*, double*, int*, double*, int*);
00082 extern float snrm2(int*, float*, int*);
00083 extern double dnrm2_(int*, double*, int*);
00084 extern float sasum_(int*, float*, int*);
00085 extern double dasum_(int*, double*, int*);
00086 extern int isamax_(int*, float*, int*);
00087 extern int idamax_(int*, double*, int*);
00088 extern int icamax_(int*, Complex_f*, int*);
00089 extern int izamax_(int*, Complex_d*, int*);
00090 
00091 
00092 /* ===============  LEVEL 2 EXTERNS ==============*/
00093 
00094 extern int sgemv_(char*, int*, int*, float*, float*, int*,
00095                   float*, int*, float*, float*, int*);
00096 extern int dgemv_(char*, int*, int*, double*, double*, int*,
00097                   double*, int*, double*, double*, int*);
00098 extern int cgemv_(char*, int*, int*, Complex_f*, Complex_f*, int*,
00099                   Complex_f*, int*, Complex_f*, Complex_f*, int*);
00100 extern int zgemv_(char*, int*, int*, Complex_d*, Complex_d*, int*,
00101                   Complex_d*, int*, Complex_d*, Complex_d*, int*);
00102 
00103 
00104 /* ===============  LEVEL 3 EXTERNS ==============*/
00105 
00106 extern int sgemm_(char*, char*, int*, int*, int*, float*, float*, int*,
00107                   float*, int*, float*, float*, int*);
00108 extern int dgemm_(char*, char*, int*, int*, int*, double*, double*, int*,
00109                   double*, int*, double*, double*, int*);
00110 extern int cgemm_(char*, char*, int*, int*, int*, Complex_f*, Complex_f*, int*,
00111                   Complex_f*, int*, Complex_f*, Complex_f*, int*);
00112 extern int zgemm_(char*, char*, int*, int*, int*, Complex_d*, Complex_d*, int*,
00113                   Complex_d*, int*, Complex_d*, Complex_d*, int*);
00114 
00115 
00116 
00117 
00118 /* ===============  LEVEL 1 ==============*/
00119 
00120 
00128 void blas_sswap(int n, float* x, int inc_x, float* y, int inc_y)
00129 {
00130     sswap_(&n, x, &inc_x, y, &inc_y);
00131 }
00132 
00133 void blas_dswap(int n, double* x, int inc_x, double* y, int inc_y)
00134 {
00135     dswap_(&n, x, &inc_x, y, &inc_y);
00136 }
00137 
00138 void blas_cswap(int n, Complex_f* x, int inc_x, Complex_f* y, int inc_y)
00139 {
00140     cswap_(&n, x, &inc_x, y, &inc_y);
00141 }
00142 
00143 void blas_zswap(int n, Complex_d* x, int inc_x, Complex_d* y, int inc_y)
00144 {
00145     zswap_(&n, x, &inc_x, y, &inc_y);
00146 }
00147 
00160 void blas_sscal(int n, float a, float* x, int inc_x)
00161 {
00162     sscal_(&n, &a, x, &inc_x);
00163 }
00164 
00165 void blas_dscal(int n, double a, double* x, int inc_x)
00166 {
00167     dscal_(&n, &a, x, &inc_x);
00168 }
00169 
00170 void blas_cscal(int n, Complex_f a, Complex_f* x, int inc_x)
00171 {
00172     cscal_(&n, &a, x, &inc_x);
00173 }
00174 
00175 void blas_zscal(int n, Complex_d a, Complex_d* x, int inc_x)
00176 {
00177     zscal_(&n, &a, x, &inc_x);
00178 }
00179 
00192 void blas_scopy(int n, const float* x, int inc_x, float* y, int inc_y)
00193 {
00194     scopy_(&n, (float*)x, &inc_x, y, &inc_y);
00195 }
00196 
00197 void blas_dcopy(int n, const double* x, int inc_x, double* y, int inc_y)
00198 {
00199     dcopy_(&n, (double*)x, &inc_x, y, &inc_y);
00200 }
00201 
00202 void blas_ccopy(int n, const Complex_f* x, int inc_x, Complex_f* y, int inc_y)
00203 {
00204     ccopy_(&n, (Complex_f*)x, &inc_x, y, &inc_y);
00205 }
00206 
00207 void blas_zcopy(int n, const Complex_d* x, int inc_x, Complex_d* y, int inc_y)
00208 {
00209     zcopy_(&n, (Complex_d*)x, &inc_x, y, &inc_y);
00210 }
00211 
00224 void blas_saxpy
00225 (
00226     int          n, 
00227     float        a, 
00228     const float* x, 
00229     int          inc_x, 
00230     float*       y, 
00231     int          inc_y
00232 )
00233 {
00234     saxpy_(&n, &a, (float*)x, &inc_x, y, &inc_y);
00235 }
00236 
00237 void blas_daxpy
00238 (
00239     int           n, 
00240     double        a, 
00241     const double* x, 
00242     int           inc_x, 
00243     double*       y, 
00244     int           inc_y
00245 )
00246 {
00247     daxpy_(&n, &a, (double*)x, &inc_x, y, &inc_y);
00248 }
00249 
00250 void blas_caxpy
00251 (
00252     int              n, 
00253     Complex_f        a, 
00254     const Complex_f* x, 
00255     int              inc_x, 
00256     Complex_f*       y, 
00257     int              inc_y
00258 )
00259 {
00260     caxpy_(&n, &a, (Complex_f*)x, &inc_x, y, &inc_y);
00261 }
00262 
00263 void blas_zaxpy
00264 (
00265     int              n, 
00266     Complex_d        a, 
00267     const Complex_d* x, 
00268     int              inc_x, 
00269     Complex_d*       y, 
00270     int              inc_y
00271 )
00272 {
00273     zaxpy_(&n, &a, (Complex_d*)x, &inc_x, y, &inc_y);
00274 }
00275 
00288 float blas_sdot(int n, const float* x, int inc_x, const float* y, int inc_y)
00289 {
00290     return sdot_(&n, (float*)x, &inc_x, (float*)y, &inc_y);
00291 }
00292 
00293 double blas_ddot(int n, const double* x, int inc_x, const double* y, int inc_y)
00294 {
00295     return ddot_(&n, (double*)x, &inc_x, (double*)y, &inc_y);
00296 }
00297 
00310 float blas_snrm2(int n, const float* x, int inc_x)
00311 {
00312     return snrm2(&n, (float*)x, &inc_x);
00313 }
00314 
00315 double blas_dnrm2(int n, const double* x, int inc_x)
00316 {
00317     return dnrm2_(&n, (double*)x, &inc_x);
00318 }
00319 
00332 float blas_sasum(int n, const float* x, int inc_x)
00333 {
00334     return sasum_(&n, (float*)x, &inc_x);
00335 }
00336 
00337 double blas_dasum(int n, const double* x, int inc_x)
00338 {
00339     return dasum_(&n, (double*)x, &inc_x);
00340 }
00341 
00354 int blas_isamax(int n, const float* x, int inc_x)
00355 {
00356     return isamax_(&n, (float*)x, &inc_x);
00357 }
00358 
00359 int blas_idamax(int n, const double* x, int inc_x)
00360 {
00361     return idamax_(&n, (double*)x, &inc_x);
00362 }
00363 
00364 int blas_icamax(int n, const Complex_f* x, int inc_x)
00365 {
00366     return icamax_(&n, (Complex_f*)x, &inc_x);
00367 }
00368 
00369 int blas_izamax(int n, const Complex_d* x, int inc_x)
00370 {
00371     return izamax_(&n, (Complex_d*)x, &inc_x);
00372 }
00373 
00379 /* ===============  LEVEL 2 PROTOTYPES ==============*/
00380 
00381 
00412 void blas_sgemv
00413 (
00414     char         trans, 
00415     int          m, 
00416     int          n, 
00417     float        alpha, 
00418     const float* A, 
00419     int          lda,
00420     const float* x,
00421     int          inc_x,
00422     float        beta,
00423     float*       y,
00424     int          inc_y
00425 )
00426 {
00427     trans = (trans == 'N' || trans == 'n') ? 'T' : 'N';
00428     sgemv_(&trans, &n, &m, &alpha, (float*)A, &lda, (float*)x, &inc_x,
00429             &beta, y, &inc_y);
00430 }
00431 
00455 void blas_dgemv
00456 (
00457     char          trans, 
00458     int           m, 
00459     int           n, 
00460     double        alpha, 
00461     const double* A, 
00462     int           lda,
00463     const double* x,
00464     int           inc_x,
00465     double        beta,
00466     double*       y,
00467     int           inc_y
00468 )
00469 {
00470     trans = (trans == 'N' || trans == 'n') ? 'T' : 'N';
00471     dgemv_(&trans, &n, &m, &alpha, (double*)A, &lda, (double*)x, &inc_x,
00472             &beta, y, &inc_y);
00473 }
00474 
00498 void blas_cgemv
00499 (
00500     char             trans, 
00501     int              m, 
00502     int              n, 
00503     Complex_f        alpha, 
00504     const Complex_f* A, 
00505     int              lda,
00506     const Complex_f* x,
00507     int              inc_x,
00508     Complex_f        beta,
00509     Complex_f*       y,
00510     int              inc_y
00511 )
00512 {
00513     trans = (trans == 'N' || trans == 'n') ? 'T' : 'N';
00514     cgemv_(&trans, &n, &m, &alpha, (Complex_f*)A, &lda, (Complex_f*)x, &inc_x,
00515             &beta, y, &inc_y);
00516 }
00517 
00541 void blas_zgemv
00542 (
00543     char             trans, 
00544     int              m, 
00545     int              n, 
00546     Complex_d        alpha, 
00547     const Complex_d* A, 
00548     int              lda,
00549     const Complex_d* x,
00550     int              inc_x,
00551     Complex_d        beta,
00552     Complex_d*       y,
00553     int              inc_y
00554 )
00555 {
00556     trans = (trans == 'N' || trans == 'n') ? 'T' : 'N';
00557     zgemv_(&trans, &n, &m, &alpha, (Complex_d*)A, &lda, (Complex_d*)x, &inc_x,
00558             &beta, y, &inc_y);
00559 }
00560 
00566 /* ===============  LEVEL 3 ==============*/
00567 
00568 
00607 void blas_sgemm
00608 (
00609     char         trans_a, 
00610     char         trans_b, 
00611     int          m, 
00612     int          n, 
00613     int          k, 
00614     float        alpha, 
00615     const float* A, 
00616     int          lda,
00617     const float* B,
00618     int          ldb,
00619     float        beta,
00620     float*       C,
00621     int          ldc
00622 )
00623 {
00624     sgemm_(&trans_a, &trans_b, &n, &m, &k, &alpha, (float*) B, &ldb, 
00625             (float*) A, &lda, &beta, C, &ldc);
00626 }
00627 
00659 void blas_dgemm
00660 (
00661     char          trans_a, 
00662     char          trans_b, 
00663     int           m, 
00664     int           n, 
00665     int           k, 
00666     double        alpha, 
00667     const double* A, 
00668     int           lda,
00669     const double* B,
00670     int           ldb,
00671     double        beta,
00672     double*       C,
00673     int           ldc
00674 )
00675 {
00676     dgemm_(&trans_a, &trans_b, &n, &m, &k, &alpha, (double*) B, &ldb, 
00677             (double*) A, &lda, &beta, C, &ldc);
00678 }
00679 
00711 void blas_cgemm
00712 (
00713     char             trans_a, 
00714     char             trans_b, 
00715     int              m, 
00716     int              n, 
00717     int              k, 
00718     Complex_f        alpha, 
00719     const Complex_f* A, 
00720     int              lda,
00721     const Complex_f* B,
00722     int              ldb,
00723     Complex_f        beta,
00724     Complex_f*       C,
00725     int              ldc
00726 )
00727 {
00728     cgemm_(&trans_a, &trans_b, &n, &m, &k, &alpha, (Complex_f*) B, &ldb, 
00729             (Complex_f*) A, &lda, &beta, C, &ldc);
00730 }
00731 
00763 void blas_zgemm
00764 (
00765     char             trans_a, 
00766     char             trans_b, 
00767     int              m, 
00768     int              n, 
00769     int              k, 
00770     Complex_d        alpha, 
00771     const Complex_d* A, 
00772     int              lda,
00773     const Complex_d* B,
00774     int              ldb,
00775     Complex_d        beta,
00776     Complex_d*       C,
00777     int              ldc
00778 )
00779 {
00780     zgemm_(&trans_a, &trans_b, &n, &m, &k, &alpha, (Complex_d*) B, &ldb, 
00781             (Complex_d*) A, &lda, &beta, C, &ldc);
00782 }
00783