cblas blas implementations

These should conform to the blas package specification, and have been
tested via biogo.matrix for routines that that package is dependent on.
There has been a fair level of manual review, but the code generation is
not guaranteed to be free from interpretation errors.
This commit is contained in:
kortschak
2013-07-14 20:23:24 +09:30
parent 2b459e3bd2
commit 6fca5f3394
3 changed files with 4292 additions and 0 deletions

3143
cblas/blas.go Normal file

File diff suppressed because it is too large Load Diff

596
cblas/cblas.h Normal file
View File

@@ -0,0 +1,596 @@
#ifndef CBLAS_H
#ifndef CBLAS_ENUM_DEFINED_H
#define CBLAS_ENUM_DEFINED_H
enum CBLAS_ORDER {CblasRowMajor=101, CblasColMajor=102 };
enum CBLAS_TRANSPOSE {CblasNoTrans=111, CblasTrans=112, CblasConjTrans=113,
AtlasConj=114};
enum CBLAS_UPLO {CblasUpper=121, CblasLower=122};
enum CBLAS_DIAG {CblasNonUnit=131, CblasUnit=132};
enum CBLAS_SIDE {CblasLeft=141, CblasRight=142};
#endif
#ifndef CBLAS_ENUM_ONLY
#define CBLAS_H
#define CBLAS_INDEX int
int cblas_errprn(int ierr, int info, char *form, ...);
/*
* ===========================================================================
* Prototypes for level 1 BLAS functions (complex are recast as routines)
* ===========================================================================
*/
float cblas_sdsdot(const int N, const float alpha, const float *X,
const int incX, const float *Y, const int incY);
double cblas_dsdot(const int N, const float *X, const int incX, const float *Y,
const int incY);
float cblas_sdot(const int N, const float *X, const int incX,
const float *Y, const int incY);
double cblas_ddot(const int N, const double *X, const int incX,
const double *Y, const int incY);
/*
* Functions having prefixes Z and C only
*/
void cblas_cdotu_sub(const int N, const void *X, const int incX,
const void *Y, const int incY, void *dotu);
void cblas_cdotc_sub(const int N, const void *X, const int incX,
const void *Y, const int incY, void *dotc);
void cblas_zdotu_sub(const int N, const void *X, const int incX,
const void *Y, const int incY, void *dotu);
void cblas_zdotc_sub(const int N, const void *X, const int incX,
const void *Y, const int incY, void *dotc);
/*
* Functions having prefixes S D SC DZ
*/
float cblas_snrm2(const int N, const float *X, const int incX);
float cblas_sasum(const int N, const float *X, const int incX);
double cblas_dnrm2(const int N, const double *X, const int incX);
double cblas_dasum(const int N, const double *X, const int incX);
float cblas_scnrm2(const int N, const void *X, const int incX);
float cblas_scasum(const int N, const void *X, const int incX);
double cblas_dznrm2(const int N, const void *X, const int incX);
double cblas_dzasum(const int N, const void *X, const int incX);
/*
* Functions having standard 4 prefixes (S D C Z)
*/
CBLAS_INDEX cblas_isamax(const int N, const float *X, const int incX);
CBLAS_INDEX cblas_idamax(const int N, const double *X, const int incX);
CBLAS_INDEX cblas_icamax(const int N, const void *X, const int incX);
CBLAS_INDEX cblas_izamax(const int N, const void *X, const int incX);
/*
* ===========================================================================
* Prototypes for level 1 BLAS routines
* ===========================================================================
*/
/*
* Routines with standard 4 prefixes (s, d, c, z)
*/
void cblas_sswap(const int N, float *X, const int incX,
float *Y, const int incY);
void cblas_scopy(const int N, const float *X, const int incX,
float *Y, const int incY);
void cblas_saxpy(const int N, const float alpha, const float *X,
const int incX, float *Y, const int incY);
void catlas_saxpby(const int N, const float alpha, const float *X,
const int incX, const float beta, float *Y, const int incY);
void catlas_sset
(const int N, const float alpha, float *X, const int incX);
void cblas_dswap(const int N, double *X, const int incX,
double *Y, const int incY);
void cblas_dcopy(const int N, const double *X, const int incX,
double *Y, const int incY);
void cblas_daxpy(const int N, const double alpha, const double *X,
const int incX, double *Y, const int incY);
void catlas_daxpby(const int N, const double alpha, const double *X,
const int incX, const double beta, double *Y, const int incY);
void catlas_dset
(const int N, const double alpha, double *X, const int incX);
void cblas_cswap(const int N, void *X, const int incX,
void *Y, const int incY);
void cblas_ccopy(const int N, const void *X, const int incX,
void *Y, const int incY);
void cblas_caxpy(const int N, const void *alpha, const void *X,
const int incX, void *Y, const int incY);
void catlas_caxpby(const int N, const void *alpha, const void *X,
const int incX, const void *beta, void *Y, const int incY);
void catlas_cset
(const int N, const void *alpha, void *X, const int incX);
void cblas_zswap(const int N, void *X, const int incX,
void *Y, const int incY);
void cblas_zcopy(const int N, const void *X, const int incX,
void *Y, const int incY);
void cblas_zaxpy(const int N, const void *alpha, const void *X,
const int incX, void *Y, const int incY);
void catlas_zaxpby(const int N, const void *alpha, const void *X,
const int incX, const void *beta, void *Y, const int incY);
void catlas_zset
(const int N, const void *alpha, void *X, const int incX);
/*
* Routines with S and D prefix only
*/
void cblas_srotg(float *a, float *b, float *c, float *s);
void cblas_srotmg(float *d1, float *d2, float *b1, const float b2, float *P);
void cblas_srot(const int N, float *X, const int incX,
float *Y, const int incY, const float c, const float s);
void cblas_srotm(const int N, float *X, const int incX,
float *Y, const int incY, const float *P);
void cblas_drotg(double *a, double *b, double *c, double *s);
void cblas_drotmg(double *d1, double *d2, double *b1, const double b2, double *P);
void cblas_drot(const int N, double *X, const int incX,
double *Y, const int incY, const double c, const double s);
void cblas_drotm(const int N, double *X, const int incX,
double *Y, const int incY, const double *P);
/*
* Routines with S D C Z CS and ZD prefixes
*/
void cblas_sscal(const int N, const float alpha, float *X, const int incX);
void cblas_dscal(const int N, const double alpha, double *X, const int incX);
void cblas_cscal(const int N, const void *alpha, void *X, const int incX);
void cblas_zscal(const int N, const void *alpha, void *X, const int incX);
void cblas_csscal(const int N, const float alpha, void *X, const int incX);
void cblas_zdscal(const int N, const double alpha, void *X, const int incX);
/*
* Extra reference routines provided by ATLAS, but not mandated by the standard
*/
void cblas_crotg(void *a, void *b, void *c, void *s);
void cblas_zrotg(void *a, void *b, void *c, void *s);
void cblas_csrot(const int N, void *X, const int incX, void *Y, const int incY,
const float c, const float s);
void cblas_zdrot(const int N, void *X, const int incX, void *Y, const int incY,
const double c, const double s);
/*
* ===========================================================================
* Prototypes for level 2 BLAS
* ===========================================================================
*/
/*
* Routines with standard 4 prefixes (S, D, C, Z)
*/
void cblas_sgemv(const enum CBLAS_ORDER Order,
const enum CBLAS_TRANSPOSE TransA, const int M, const int N,
const float alpha, const float *A, const int lda,
const float *X, const int incX, const float beta,
float *Y, const int incY);
void cblas_sgbmv(const enum CBLAS_ORDER Order,
const enum CBLAS_TRANSPOSE TransA, const int M, const int N,
const int KL, const int KU, const float alpha,
const float *A, const int lda, const float *X,
const int incX, const float beta, float *Y, const int incY);
void cblas_strmv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo,
const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
const int N, const float *A, const int lda,
float *X, const int incX);
void cblas_stbmv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo,
const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
const int N, const int K, const float *A, const int lda,
float *X, const int incX);
void cblas_stpmv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo,
const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
const int N, const float *Ap, float *X, const int incX);
void cblas_strsv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo,
const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
const int N, const float *A, const int lda, float *X,
const int incX);
void cblas_stbsv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo,
const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
const int N, const int K, const float *A, const int lda,
float *X, const int incX);
void cblas_stpsv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo,
const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
const int N, const float *Ap, float *X, const int incX);
void cblas_dgemv(const enum CBLAS_ORDER Order,
const enum CBLAS_TRANSPOSE TransA, const int M, const int N,
const double alpha, const double *A, const int lda,
const double *X, const int incX, const double beta,
double *Y, const int incY);
void cblas_dgbmv(const enum CBLAS_ORDER Order,
const enum CBLAS_TRANSPOSE TransA, const int M, const int N,
const int KL, const int KU, const double alpha,
const double *A, const int lda, const double *X,
const int incX, const double beta, double *Y, const int incY);
void cblas_dtrmv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo,
const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
const int N, const double *A, const int lda,
double *X, const int incX);
void cblas_dtbmv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo,
const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
const int N, const int K, const double *A, const int lda,
double *X, const int incX);
void cblas_dtpmv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo,
const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
const int N, const double *Ap, double *X, const int incX);
void cblas_dtrsv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo,
const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
const int N, const double *A, const int lda, double *X,
const int incX);
void cblas_dtbsv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo,
const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
const int N, const int K, const double *A, const int lda,
double *X, const int incX);
void cblas_dtpsv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo,
const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
const int N, const double *Ap, double *X, const int incX);
void cblas_cgemv(const enum CBLAS_ORDER Order,
const enum CBLAS_TRANSPOSE TransA, const int M, const int N,
const void *alpha, const void *A, const int lda,
const void *X, const int incX, const void *beta,
void *Y, const int incY);
void cblas_cgbmv(const enum CBLAS_ORDER Order,
const enum CBLAS_TRANSPOSE TransA, const int M, const int N,
const int KL, const int KU, const void *alpha,
const void *A, const int lda, const void *X,
const int incX, const void *beta, void *Y, const int incY);
void cblas_ctrmv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo,
const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
const int N, const void *A, const int lda,
void *X, const int incX);
void cblas_ctbmv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo,
const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
const int N, const int K, const void *A, const int lda,
void *X, const int incX);
void cblas_ctpmv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo,
const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
const int N, const void *Ap, void *X, const int incX);
void cblas_ctrsv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo,
const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
const int N, const void *A, const int lda, void *X,
const int incX);
void cblas_ctbsv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo,
const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
const int N, const int K, const void *A, const int lda,
void *X, const int incX);
void cblas_ctpsv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo,
const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
const int N, const void *Ap, void *X, const int incX);
void cblas_zgemv(const enum CBLAS_ORDER Order,
const enum CBLAS_TRANSPOSE TransA, const int M, const int N,
const void *alpha, const void *A, const int lda,
const void *X, const int incX, const void *beta,
void *Y, const int incY);
void cblas_zgbmv(const enum CBLAS_ORDER Order,
const enum CBLAS_TRANSPOSE TransA, const int M, const int N,
const int KL, const int KU, const void *alpha,
const void *A, const int lda, const void *X,
const int incX, const void *beta, void *Y, const int incY);
void cblas_ztrmv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo,
const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
const int N, const void *A, const int lda,
void *X, const int incX);
void cblas_ztbmv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo,
const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
const int N, const int K, const void *A, const int lda,
void *X, const int incX);
void cblas_ztpmv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo,
const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
const int N, const void *Ap, void *X, const int incX);
void cblas_ztrsv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo,
const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
const int N, const void *A, const int lda, void *X,
const int incX);
void cblas_ztbsv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo,
const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
const int N, const int K, const void *A, const int lda,
void *X, const int incX);
void cblas_ztpsv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo,
const enum CBLAS_TRANSPOSE TransA, const enum CBLAS_DIAG Diag,
const int N, const void *Ap, void *X, const int incX);
/*
* Routines with S and D prefixes only
*/
void cblas_ssymv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo,
const int N, const float alpha, const float *A,
const int lda, const float *X, const int incX,
const float beta, float *Y, const int incY);
void cblas_ssbmv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo,
const int N, const int K, const float alpha, const float *A,
const int lda, const float *X, const int incX,
const float beta, float *Y, const int incY);
void cblas_sspmv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo,
const int N, const float alpha, const float *Ap,
const float *X, const int incX,
const float beta, float *Y, const int incY);
void cblas_sger(const enum CBLAS_ORDER Order, const int M, const int N,
const float alpha, const float *X, const int incX,
const float *Y, const int incY, float *A, const int lda);
void cblas_ssyr(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo,
const int N, const float alpha, const float *X,
const int incX, float *A, const int lda);
void cblas_sspr(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo,
const int N, const float alpha, const float *X,
const int incX, float *Ap);
void cblas_ssyr2(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo,
const int N, const float alpha, const float *X,
const int incX, const float *Y, const int incY, float *A,
const int lda);
void cblas_sspr2(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo,
const int N, const float alpha, const float *X,
const int incX, const float *Y, const int incY, float *Ap);
void cblas_dsymv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo,
const int N, const double alpha, const double *A,
const int lda, const double *X, const int incX,
const double beta, double *Y, const int incY);
void cblas_dsbmv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo,
const int N, const int K, const double alpha, const double *A,
const int lda, const double *X, const int incX,
const double beta, double *Y, const int incY);
void cblas_dspmv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo,
const int N, const double alpha, const double *Ap,
const double *X, const int incX,
const double beta, double *Y, const int incY);
void cblas_dger(const enum CBLAS_ORDER Order, const int M, const int N,
const double alpha, const double *X, const int incX,
const double *Y, const int incY, double *A, const int lda);
void cblas_dsyr(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo,
const int N, const double alpha, const double *X,
const int incX, double *A, const int lda);
void cblas_dspr(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo,
const int N, const double alpha, const double *X,
const int incX, double *Ap);
void cblas_dsyr2(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo,
const int N, const double alpha, const double *X,
const int incX, const double *Y, const int incY, double *A,
const int lda);
void cblas_dspr2(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo,
const int N, const double alpha, const double *X,
const int incX, const double *Y, const int incY, double *Ap);
/*
* Routines with C and Z prefixes only
*/
void cblas_chemv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo,
const int N, const void *alpha, const void *A,
const int lda, const void *X, const int incX,
const void *beta, void *Y, const int incY);
void cblas_chbmv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo,
const int N, const int K, const void *alpha, const void *A,
const int lda, const void *X, const int incX,
const void *beta, void *Y, const int incY);
void cblas_chpmv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo,
const int N, const void *alpha, const void *Ap,
const void *X, const int incX,
const void *beta, void *Y, const int incY);
void cblas_cgeru(const enum CBLAS_ORDER Order, const int M, const int N,
const void *alpha, const void *X, const int incX,
const void *Y, const int incY, void *A, const int lda);
void cblas_cgerc(const enum CBLAS_ORDER Order, const int M, const int N,
const void *alpha, const void *X, const int incX,
const void *Y, const int incY, void *A, const int lda);
void cblas_cher(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo,
const int N, const float alpha, const void *X, const int incX,
void *A, const int lda);
void cblas_chpr(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo,
const int N, const float alpha, const void *X,
const int incX, void *Ap);
void cblas_cher2(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, const int N,
const void *alpha, const void *X, const int incX,
const void *Y, const int incY, void *A, const int lda);
void cblas_chpr2(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, const int N,
const void *alpha, const void *X, const int incX,
const void *Y, const int incY, void *Ap);
void cblas_zhemv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo,
const int N, const void *alpha, const void *A,
const int lda, const void *X, const int incX,
const void *beta, void *Y, const int incY);
void cblas_zhbmv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo,
const int N, const int K, const void *alpha, const void *A,
const int lda, const void *X, const int incX,
const void *beta, void *Y, const int incY);
void cblas_zhpmv(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo,
const int N, const void *alpha, const void *Ap,
const void *X, const int incX,
const void *beta, void *Y, const int incY);
void cblas_zgeru(const enum CBLAS_ORDER Order, const int M, const int N,
const void *alpha, const void *X, const int incX,
const void *Y, const int incY, void *A, const int lda);
void cblas_zgerc(const enum CBLAS_ORDER Order, const int M, const int N,
const void *alpha, const void *X, const int incX,
const void *Y, const int incY, void *A, const int lda);
void cblas_zher(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo,
const int N, const double alpha, const void *X, const int incX,
void *A, const int lda);
void cblas_zhpr(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo,
const int N, const double alpha, const void *X,
const int incX, void *Ap);
void cblas_zher2(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, const int N,
const void *alpha, const void *X, const int incX,
const void *Y, const int incY, void *A, const int lda);
void cblas_zhpr2(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo, const int N,
const void *alpha, const void *X, const int incX,
const void *Y, const int incY, void *Ap);
/*
* ===========================================================================
* Prototypes for level 3 BLAS
* ===========================================================================
*/
/*
* Routines with standard 4 prefixes (S, D, C, Z)
*/
void cblas_sgemm(const enum CBLAS_ORDER Order, const enum CBLAS_TRANSPOSE TransA,
const enum CBLAS_TRANSPOSE TransB, const int M, const int N,
const int K, const float alpha, const float *A,
const int lda, const float *B, const int ldb,
const float beta, float *C, const int ldc);
void cblas_ssymm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side,
const enum CBLAS_UPLO Uplo, const int M, const int N,
const float alpha, const float *A, const int lda,
const float *B, const int ldb, const float beta,
float *C, const int ldc);
void cblas_ssyrk(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo,
const enum CBLAS_TRANSPOSE Trans, const int N, const int K,
const float alpha, const float *A, const int lda,
const float beta, float *C, const int ldc);
void cblas_ssyr2k(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo,
const enum CBLAS_TRANSPOSE Trans, const int N, const int K,
const float alpha, const float *A, const int lda,
const float *B, const int ldb, const float beta,
float *C, const int ldc);
void cblas_strmm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side,
const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA,
const enum CBLAS_DIAG Diag, const int M, const int N,
const float alpha, const float *A, const int lda,
float *B, const int ldb);
void cblas_strsm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side,
const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA,
const enum CBLAS_DIAG Diag, const int M, const int N,
const float alpha, const float *A, const int lda,
float *B, const int ldb);
void cblas_dgemm(const enum CBLAS_ORDER Order, const enum CBLAS_TRANSPOSE TransA,
const enum CBLAS_TRANSPOSE TransB, const int M, const int N,
const int K, const double alpha, const double *A,
const int lda, const double *B, const int ldb,
const double beta, double *C, const int ldc);
void cblas_dsymm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side,
const enum CBLAS_UPLO Uplo, const int M, const int N,
const double alpha, const double *A, const int lda,
const double *B, const int ldb, const double beta,
double *C, const int ldc);
void cblas_dsyrk(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo,
const enum CBLAS_TRANSPOSE Trans, const int N, const int K,
const double alpha, const double *A, const int lda,
const double beta, double *C, const int ldc);
void cblas_dsyr2k(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo,
const enum CBLAS_TRANSPOSE Trans, const int N, const int K,
const double alpha, const double *A, const int lda,
const double *B, const int ldb, const double beta,
double *C, const int ldc);
void cblas_dtrmm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side,
const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA,
const enum CBLAS_DIAG Diag, const int M, const int N,
const double alpha, const double *A, const int lda,
double *B, const int ldb);
void cblas_dtrsm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side,
const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA,
const enum CBLAS_DIAG Diag, const int M, const int N,
const double alpha, const double *A, const int lda,
double *B, const int ldb);
void cblas_cgemm(const enum CBLAS_ORDER Order, const enum CBLAS_TRANSPOSE TransA,
const enum CBLAS_TRANSPOSE TransB, const int M, const int N,
const int K, const void *alpha, const void *A,
const int lda, const void *B, const int ldb,
const void *beta, void *C, const int ldc);
void cblas_csymm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side,
const enum CBLAS_UPLO Uplo, const int M, const int N,
const void *alpha, const void *A, const int lda,
const void *B, const int ldb, const void *beta,
void *C, const int ldc);
void cblas_csyrk(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo,
const enum CBLAS_TRANSPOSE Trans, const int N, const int K,
const void *alpha, const void *A, const int lda,
const void *beta, void *C, const int ldc);
void cblas_csyr2k(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo,
const enum CBLAS_TRANSPOSE Trans, const int N, const int K,
const void *alpha, const void *A, const int lda,
const void *B, const int ldb, const void *beta,
void *C, const int ldc);
void cblas_ctrmm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side,
const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA,
const enum CBLAS_DIAG Diag, const int M, const int N,
const void *alpha, const void *A, const int lda,
void *B, const int ldb);
void cblas_ctrsm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side,
const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA,
const enum CBLAS_DIAG Diag, const int M, const int N,
const void *alpha, const void *A, const int lda,
void *B, const int ldb);
void cblas_zgemm(const enum CBLAS_ORDER Order, const enum CBLAS_TRANSPOSE TransA,
const enum CBLAS_TRANSPOSE TransB, const int M, const int N,
const int K, const void *alpha, const void *A,
const int lda, const void *B, const int ldb,
const void *beta, void *C, const int ldc);
void cblas_zsymm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side,
const enum CBLAS_UPLO Uplo, const int M, const int N,
const void *alpha, const void *A, const int lda,
const void *B, const int ldb, const void *beta,
void *C, const int ldc);
void cblas_zsyrk(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo,
const enum CBLAS_TRANSPOSE Trans, const int N, const int K,
const void *alpha, const void *A, const int lda,
const void *beta, void *C, const int ldc);
void cblas_zsyr2k(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo,
const enum CBLAS_TRANSPOSE Trans, const int N, const int K,
const void *alpha, const void *A, const int lda,
const void *B, const int ldb, const void *beta,
void *C, const int ldc);
void cblas_ztrmm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side,
const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA,
const enum CBLAS_DIAG Diag, const int M, const int N,
const void *alpha, const void *A, const int lda,
void *B, const int ldb);
void cblas_ztrsm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side,
const enum CBLAS_UPLO Uplo, const enum CBLAS_TRANSPOSE TransA,
const enum CBLAS_DIAG Diag, const int M, const int N,
const void *alpha, const void *A, const int lda,
void *B, const int ldb);
/*
* Routines with prefixes C and Z only
*/
void cblas_chemm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side,
const enum CBLAS_UPLO Uplo, const int M, const int N,
const void *alpha, const void *A, const int lda,
const void *B, const int ldb, const void *beta,
void *C, const int ldc);
void cblas_cherk(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo,
const enum CBLAS_TRANSPOSE Trans, const int N, const int K,
const float alpha, const void *A, const int lda,
const float beta, void *C, const int ldc);
void cblas_cher2k(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo,
const enum CBLAS_TRANSPOSE Trans, const int N, const int K,
const void *alpha, const void *A, const int lda,
const void *B, const int ldb, const float beta,
void *C, const int ldc);
void cblas_zhemm(const enum CBLAS_ORDER Order, const enum CBLAS_SIDE Side,
const enum CBLAS_UPLO Uplo, const int M, const int N,
const void *alpha, const void *A, const int lda,
const void *B, const int ldb, const void *beta,
void *C, const int ldc);
void cblas_zherk(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo,
const enum CBLAS_TRANSPOSE Trans, const int N, const int K,
const double alpha, const void *A, const int lda,
const double beta, void *C, const int ldc);
void cblas_zher2k(const enum CBLAS_ORDER Order, const enum CBLAS_UPLO Uplo,
const enum CBLAS_TRANSPOSE Trans, const int N, const int K,
const void *alpha, const void *A, const int lda,
const void *B, const int ldb, const double beta,
void *C, const int ldc);
int cblas_errprn(int ierr, int info, char *form, ...);
#endif /* end #ifdef CBLAS_ENUM_ONLY */
#endif

