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