|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include <stddef.h></stddef.h>
|
|
Toshihiro Shimizu |
890ddd |
#include <stdlib.h></stdlib.h>
|
|
Toshihiro Shimizu |
890ddd |
#include <memory></memory>
|
|
Campbell Barton |
107701 |
#include <cstring></cstring>
|
|
Campbell Barton |
107701 |
|
|
Toshihiro Shimizu |
890ddd |
//blasint may either be common 4 bytes or extended 8 (long)...
|
|
Toshihiro Shimizu |
890ddd |
//Replace this and REBUILD the CBLAS with extended int if needed.
|
|
Toshihiro Shimizu |
890ddd |
typedef int blasint;
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
extern "C" {
|
|
Toshihiro Shimizu |
890ddd |
#include "tlin/cblas.h"
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
#include "tlin/tlin_cblas_wrap.h"
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//========================================================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
LITTLE RESUME OF BLAS NOMENCLATURE
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
Function names behave like:
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
cblas_[Precision][Matrix type][Operation specifier]
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
Precision can be:
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
S - REAL C - COMPLEX
|
|
Toshihiro Shimizu |
890ddd |
D - DOUBLE PRECISION Z - COMPLEX*16 (may not be supported by all machines)
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
In current wrapper implementation only D routines will be adopted.
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
Matrix type can be:
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
GE - GEneral GB - General Band
|
|
Toshihiro Shimizu |
890ddd |
SY - SYmmetric SB - Sym. Band SP - Sym. Packed
|
|
Toshihiro Shimizu |
890ddd |
HE - HErmitian HB - Herm. Band HP - Herm. Packed
|
|
Toshihiro Shimizu |
890ddd |
TR - TRiangular TB - Triang. Band TP - Triang. Packed
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
In current wrapper implementation only GE routines will be adopted.
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
Operation specifier depends on the operation. For example, mm means matrix * matrix, mv matrix * vector, etc..
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//========================================================================================
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void sum(int n, const double *x, double *&y)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
void cblas_daxpy(blasint n, double a, double *x, blasint incx, double *y, blasint incy);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
NOTE:
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
Returns a * x + y. Output is stored in y.
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
incx and incy are the increments in array access - ie x[incx * i] and y[incy * j] values only are
|
|
Toshihiro Shimizu |
890ddd |
considered (=> we'll use 1).
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
double *_x = const_cast<double *="">(x);</double>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
cblas_daxpy(n, 1.0, _x, 1, y, 1);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void tlin::multiply(int rows, int cols, const double *A, const double *x, double *&y)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
/*
|
|
Toshihiro Shimizu |
890ddd |
void cblas_dgemv(enum CBLAS_ORDER order, enum CBLAS_TRANSPOSE trans, blasint m, blasint n,
|
|
Toshihiro Shimizu |
890ddd |
double alpha, double *a, blasint lda, double *x, blasint incx, double beta, double *y, blasint incy);
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
NOTE:
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
Returns alpha*A*x + beta*y. Output is stored in y.
|
|
Toshihiro Shimizu |
890ddd |
*/
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
if (!y) {
|
|
Toshihiro Shimizu |
890ddd |
y = (double *)malloc(rows * sizeof(double));
|
|
Toshihiro Shimizu |
890ddd |
memset(y, 0, rows * sizeof(double));
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
double *_A = const_cast<double *="">(A);</double>
|
|
Toshihiro Shimizu |
890ddd |
double *_x = const_cast<double *="">(x);</double>
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
cblas_dgemv(CblasColMajor, CblasNoTrans, rows, cols, 1.0, _A, rows, _x, 1, 1.0, y, 1);
|
|
Toshihiro Shimizu |
890ddd |
}
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
//---------------------------------------------------------------------------------------------------
|
|
Toshihiro Shimizu |
890ddd |
|
|
Toshihiro Shimizu |
890ddd |
void tlin::multiply(const mat &A, const double *x, double *&y)
|
|
Toshihiro Shimizu |
890ddd |
{
|
|
Toshihiro Shimizu |
890ddd |
multiply(A.rows(), A.cols(), A.values(), x, y);
|
|
Toshihiro Shimizu |
890ddd |
}
|