553
cblas/genBlas.pl Executable file
View File

@@ -0,0 +1,553 @@
#!/usr/bin/env perl
# Copyright ©2012 The bíogo.blas Authors. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.
use strict;
use warnings;
my $cblasHeader = "cblas.h";
my $LIB = "/usr/lib/";
my $excludeComplex = 0;
my $excludeAtlas = 1;
open(my $cblas, "<", $cblasHeader) or die;
open(my $goblas, ">", "blas.go") or die;
my %done = ("cblas_errprn" => 1,
"cblas_srotg" => 1,
"cblas_srotmg" => 1,
"cblas_srotm" => 1,
"cblas_drotg" => 1,
"cblas_drotmg" => 1,
"cblas_drotm" => 1,
"cblas_crotg" => 1,
"cblas_zrotg" => 1,
"cblas_cdotu_sub" => 1,
"cblas_cdotc_sub" => 1,
"cblas_zdotu_sub" => 1,
"cblas_zdotc_sub" => 1,
);
my $atlas = "";
if ($excludeAtlas) {
$done{'cblas_csrot'} = 1;
$done{'cblas_zdrot'} = 1;
} else {
$atlas = " -latlas";
}
printf $goblas <<EOH;
// Do not manually edit this file. It was created by the genBlas.pl script from ${cblasHeader}.
// Copyright ©2012 The bíogo.blas Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Package cblas implements the blas interfaces.
package cblas
/*
#cgo CFLAGS: -g -O2 -fPIC -m64 -pthread
#cgo LDFLAGS: -L${LIB} -lblas${atlas}
#include "${cblasHeader}"
*/
import "C"
import (
"github.com/gonum/blas"
"unsafe"
)
// Type check assertions:
var (
_ blas.Float32 = Blas{}
_ blas.Float64 = Blas{}
_ blas.Complex64 = Blas{}
_ blas.Complex128 = Blas{}
)
func max(a, b int) int {
if a > b {
return a
}
return b
}
type Blas struct{}
// Special cases...
func (Blas) Srotg(a float32, b float32) (c float32, s float32, r float32, z float32) {
C.cblas_srotg((*C.float)(&a), (*C.float)(&b), (*C.float)(&c), (*C.float)(&s))
return c, s, a, b
}
func (Blas) Srotmg(d1 float32, d2 float32, b1 float32, b2 float32) (p *blas.SrotmParams, rd1 float32, rd2 float32, rb1 float32) {
p = &blas.SrotmParams{}
C.cblas_srotmg((*C.float)(&d1), (*C.float)(&d2), (*C.float)(&b1), C.float(b2), (*C.float)(unsafe.Pointer(p)))
return p, d1, d2, b1
}
func (Blas) Srotm(n int, x []float32, incX int, y []float32, incY int, p *blas.SrotmParams) {
if n < 0 {
panic("cblas: n < 0")
}
if n*incX > len(x) {
panic("cblas: index out of range")
}
if n*incY > len(y) {
panic("cblas: index out of range")
}
C.cblas_srotm(C.int(n), (*C.float)(&x[0]), C.int(incX), (*C.float)(&y[0]), C.int(incY), (*C.float)(unsafe.Pointer(p)))
}
func (Blas) Drotg(a float64, b float64) (c float64, s float64, r float64, z float64) {
C.cblas_drotg((*C.double)(&a), (*C.double)(&b), (*C.double)(&c), (*C.double)(&s))
return c, s, a, b
}
func (Blas) Drotmg(d1 float64, d2 float64, b1 float64, b2 float64) (p *blas.DrotmParams, rd1 float64, rd2 float64, rb1 float64) {
p = &blas.DrotmParams{}
C.cblas_drotmg((*C.double)(&d1), (*C.double)(&d2), (*C.double)(&b1), C.double(b2), (*C.double)(unsafe.Pointer(p)))
return p, d1, d2, b1
}
func (Blas) Drotm(n int, x []float64, incX int, y []float64, incY int, p *blas.DrotmParams) {
if n < 0 {
panic("cblas: n < 0")
}
if n*incX > len(x) {
panic("cblas: index out of range")
}
if n*incY > len(y) {
panic("cblas: index out of range")
}
C.cblas_drotm(C.int(n), (*C.double)(&x[0]), C.int(incX), (*C.double)(&y[0]), C.int(incY), (*C.double)(unsafe.Pointer(p)))
}
func (Blas) Cdotu(n int, x []complex64, incX int, y []complex64, incY int) (dotu complex64) {
if n < 0 {
panic("cblas: n < 0")
}
if incX <= 0 || n*incX > len(x) {
panic("cblas: index out of range")
}
if incY <= 0 || n*incY > len(y) {
panic("cblas: index out of range")
}
C.cblas_cdotu_sub(C.int(n), unsafe.Pointer(&x[0]), C.int(incX), unsafe.Pointer(&y[0]), C.int(incY), unsafe.Pointer(&dotu))
return dotu
}
func (Blas) Cdotc(n int, x []complex64, incX int, y []complex64, incY int) (dotc complex64) {
if n < 0 {
panic("cblas: n < 0")
}
if incX <= 0 || n*incX > len(x) {
panic("cblas: index out of range")
}
if incY <= 0 || n*incY > len(y) {
panic("cblas: index out of range")
}
C.cblas_cdotc_sub(C.int(n), unsafe.Pointer(&x[0]), C.int(incX), unsafe.Pointer(&y[0]), C.int(incY), unsafe.Pointer(&dotc))
return dotc
}
func (Blas) Zdotu(n int, x []complex128, incX int, y []complex128, incY int) (dotu complex128) {
if n < 0 {
panic("cblas: n < 0")
}
if incX <= 0 || n*incX > len(x) {
panic("cblas: index out of range")
}
if incY <= 0 || n*incY > len(y) {
panic("cblas: index out of range")
}
C.cblas_zdotu_sub(C.int(n), unsafe.Pointer(&x[0]), C.int(incX), unsafe.Pointer(&y[0]), C.int(incY), unsafe.Pointer(&dotu))
return dotu
}
func (Blas) Zdotc(n int, x []complex128, incX int, y []complex128, incY int) (dotc complex128) {
if n < 0 {
panic("cblas: n < 0")
}
if incX <= 0 || n*incX > len(x) {
panic("cblas: index out of range")
}
if incY <= 0 || n*incY > len(y) {
panic("cblas: index out of range")
}
C.cblas_zdotc_sub(C.int(n), unsafe.Pointer(&x[0]), C.int(incX), unsafe.Pointer(&y[0]), C.int(incY), unsafe.Pointer(&dotc))
return dotc
}
EOH
printf $goblas <<EOH unless $excludeAtlas;
func (Blas) Crotg(a complex64, b complex64) (c complex64, s complex64, r complex64, z complex64) {
C.cblas_srotg(unsafe.Pointer(&a), unsafe.Pointer(&b), unsafe.Pointer(&c), unsafe.Pointer(&s))
return c, s, a, b
}
func (Blas) Zrotg(a complex128, b complex128) (c complex128, s complex128, r complex128, z complex128) {
C.cblas_drotg(unsafe.Pointer(&a), unsafe.Pointer(&b), unsafe.Pointer(&c), unsafe.Pointer(&s))
return c, s, a, b
}
EOH
print $goblas "\n";
$/ = undef;
my $header = <$cblas>;
# horrible munging of text...
$header =~ s/#[^\n\r]*//g; # delete cpp lines
$header =~ s/\n +([^\n\r]*)/\n$1/g; # remove starting space
$header =~ s/(?:\n ?\n)+/\n/g; # delete empty lines
$header =~ s! ((['"]) (?: \\. | .)*? \2) | # skip quoted strings
/\* .*? \*/ | # delete C comments
// [^\n\r]* # delete C++ comments just in case
! $1 || ' ' # change comments to a single space
!xseg; # ignore white space, treat as single line
# evaluate result, repeat globally
$header =~ s/([^;])\n/$1/g; # join prototypes into single lines
$header =~ s/, +/,/g;
$header =~ s/ +/ /g;
$header =~ s/ +}/}/g;
$header =~ s/\n+//;
$/ = "\n";
my @lines = split ";\n", $header;
our %retConv = (
"int" => "int ",
"float" => "float32 ",
"double" => "float64 ",
"CBLAS_INDEX" => "int ",
"void" => ""
);
foreach my $line (@lines) {
process($line);
}
close($goblas);
`go fmt .`;
sub process {
my $line = shift;
chomp $line;
if (not $line =~ m/^enum/) {
processProto($line);
}
}
sub processProto {
my $proto = shift;
my ($func, $paramList) = split /[()]/, $proto;
(my $ret, $func) = split ' ', $func;
if ($done{$func} or $excludeComplex && $func =~ m/_[isd]?[zc]/ or $excludeAtlas && $func =~ m/^catlas_/) {
return
}
$done{$func} = 1;
my $GoRet = $retConv{$ret};
my $complexType = $func;
$complexType =~ s/.*_[isd]?([zc]).*/$1/;
print $goblas "func (Blas) ".Gofunc($func)."(".processParamToGo($func, $paramList, $complexType).") ".$GoRet."{\n";
print $goblas processParamToChecks($func, $paramList);
print $goblas "\t";
if ($ret ne 'void') {
chop($GoRet);
print $goblas "return ".$GoRet."(";
}
print $goblas "C.$func(".processParamToC($func, $paramList).")";
if ($ret ne 'void') {
print $goblas ")";
}
print $goblas "\n}\n";
}
sub Gofunc {
my $fnName = shift;
$fnName =~ s/_sub//;
my ($pack, $func, $tail) = split '_', $fnName;
if ($pack eq 'cblas') {
$pack = "";
} else {
$pack = substr $pack, 1;
}
return ucfirst $pack . ucfirst $func . ucfirst $tail if $tail;
return ucfirst $pack . ucfirst $func;
}
sub processParamToGo {
my $func = shift;
my $paramList = shift;
my $complexType = shift;
my @processed;
my @params = split ',', $paramList;
foreach my $param (@params) {
my @parts = split /[ *]/, $param;
my $var = lcfirst $parts[scalar @parts - 1];
$param =~ m/^(?:const )?int/ && do {
push @processed, $var." int"; next;
};
$param =~ m/^(?:const )?void/ && do {
my $type;
if ($var eq "alpha" || $var eq "beta") {
$type = " ";
} else {
$type = " []";
}
if ($complexType eq 'c') {
push @processed, $var.$type."complex64"; next;
} elsif ($complexType eq 'z') {
push @processed, $var.$type."complex128"; next;
} else {
die "unexpected complex type for '$func' - '$complexType'";
}
};
$param =~ m/^(?:const )?char \*/ && do {
push @processed, $var." *byte"; next;
};
$param =~ m/^(?:const )?float \*/ && do {
push @processed, $var." []float32"; next;
};
$param =~ m/^(?:const )?double \*/ && do {
push @processed, $var." []float64"; next;
};
$param =~ m/^(?:const )?float/ && do {
push @processed, $var." float32"; next;
};
$param =~ m/^(?:const )?double/ && do {
push @processed, $var." float64"; next;
};
$param =~ m/^const enum/ && do {
$var eq "order" && do {
$var = "o";
push @processed, $var." blas.Order"; next;
};
$var =~ /trans/ && do {
$var =~ s/trans([AB]?)/t$1/;
push @processed, $var." blas.Transpose"; next;
};
$var eq "uplo" && do {
$var = "ul";
push @processed, $var." blas.Uplo"; next;
};
$var eq "diag" && do {
$var = "d";
push @processed, $var." blas.Diag"; next;
};
$var eq "side" && do {
$var = "s";
push @processed, $var." blas.Side"; next;
};
};
}
die "missed Go parameters from '$func', '$paramList'" if scalar @processed != scalar @params;
return join ", ", @processed;
}
sub processParamToChecks {
my $func = shift;
my $paramList = shift;
my @processed;
my @params = split ',', $paramList;
my %arrayArgs;
my %scalarArgs;
foreach my $param (@params) {
my @parts = split /[ *]/, $param;
my $var = lcfirst $parts[scalar @parts - 1];
$param =~ m/^(?:const )?int \*[a-zA-Z]/ && do {
$scalarArgs{$var} = 1; next;
};
$param =~ m/^(?:const )?void \*[a-zA-Z]/ && do {
if ($var ne "alpha" && $var ne "beta") {
$arrayArgs{$var} = 1;
}
next;
};
$param =~ m/^(?:const )?(?:float|double) \*[a-zA-Z]/ && do {
$arrayArgs{$var} = 1; next;
};
$param =~ m/^(?:const )?(?:int|float|double) [a-zA-Z]/ && do {
$scalarArgs{$var} = 1; next;
};
$param =~ m/^const enum [a-zA-Z]/ && do {
$var eq "order" && do {
$scalarArgs{'o'} = 1;
push @processed, "if o != blas.RowMajor && o != blas.ColMajor { panic(\"cblas: illegal order\") }"; next;
};
$var =~ /trans/ && do {
$var =~ s/trans([AB]?)/t$1/;
$scalarArgs{$var} = 1; next;
if ($func =~ m/cblas_[cz]h/) {
push @processed, "if $var != blas.NoTrans && $var != blas.ConjTrans { panic(\"cblas: illegal transpose\") }"; next;
} elsif ($func =~ m/cblas_[cz]s/) {
push @processed, "if $var != blas.NoTrans && $var != blas.Trans { panic(\"cblas: illegal transpose\") }"; next;
} else {
push @processed, "if $var != blas.NoTrans && $var != blas.Trans && $var != blas.ConjTrans { panic(\"cblas: illegal transpose\") }"; next;
}
};
$var eq "uplo" && do {
push @processed, "if ul != blas.Upper && ul != blas.Lower { panic(\"cblas: illegal triangle\") }"; next;
};
$var eq "diag" && do {
push @processed, "if d != blas.NonUnit && d != blas.Unit { panic(\"cblas: illegal diagonal\") }"; next;
};
$var eq "side" && do {
$scalarArgs{'s'} = 1;
push @processed, "if s != blas.Left && s != blas.Right { panic(\"cblas: illegal side\") }"; next;
};
};
}
# shape checks
foreach my $ref ('m', 'n', 'k', 'kL', 'kU') {
push @processed, "if $ref < 0 { panic(\"cblas: $ref < 0\") }" if $scalarArgs{$ref};
}
if ($arrayArgs{'ap'}) {
push @processed, "if n*(n + 1)/2 > len(ap) { panic(\"cblas: index out of range\") }"
}
if ($func =~ m/cblas_[sdcz]g[eb]mv/) {
push @processed, "if incX <= 0 || incY <= 0 { panic(\"cblas: index out of range\") }";
push @processed, "var lenX, lenY int";
push @processed, "if tA == blas.NoTrans { lenX, lenY = n, m } else { lenX, lenY = m, n }";
push @processed, "if (lenX-1)*incX >= len(x) { panic(\"cblas: index out of range\") }";
push @processed, "if (lenY-1)*incY >= len(y) { panic(\"cblas: index out of range\") }";
} elsif ($scalarArgs{'m'}) {
push @processed, "if incX <= 0 || (m-1)*incX >= len(x) { panic(\"cblas: index out of range\") }" if $scalarArgs{'incX'};
push @processed, "if incY <= 0 || (n-1)*incY >= len(y) { panic(\"cblas: index out of range\") }" if $scalarArgs{'incY'};
} else {
push @processed, "if incX <= 0 || (n-1)*incX >= len(x) { panic(\"cblas: index out of range\") }" if $scalarArgs{'incX'};
push @processed, "if incY <= 0 || (n-1)*incY >= len(y) { panic(\"cblas: index out of range\") }" if $scalarArgs{'incY'};
}
if (not $func =~ m/(?:mm|r2?k)$/) {
if ($arrayArgs{'a'}) {
if ($scalarArgs{'kL'} && $scalarArgs{'kU'}) {
push @processed, "if lda*n > len(a) || lda < kL+kU+1 { panic(\"cblas: index out of range\") }";
} elsif ($scalarArgs{'k'}) {
push @processed, "if lda*n > len(a) || lda < k+1 { panic(\"cblas: index out of range\") }";
} elsif ($scalarArgs{'m'}) {
push @processed, "if lda*n > len(a) || lda < max(1, m) { panic(\"cblas: index out of range\") }";
} else {
push @processed, "if lda*n > len(a) || lda < max(1, n) { panic(\"cblas: index out of range\") }";
}
}
} else {
if ($scalarArgs{'s'}) {
push @processed, "var k int";
push @processed, "if s == blas.Left { k = m } else { k = n }";
push @processed, "if o == blas.RowMajor {";
push @processed, "if lda*n > len(a) || lda < max(1, m) { panic(\"cblas: index out of range\") }";
push @processed, "if ldb*k > len(b) || ldb < max(1, k) { panic(\"cblas: index out of range\") }";
push @processed, "} else {";
push @processed, "if lda*k > len(a) || lda < max(1, k) { panic(\"cblas: index out of range\") }";
push @processed, "if ldb*n > len(b) || ldb < max(1, m) { panic(\"cblas: index out of range\") }";
push @processed, "}";
}
if ($scalarArgs{'t'}) {
push @processed, "var row, col int";
push @processed, "if t == blas.NoTrans { row, col = n, k } else { row, col = k, n }";
push @processed, "if o == blas.RowMajor {";
foreach my $ref ('a', 'b') {
if ($arrayArgs{$ref}) {
push @processed, "if ld${ref}*col > len(${ref}) || ld${ref} < max(1, row) { panic(\"cblas: index out of range\") }";
}
}
push @processed, "} else {";
foreach my $ref ('a', 'b') {
if ($arrayArgs{$ref}) {
push @processed, "if ld${ref}*row > len(${ref}) || ld${ref} < max(1, col) { panic(\"cblas: index out of range\") }";
}
}
push @processed, "}";
}
if ($scalarArgs{'tA'} && $scalarArgs{'tB'}) {
push @processed, "var rowA, colA, rowB, colB int";
push @processed, "if tA == blas.NoTrans { rowA, colA = m, k } else { rowA, colA = k, m }";
push @processed, "if tB == blas.NoTrans { rowB, colB = k, n } else { rowB, colB = n, k }";
push @processed, "if o == blas.RowMajor {";
push @processed, "if lda*rowA > len(a) || lda < max(1, colA) { panic(\"cblas: index out of range\") }";
push @processed, "if ldb*rowB > len(b) || ldb < max(1, colB) { panic(\"cblas: index out of range\") }";
push @processed, "if ldc*m > len(c) || ldc < max(1, n) { panic(\"cblas: index out of range\") }";
push @processed, "} else {";
push @processed, "if lda*colA > len(a) || lda < max(1, rowA) { panic(\"cblas: index out of range\") }";
push @processed, "if ldb*colB > len(b) || ldb < max(1, rowB) { panic(\"cblas: index out of range\") }";
push @processed, "if ldc*n > len(c) || ldc < max(1, m) { panic(\"cblas: index out of range\") }";
push @processed, "}";
}
if ($arrayArgs{'c'} and !($scalarArgs{'tA'} && $scalarArgs{'tB'})) {
if ($scalarArgs{'m'}) {
push @processed, "if ldc*n > len(c) || ldc < max(1, m) { panic(\"cblas: index out of range\") }"
} else {
push @processed, "if ldc*n > len(c) || ldc < max(1, n) { panic(\"cblas: index out of range\") }"
}
}
}
my $checks = join "\n", @processed;
$checks .= "\n" if scalar @processed > 0;
return $checks
}
sub processParamToC {
my $func = shift;
my $paramList = shift;
my @processed;
my @params = split ',', $paramList;
foreach my $param (@params) {
my @parts = split /[ *]/, $param;
my $var = lcfirst $parts[scalar @parts - 1];
$param =~ m/^(?:const )?int \*[a-zA-Z]/ && do {
push @processed, "(*C.int)(&".$var.")"; next;
};
$param =~ m/^(?:const )?void \*[a-zA-Z]/ && do {
my $type;
if ($var eq "alpha" || $var eq "beta") {
$type = "";
} else {
$type = "[0]";
}
push @processed, "unsafe.Pointer(&".$var.$type.")"; next;
};
$param =~ m/^(?:const )?char \*[a-zA-Z]/ && do {
push @processed, "(*C.char)(&".$var.")"; next;
};
$param =~ m/^(?:const )?float \*[a-zA-Z]/ && do {
push @processed, "(*C.float)(&".$var."[0])"; next;
};
$param =~ m/^(?:const )?double \*[a-zA-Z]/ && do {
push @processed, "(*C.double)(&".$var."[0])"; next;
};
$param =~ m/^(?:const )?int [a-zA-Z]/ && do {
push @processed, "C.int(".$var.")"; next;
};
$param =~ m/^(?:const )float [a-zA-Z]/ && do {
push @processed, "C.float(".$var.")"; next;
};
$param =~ m/^(?:const )double [a-zA-Z]/ && do {
push @processed, "C.double(".$var.")"; next;
};
$param =~ m/^const enum [a-zA-Z]/ && do {
$var eq "order" && do {
$var = "o";
push @processed, "C.enum_$parts[scalar @parts - 2](".$var.")"; next;
};
$var =~ /trans/ && do {
$var =~ s/trans([AB]?)/t$1/;
push @processed, "C.enum_$parts[scalar @parts - 2](".$var.")"; next;
};
$var eq "uplo" && do {
$var = "ul";
push @processed, "C.enum_$parts[scalar @parts - 2](".$var.")"; next;
};
$var eq "diag" && do {
$var = "d";
push @processed, "C.enum_$parts[scalar @parts - 2](".$var.")"; next;
};
$var eq "side" && do {
$var = "s";
push @processed, "C.enum_$parts[scalar @parts - 2](".$var.")"; next;
};
};
}
die "missed C parameters from '$func', '$paramList'" if scalar @processed != scalar @params;
return join ", ", @processed;
}