kusano 2b45e8
/*
kusano 2b45e8
 *     Written by D.P. Manley, Digital Equipment Corporation.
kusano 2b45e8
 *     Prefixed "C_" to BLAS routines and their declarations.
kusano 2b45e8
 *
kusano 2b45e8
 *     Modified by T. H. Do, 2/19/98, SGI/CRAY Research.
kusano 2b45e8
 */
kusano 2b45e8
#include <stdio.h></stdio.h>
kusano 2b45e8
#include <stdlib.h></stdlib.h>
kusano 2b45e8
#include "common.h"
kusano 2b45e8
#include "cblas_test.h"
kusano 2b45e8
kusano 2b45e8
void F77_sgemm(int *order, char *transpa, char *transpb, int *m, int *n, 
kusano 2b45e8
              int *k, float *alpha, float *a, int *lda, float *b, int *ldb,
kusano 2b45e8
              float *beta, float *c, int *ldc ) {
kusano 2b45e8
kusano 2b45e8
  float *A, *B, *C;
kusano 2b45e8
  int i,j,LDA, LDB, LDC;
kusano 2b45e8
  enum CBLAS_TRANSPOSE transa, transb;
kusano 2b45e8
kusano 2b45e8
  get_transpose_type(transpa, &transa);
kusano 2b45e8
  get_transpose_type(transpb, &transb);
kusano 2b45e8
kusano 2b45e8
  if (*order == TEST_ROW_MJR) {
kusano 2b45e8
     if (transa == CblasNoTrans) {
kusano 2b45e8
        LDA = *k+1;
kusano 2b45e8
        A = (float *)malloc( (*m)*LDA*sizeof( float ) );
kusano 2b45e8
        for( i=0; i<*m; i++ )
kusano 2b45e8
           for( j=0; j<*k; j++ )
kusano 2b45e8
              A[i*LDA+j]=a[j*(*lda)+i];
kusano 2b45e8
     }
kusano 2b45e8
     else {
kusano 2b45e8
        LDA = *m+1;
kusano 2b45e8
        A   = ( float* )malloc( LDA*(*k)*sizeof( float ) );
kusano 2b45e8
        for( i=0; i<*k; i++ )
kusano 2b45e8
           for( j=0; j<*m; j++ )
kusano 2b45e8
              A[i*LDA+j]=a[j*(*lda)+i];
kusano 2b45e8
     }
kusano 2b45e8
     if (transb == CblasNoTrans) {
kusano 2b45e8
        LDB = *n+1;
kusano 2b45e8
        B   = ( float* )malloc( (*k)*LDB*sizeof( float ) );
kusano 2b45e8
        for( i=0; i<*k; i++ )
kusano 2b45e8
           for( j=0; j<*n; j++ )
kusano 2b45e8
              B[i*LDB+j]=b[j*(*ldb)+i];
kusano 2b45e8
     }
kusano 2b45e8
     else {
kusano 2b45e8
        LDB = *k+1;
kusano 2b45e8
        B   = ( float* )malloc( LDB*(*n)*sizeof( float ) );
kusano 2b45e8
        for( i=0; i<*n; i++ )
kusano 2b45e8
           for( j=0; j<*k; j++ )
kusano 2b45e8
              B[i*LDB+j]=b[j*(*ldb)+i];
kusano 2b45e8
     }
kusano 2b45e8
     LDC = *n+1;
kusano 2b45e8
     C   = ( float* )malloc( (*m)*LDC*sizeof( float ) );
kusano 2b45e8
     for( j=0; j<*n; j++ )
kusano 2b45e8
        for( i=0; i<*m; i++ )
kusano 2b45e8
           C[i*LDC+j]=c[j*(*ldc)+i];
kusano 2b45e8
     cblas_sgemm( CblasRowMajor, transa, transb, *m, *n, *k, *alpha, A, LDA,
kusano 2b45e8
                  B, LDB, *beta, C, LDC );
kusano 2b45e8
     for( j=0; j<*n; j++ )
kusano 2b45e8
        for( i=0; i<*m; i++ )
kusano 2b45e8
           c[j*(*ldc)+i]=C[i*LDC+j];
kusano 2b45e8
     free(A);
kusano 2b45e8
     free(B);
kusano 2b45e8
     free(C);
kusano 2b45e8
  }
kusano 2b45e8
  else if (*order == TEST_COL_MJR)
kusano 2b45e8
     cblas_sgemm( CblasColMajor, transa, transb, *m, *n, *k, *alpha, a, *lda,
kusano 2b45e8
                  b, *ldb, *beta, c, *ldc );
kusano 2b45e8
  else
kusano 2b45e8
     cblas_sgemm( UNDEFINED, transa, transb, *m, *n, *k, *alpha, a, *lda,
kusano 2b45e8
                  b, *ldb, *beta, c, *ldc );
kusano 2b45e8
}
kusano 2b45e8
void F77_ssymm(int *order, char *rtlf, char *uplow, int *m, int *n,
kusano 2b45e8
              float *alpha, float *a, int *lda, float *b, int *ldb,
kusano 2b45e8
              float *beta, float *c, int *ldc ) {
kusano 2b45e8
kusano 2b45e8
  float *A, *B, *C;
kusano 2b45e8
  int i,j,LDA, LDB, LDC;
kusano 2b45e8
  enum CBLAS_UPLO uplo;
kusano 2b45e8
  enum CBLAS_SIDE side;
kusano 2b45e8
kusano 2b45e8
  get_uplo_type(uplow,&uplo);
kusano 2b45e8
  get_side_type(rtlf,&side);
kusano 2b45e8
kusano 2b45e8
  if (*order == TEST_ROW_MJR) {
kusano 2b45e8
     if (side == CblasLeft) {
kusano 2b45e8
        LDA = *m+1;
kusano 2b45e8
        A   = ( float* )malloc( (*m)*LDA*sizeof( float ) );
kusano 2b45e8
        for( i=0; i<*m; i++ )
kusano 2b45e8
           for( j=0; j<*m; j++ )
kusano 2b45e8
              A[i*LDA+j]=a[j*(*lda)+i];
kusano 2b45e8
     }
kusano 2b45e8
     else{
kusano 2b45e8
        LDA = *n+1;
kusano 2b45e8
        A   = ( float* )malloc( (*n)*LDA*sizeof( float ) );
kusano 2b45e8
        for( i=0; i<*n; i++ )
kusano 2b45e8
           for( j=0; j<*n; j++ )
kusano 2b45e8
              A[i*LDA+j]=a[j*(*lda)+i];
kusano 2b45e8
     }
kusano 2b45e8
     LDB = *n+1;
kusano 2b45e8
     B   = ( float* )malloc( (*m)*LDB*sizeof( float ) );
kusano 2b45e8
     for( i=0; i<*m; i++ )
kusano 2b45e8
        for( j=0; j<*n; j++ )
kusano 2b45e8
           B[i*LDB+j]=b[j*(*ldb)+i];
kusano 2b45e8
     LDC = *n+1;
kusano 2b45e8
     C   = ( float* )malloc( (*m)*LDC*sizeof( float ) );
kusano 2b45e8
     for( j=0; j<*n; j++ )
kusano 2b45e8
        for( i=0; i<*m; i++ )
kusano 2b45e8
           C[i*LDC+j]=c[j*(*ldc)+i];
kusano 2b45e8
     cblas_ssymm( CblasRowMajor, side, uplo, *m, *n, *alpha, A, LDA, B, LDB, 
kusano 2b45e8
                  *beta, C, LDC );
kusano 2b45e8
     for( j=0; j<*n; j++ )
kusano 2b45e8
        for( i=0; i<*m; i++ )
kusano 2b45e8
           c[j*(*ldc)+i]=C[i*LDC+j];
kusano 2b45e8
     free(A);
kusano 2b45e8
     free(B);
kusano 2b45e8
     free(C);
kusano 2b45e8
  }
kusano 2b45e8
  else if (*order == TEST_COL_MJR)
kusano 2b45e8
     cblas_ssymm( CblasColMajor, side, uplo, *m, *n, *alpha, a, *lda, b, *ldb, 
kusano 2b45e8
                  *beta, c, *ldc );
kusano 2b45e8
  else
kusano 2b45e8
     cblas_ssymm( UNDEFINED, side, uplo, *m, *n, *alpha, a, *lda, b, *ldb, 
kusano 2b45e8
                  *beta, c, *ldc );
kusano 2b45e8
}
kusano 2b45e8
kusano 2b45e8
void F77_ssyrk(int *order, char *uplow, char *transp, int *n, int *k,
kusano 2b45e8
              float *alpha, float *a, int *lda, 
kusano 2b45e8
              float *beta, float *c, int *ldc ) {
kusano 2b45e8
kusano 2b45e8
  int i,j,LDA,LDC;
kusano 2b45e8
  float *A, *C;
kusano 2b45e8
  enum CBLAS_UPLO uplo;
kusano 2b45e8
  enum CBLAS_TRANSPOSE trans;
kusano 2b45e8
kusano 2b45e8
  get_uplo_type(uplow,&uplo);
kusano 2b45e8
  get_transpose_type(transp,&trans);
kusano 2b45e8
kusano 2b45e8
  if (*order == TEST_ROW_MJR) {
kusano 2b45e8
     if (trans == CblasNoTrans) {
kusano 2b45e8
        LDA = *k+1;
kusano 2b45e8
        A   = ( float* )malloc( (*n)*LDA*sizeof( float ) );
kusano 2b45e8
        for( i=0; i<*n; i++ )
kusano 2b45e8
           for( j=0; j<*k; j++ )
kusano 2b45e8
              A[i*LDA+j]=a[j*(*lda)+i];
kusano 2b45e8
     }
kusano 2b45e8
     else{
kusano 2b45e8
        LDA = *n+1;
kusano 2b45e8
        A   = ( float* )malloc( (*k)*LDA*sizeof( float ) );
kusano 2b45e8
        for( i=0; i<*k; i++ )
kusano 2b45e8
           for( j=0; j<*n; j++ )
kusano 2b45e8
              A[i*LDA+j]=a[j*(*lda)+i];
kusano 2b45e8
     }
kusano 2b45e8
     LDC = *n+1;
kusano 2b45e8
     C   = ( float* )malloc( (*n)*LDC*sizeof( float ) );
kusano 2b45e8
     for( i=0; i<*n; i++ )
kusano 2b45e8
        for( j=0; j<*n; j++ )
kusano 2b45e8
           C[i*LDC+j]=c[j*(*ldc)+i];
kusano 2b45e8
     cblas_ssyrk(CblasRowMajor, uplo, trans, *n, *k, *alpha, A, LDA, *beta, 
kusano 2b45e8
	         C, LDC );
kusano 2b45e8
     for( j=0; j<*n; j++ )
kusano 2b45e8
        for( i=0; i<*n; i++ )
kusano 2b45e8
           c[j*(*ldc)+i]=C[i*LDC+j];
kusano 2b45e8
     free(A);
kusano 2b45e8
     free(C);
kusano 2b45e8
  }
kusano 2b45e8
  else if (*order == TEST_COL_MJR)
kusano 2b45e8
     cblas_ssyrk(CblasColMajor, uplo, trans, *n, *k, *alpha, a, *lda, *beta, 
kusano 2b45e8
	         c, *ldc );
kusano 2b45e8
  else
kusano 2b45e8
     cblas_ssyrk(UNDEFINED, uplo, trans, *n, *k, *alpha, a, *lda, *beta, 
kusano 2b45e8
	         c, *ldc );
kusano 2b45e8
}
kusano 2b45e8
kusano 2b45e8
void F77_ssyr2k(int *order, char *uplow, char *transp, int *n, int *k,
kusano 2b45e8
               float *alpha, float *a, int *lda, float *b, int *ldb,
kusano 2b45e8
               float *beta, float *c, int *ldc ) {
kusano 2b45e8
  int i,j,LDA,LDB,LDC;
kusano 2b45e8
  float *A, *B, *C;
kusano 2b45e8
  enum CBLAS_UPLO uplo;
kusano 2b45e8
  enum CBLAS_TRANSPOSE trans;
kusano 2b45e8
kusano 2b45e8
  get_uplo_type(uplow,&uplo);
kusano 2b45e8
  get_transpose_type(transp,&trans);
kusano 2b45e8
kusano 2b45e8
  if (*order == TEST_ROW_MJR) {
kusano 2b45e8
     if (trans == CblasNoTrans) {
kusano 2b45e8
        LDA = *k+1;
kusano 2b45e8
        LDB = *k+1;
kusano 2b45e8
        A   = ( float* )malloc( (*n)*LDA*sizeof( float ) );
kusano 2b45e8
        B   = ( float* )malloc( (*n)*LDB*sizeof( float ) );
kusano 2b45e8
        for( i=0; i<*n; i++ )
kusano 2b45e8
           for( j=0; j<*k; j++ ) {
kusano 2b45e8
              A[i*LDA+j]=a[j*(*lda)+i];
kusano 2b45e8
              B[i*LDB+j]=b[j*(*ldb)+i];
kusano 2b45e8
           }
kusano 2b45e8
     }
kusano 2b45e8
     else {
kusano 2b45e8
        LDA = *n+1;
kusano 2b45e8
        LDB = *n+1;
kusano 2b45e8
        A   = ( float* )malloc( LDA*(*k)*sizeof( float ) );
kusano 2b45e8
        B   = ( float* )malloc( LDB*(*k)*sizeof( float ) );
kusano 2b45e8
        for( i=0; i<*k; i++ )
kusano 2b45e8
           for( j=0; j<*n; j++ ){
kusano 2b45e8
              A[i*LDA+j]=a[j*(*lda)+i];
kusano 2b45e8
              B[i*LDB+j]=b[j*(*ldb)+i];
kusano 2b45e8
           }
kusano 2b45e8
     }
kusano 2b45e8
     LDC = *n+1;
kusano 2b45e8
     C   = ( float* )malloc( (*n)*LDC*sizeof( float ) );
kusano 2b45e8
     for( i=0; i<*n; i++ )
kusano 2b45e8
        for( j=0; j<*n; j++ )
kusano 2b45e8
           C[i*LDC+j]=c[j*(*ldc)+i];
kusano 2b45e8
     cblas_ssyr2k(CblasRowMajor, uplo, trans, *n, *k, *alpha, A, LDA, 
kusano 2b45e8
		  B, LDB, *beta, C, LDC );
kusano 2b45e8
     for( j=0; j<*n; j++ )
kusano 2b45e8
        for( i=0; i<*n; i++ )
kusano 2b45e8
           c[j*(*ldc)+i]=C[i*LDC+j];
kusano 2b45e8
     free(A);
kusano 2b45e8
     free(B);
kusano 2b45e8
     free(C);
kusano 2b45e8
  }
kusano 2b45e8
  else if (*order == TEST_COL_MJR)
kusano 2b45e8
     cblas_ssyr2k(CblasColMajor, uplo, trans, *n, *k, *alpha, a, *lda, 
kusano 2b45e8
		   b, *ldb, *beta, c, *ldc );
kusano 2b45e8
  else
kusano 2b45e8
     cblas_ssyr2k(UNDEFINED, uplo, trans, *n, *k, *alpha, a, *lda, 
kusano 2b45e8
		   b, *ldb, *beta, c, *ldc );
kusano 2b45e8
}
kusano 2b45e8
void F77_strmm(int *order, char *rtlf, char *uplow, char *transp, char *diagn,
kusano 2b45e8
              int *m, int *n, float *alpha, float *a, int *lda, float *b, 
kusano 2b45e8
              int *ldb) {
kusano 2b45e8
  int i,j,LDA,LDB;
kusano 2b45e8
  float *A, *B;
kusano 2b45e8
  enum CBLAS_SIDE side;
kusano 2b45e8
  enum CBLAS_DIAG diag;
kusano 2b45e8
  enum CBLAS_UPLO uplo;
kusano 2b45e8
  enum CBLAS_TRANSPOSE trans;
kusano 2b45e8
kusano 2b45e8
  get_uplo_type(uplow,&uplo);
kusano 2b45e8
  get_transpose_type(transp,&trans);
kusano 2b45e8
  get_diag_type(diagn,&diag);
kusano 2b45e8
  get_side_type(rtlf,&side);
kusano 2b45e8
kusano 2b45e8
  if (*order == TEST_ROW_MJR) {
kusano 2b45e8
     if (side == CblasLeft) {
kusano 2b45e8
        LDA = *m+1;
kusano 2b45e8
        A   = ( float* )malloc( (*m)*LDA*sizeof( float ) );
kusano 2b45e8
        for( i=0; i<*m; i++ )
kusano 2b45e8
           for( j=0; j<*m; j++ )
kusano 2b45e8
              A[i*LDA+j]=a[j*(*lda)+i];
kusano 2b45e8
     }
kusano 2b45e8
     else{
kusano 2b45e8
        LDA = *n+1;
kusano 2b45e8
        A   = ( float* )malloc( (*n)*LDA*sizeof( float ) );
kusano 2b45e8
        for( i=0; i<*n; i++ )
kusano 2b45e8
           for( j=0; j<*n; j++ )
kusano 2b45e8
              A[i*LDA+j]=a[j*(*lda)+i];
kusano 2b45e8
     }
kusano 2b45e8
     LDB = *n+1;
kusano 2b45e8
     B   = ( float* )malloc( (*m)*LDB*sizeof( float ) );
kusano 2b45e8
     for( i=0; i<*m; i++ )
kusano 2b45e8
        for( j=0; j<*n; j++ )
kusano 2b45e8
           B[i*LDB+j]=b[j*(*ldb)+i];
kusano 2b45e8
     cblas_strmm(CblasRowMajor, side, uplo, trans, diag, *m, *n, *alpha, 
kusano 2b45e8
		 A, LDA, B, LDB );
kusano 2b45e8
     for( j=0; j<*n; j++ )
kusano 2b45e8
        for( i=0; i<*m; i++ )
kusano 2b45e8
           b[j*(*ldb)+i]=B[i*LDB+j];
kusano 2b45e8
     free(A);
kusano 2b45e8
     free(B);
kusano 2b45e8
  }
kusano 2b45e8
  else if (*order == TEST_COL_MJR)
kusano 2b45e8
     cblas_strmm(CblasColMajor, side, uplo, trans, diag, *m, *n, *alpha, 
kusano 2b45e8
		   a, *lda, b, *ldb);
kusano 2b45e8
  else
kusano 2b45e8
     cblas_strmm(UNDEFINED, side, uplo, trans, diag, *m, *n, *alpha, 
kusano 2b45e8
		   a, *lda, b, *ldb);
kusano 2b45e8
}
kusano 2b45e8
kusano 2b45e8
void F77_strsm(int *order, char *rtlf, char *uplow, char *transp, char *diagn,
kusano 2b45e8
              int *m, int *n, float *alpha, float *a, int *lda, float *b,
kusano 2b45e8
              int *ldb) {
kusano 2b45e8
  int i,j,LDA,LDB;
kusano 2b45e8
  float *A, *B;
kusano 2b45e8
  enum CBLAS_SIDE side;
kusano 2b45e8
  enum CBLAS_DIAG diag;
kusano 2b45e8
  enum CBLAS_UPLO uplo;
kusano 2b45e8
  enum CBLAS_TRANSPOSE trans;
kusano 2b45e8
kusano 2b45e8
  get_uplo_type(uplow,&uplo);
kusano 2b45e8
  get_transpose_type(transp,&trans);
kusano 2b45e8
  get_diag_type(diagn,&diag);
kusano 2b45e8
  get_side_type(rtlf,&side);
kusano 2b45e8
kusano 2b45e8
  if (*order == TEST_ROW_MJR) {
kusano 2b45e8
     if (side == CblasLeft) {
kusano 2b45e8
        LDA = *m+1;
kusano 2b45e8
        A   = ( float* )malloc( (*m)*LDA*sizeof( float ) );
kusano 2b45e8
        for( i=0; i<*m; i++ )
kusano 2b45e8
           for( j=0; j<*m; j++ )
kusano 2b45e8
              A[i*LDA+j]=a[j*(*lda)+i];
kusano 2b45e8
     }
kusano 2b45e8
     else{
kusano 2b45e8
        LDA = *n+1;
kusano 2b45e8
        A   = ( float* )malloc( (*n)*LDA*sizeof( float ) );
kusano 2b45e8
        for( i=0; i<*n; i++ )
kusano 2b45e8
           for( j=0; j<*n; j++ )
kusano 2b45e8
              A[i*LDA+j]=a[j*(*lda)+i];
kusano 2b45e8
     }
kusano 2b45e8
     LDB = *n+1;
kusano 2b45e8
     B   = ( float* )malloc( (*m)*LDB*sizeof( float ) );
kusano 2b45e8
     for( i=0; i<*m; i++ )
kusano 2b45e8
        for( j=0; j<*n; j++ )
kusano 2b45e8
           B[i*LDB+j]=b[j*(*ldb)+i];
kusano 2b45e8
     cblas_strsm(CblasRowMajor, side, uplo, trans, diag, *m, *n, *alpha, 
kusano 2b45e8
		 A, LDA, B, LDB );
kusano 2b45e8
     for( j=0; j<*n; j++ )
kusano 2b45e8
        for( i=0; i<*m; i++ )
kusano 2b45e8
           b[j*(*ldb)+i]=B[i*LDB+j];
kusano 2b45e8
     free(A);
kusano 2b45e8
     free(B);
kusano 2b45e8
  }
kusano 2b45e8
  else if (*order == TEST_COL_MJR)
kusano 2b45e8
     cblas_strsm(CblasColMajor, side, uplo, trans, diag, *m, *n, *alpha, 
kusano 2b45e8
		   a, *lda, b, *ldb);
kusano 2b45e8
  else
kusano 2b45e8
     cblas_strsm(UNDEFINED, side, uplo, trans, diag, *m, *n, *alpha, 
kusano 2b45e8
		   a, *lda, b, *ldb);
kusano 2b45e8
}