mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-01-18 14:34:17 +08:00
Improve constness of level2 blas API.
This commit is contained in:
parent
0483430283
commit
91bf925fc1
@ -10,8 +10,8 @@
|
||||
#ifndef EIGEN_BLAS_COMMON_H
|
||||
#define EIGEN_BLAS_COMMON_H
|
||||
|
||||
#include <Eigen/Core>
|
||||
#include <Eigen/Jacobi>
|
||||
#include "../Eigen/Core"
|
||||
#include "../Eigen/Jacobi"
|
||||
|
||||
#include <complex>
|
||||
|
||||
@ -19,8 +19,7 @@
|
||||
#error the token SCALAR must be defined to compile this file
|
||||
#endif
|
||||
|
||||
#include <Eigen/src/misc/blas.h>
|
||||
|
||||
#include "../Eigen/src/misc/blas.h"
|
||||
|
||||
#define NOTR 0
|
||||
#define TR 1
|
||||
@ -94,6 +93,7 @@ enum
|
||||
|
||||
typedef Matrix<Scalar,Dynamic,Dynamic,ColMajor> PlainMatrixType;
|
||||
typedef Map<Matrix<Scalar,Dynamic,Dynamic,ColMajor>, 0, OuterStride<> > MatrixType;
|
||||
typedef Map<const Matrix<Scalar,Dynamic,Dynamic,ColMajor>, 0, OuterStride<> > ConstMatrixType;
|
||||
typedef Map<Matrix<Scalar,Dynamic,1>, 0, InnerStride<Dynamic> > StridedVectorType;
|
||||
typedef Map<Matrix<Scalar,Dynamic,1> > CompactVectorType;
|
||||
|
||||
@ -141,7 +141,7 @@ T* get_compact_vector(T* x, int n, int incx)
|
||||
if(incx==1)
|
||||
return x;
|
||||
|
||||
T* ret = new Scalar[n];
|
||||
typename Eigen::internal::remove_const<T>::type* ret = new Scalar[n];
|
||||
if(incx<0) make_vector(ret,n) = make_vector(x,n,-incx).reverse();
|
||||
else make_vector(ret,n) = make_vector(x,n, incx);
|
||||
return ret;
|
||||
|
@ -9,11 +9,11 @@
|
||||
|
||||
#include "common.h"
|
||||
|
||||
int EIGEN_BLAS_FUNC(axpy)(int *n, RealScalar *palpha, RealScalar *px, int *incx, RealScalar *py, int *incy)
|
||||
int EIGEN_BLAS_FUNC(axpy)(const int *n, const RealScalar *palpha, const RealScalar *px, const int *incx, RealScalar *py, const int *incy)
|
||||
{
|
||||
Scalar* x = reinterpret_cast<Scalar*>(px);
|
||||
const Scalar* x = reinterpret_cast<const Scalar*>(px);
|
||||
Scalar* y = reinterpret_cast<Scalar*>(py);
|
||||
Scalar alpha = *reinterpret_cast<Scalar*>(palpha);
|
||||
Scalar alpha = *reinterpret_cast<const Scalar*>(palpha);
|
||||
|
||||
if(*n<=0) return 0;
|
||||
|
||||
|
@ -16,7 +16,8 @@
|
||||
* where alpha and beta are scalars, x and y are n element vectors and
|
||||
* A is an n by n hermitian matrix.
|
||||
*/
|
||||
int EIGEN_BLAS_FUNC(hemv)(char *uplo, int *n, RealScalar *palpha, RealScalar *pa, int *lda, RealScalar *px, int *incx, RealScalar *pbeta, RealScalar *py, int *incy)
|
||||
int EIGEN_BLAS_FUNC(hemv)(const char *uplo, const int *n, const RealScalar *palpha, const RealScalar *pa, const int *lda,
|
||||
const RealScalar *px, const int *incx, const RealScalar *pbeta, RealScalar *py, const int *incy)
|
||||
{
|
||||
typedef void (*functype)(int, const Scalar*, int, const Scalar*, Scalar*, Scalar);
|
||||
static const functype func[2] = {
|
||||
@ -26,11 +27,11 @@ int EIGEN_BLAS_FUNC(hemv)(char *uplo, int *n, RealScalar *palpha, RealScalar *pa
|
||||
(internal::selfadjoint_matrix_vector_product<Scalar,int,ColMajor,Lower,false,false>::run),
|
||||
};
|
||||
|
||||
Scalar* a = reinterpret_cast<Scalar*>(pa);
|
||||
Scalar* x = reinterpret_cast<Scalar*>(px);
|
||||
const Scalar* a = reinterpret_cast<const Scalar*>(pa);
|
||||
const Scalar* x = reinterpret_cast<const Scalar*>(px);
|
||||
Scalar* y = reinterpret_cast<Scalar*>(py);
|
||||
Scalar alpha = *reinterpret_cast<Scalar*>(palpha);
|
||||
Scalar beta = *reinterpret_cast<Scalar*>(pbeta);
|
||||
Scalar alpha = *reinterpret_cast<const Scalar*>(palpha);
|
||||
Scalar beta = *reinterpret_cast<const Scalar*>(pbeta);
|
||||
|
||||
// check arguments
|
||||
int info = 0;
|
||||
@ -45,7 +46,7 @@ int EIGEN_BLAS_FUNC(hemv)(char *uplo, int *n, RealScalar *palpha, RealScalar *pa
|
||||
if(*n==0)
|
||||
return 1;
|
||||
|
||||
Scalar* actual_x = get_compact_vector(x,*n,*incx);
|
||||
const Scalar* actual_x = get_compact_vector(x,*n,*incx);
|
||||
Scalar* actual_y = get_compact_vector(y,*n,*incy);
|
||||
|
||||
if(beta!=Scalar(1))
|
||||
|
@ -23,7 +23,8 @@ struct general_matrix_vector_product_wrapper
|
||||
}
|
||||
};
|
||||
|
||||
int EIGEN_BLAS_FUNC(gemv)(char *opa, int *m, int *n, RealScalar *palpha, RealScalar *pa, int *lda, RealScalar *pb, int *incb, RealScalar *pbeta, RealScalar *pc, int *incc)
|
||||
int EIGEN_BLAS_FUNC(gemv)(const char *opa, const int *m, const int *n, const RealScalar *palpha,
|
||||
const RealScalar *pa, const int *lda, const RealScalar *pb, const int *incb, const RealScalar *pbeta, RealScalar *pc, const int *incc)
|
||||
{
|
||||
typedef void (*functype)(int, int, const Scalar *, int, const Scalar *, int , Scalar *, int, Scalar);
|
||||
static const functype func[4] = {
|
||||
@ -36,11 +37,11 @@ int EIGEN_BLAS_FUNC(gemv)(char *opa, int *m, int *n, RealScalar *palpha, RealSca
|
||||
0
|
||||
};
|
||||
|
||||
Scalar* a = reinterpret_cast<Scalar*>(pa);
|
||||
Scalar* b = reinterpret_cast<Scalar*>(pb);
|
||||
const Scalar* a = reinterpret_cast<const Scalar*>(pa);
|
||||
const Scalar* b = reinterpret_cast<const Scalar*>(pb);
|
||||
Scalar* c = reinterpret_cast<Scalar*>(pc);
|
||||
Scalar alpha = *reinterpret_cast<Scalar*>(palpha);
|
||||
Scalar beta = *reinterpret_cast<Scalar*>(pbeta);
|
||||
Scalar alpha = *reinterpret_cast<const Scalar*>(palpha);
|
||||
Scalar beta = *reinterpret_cast<const Scalar*>(pbeta);
|
||||
|
||||
// check arguments
|
||||
int info = 0;
|
||||
@ -62,7 +63,7 @@ int EIGEN_BLAS_FUNC(gemv)(char *opa, int *m, int *n, RealScalar *palpha, RealSca
|
||||
if(code!=NOTR)
|
||||
std::swap(actual_m,actual_n);
|
||||
|
||||
Scalar* actual_b = get_compact_vector(b,actual_n,*incb);
|
||||
const Scalar* actual_b = get_compact_vector(b,actual_n,*incb);
|
||||
Scalar* actual_c = get_compact_vector(c,actual_m,*incc);
|
||||
|
||||
if(beta!=Scalar(1))
|
||||
@ -82,7 +83,7 @@ int EIGEN_BLAS_FUNC(gemv)(char *opa, int *m, int *n, RealScalar *palpha, RealSca
|
||||
return 1;
|
||||
}
|
||||
|
||||
int EIGEN_BLAS_FUNC(trsv)(char *uplo, char *opa, char *diag, int *n, RealScalar *pa, int *lda, RealScalar *pb, int *incb)
|
||||
int EIGEN_BLAS_FUNC(trsv)(const char *uplo, const char *opa, const char *diag, const int *n, const RealScalar *pa, const int *lda, RealScalar *pb, const int *incb)
|
||||
{
|
||||
typedef void (*functype)(int, const Scalar *, int, Scalar *);
|
||||
static const functype func[16] = {
|
||||
@ -116,7 +117,7 @@ int EIGEN_BLAS_FUNC(trsv)(char *uplo, char *opa, char *diag, int *n, RealScalar
|
||||
0
|
||||
};
|
||||
|
||||
Scalar* a = reinterpret_cast<Scalar*>(pa);
|
||||
const Scalar* a = reinterpret_cast<const Scalar*>(pa);
|
||||
Scalar* b = reinterpret_cast<Scalar*>(pb);
|
||||
|
||||
int info = 0;
|
||||
@ -141,7 +142,7 @@ int EIGEN_BLAS_FUNC(trsv)(char *uplo, char *opa, char *diag, int *n, RealScalar
|
||||
|
||||
|
||||
|
||||
int EIGEN_BLAS_FUNC(trmv)(char *uplo, char *opa, char *diag, int *n, RealScalar *pa, int *lda, RealScalar *pb, int *incb)
|
||||
int EIGEN_BLAS_FUNC(trmv)(const char *uplo, const char *opa, const char *diag, const int *n, const RealScalar *pa, const int *lda, RealScalar *pb, const int *incb)
|
||||
{
|
||||
typedef void (*functype)(int, int, const Scalar *, int, const Scalar *, int, Scalar *, int, const Scalar&);
|
||||
static const functype func[16] = {
|
||||
@ -175,7 +176,7 @@ int EIGEN_BLAS_FUNC(trmv)(char *uplo, char *opa, char *diag, int *n, RealScalar
|
||||
0
|
||||
};
|
||||
|
||||
Scalar* a = reinterpret_cast<Scalar*>(pa);
|
||||
const Scalar* a = reinterpret_cast<const Scalar*>(pa);
|
||||
Scalar* b = reinterpret_cast<Scalar*>(pb);
|
||||
|
||||
int info = 0;
|
||||
@ -217,11 +218,11 @@ int EIGEN_BLAS_FUNC(trmv)(char *uplo, char *opa, char *diag, int *n, RealScalar
|
||||
int EIGEN_BLAS_FUNC(gbmv)(char *trans, int *m, int *n, int *kl, int *ku, RealScalar *palpha, RealScalar *pa, int *lda,
|
||||
RealScalar *px, int *incx, RealScalar *pbeta, RealScalar *py, int *incy)
|
||||
{
|
||||
Scalar* a = reinterpret_cast<Scalar*>(pa);
|
||||
Scalar* x = reinterpret_cast<Scalar*>(px);
|
||||
const Scalar* a = reinterpret_cast<const Scalar*>(pa);
|
||||
const Scalar* x = reinterpret_cast<const Scalar*>(px);
|
||||
Scalar* y = reinterpret_cast<Scalar*>(py);
|
||||
Scalar alpha = *reinterpret_cast<Scalar*>(palpha);
|
||||
Scalar beta = *reinterpret_cast<Scalar*>(pbeta);
|
||||
Scalar alpha = *reinterpret_cast<const Scalar*>(palpha);
|
||||
Scalar beta = *reinterpret_cast<const Scalar*>(pbeta);
|
||||
int coeff_rows = *kl+*ku+1;
|
||||
|
||||
int info = 0;
|
||||
@ -244,7 +245,7 @@ int EIGEN_BLAS_FUNC(gbmv)(char *trans, int *m, int *n, int *kl, int *ku, RealSca
|
||||
if(OP(*trans)!=NOTR)
|
||||
std::swap(actual_m,actual_n);
|
||||
|
||||
Scalar* actual_x = get_compact_vector(x,actual_n,*incx);
|
||||
const Scalar* actual_x = get_compact_vector(x,actual_n,*incx);
|
||||
Scalar* actual_y = get_compact_vector(y,actual_m,*incy);
|
||||
|
||||
if(beta!=Scalar(1))
|
||||
@ -253,7 +254,7 @@ int EIGEN_BLAS_FUNC(gbmv)(char *trans, int *m, int *n, int *kl, int *ku, RealSca
|
||||
else make_vector(actual_y, actual_m) *= beta;
|
||||
}
|
||||
|
||||
MatrixType mat_coeffs(a,coeff_rows,*n,*lda);
|
||||
ConstMatrixType mat_coeffs(a,coeff_rows,*n,*lda);
|
||||
|
||||
int nb = std::min(*n,(*m)+(*ku));
|
||||
for(int j=0; j<nb; ++j)
|
||||
|
@ -10,7 +10,8 @@
|
||||
#include "common.h"
|
||||
|
||||
// y = alpha*A*x + beta*y
|
||||
int EIGEN_BLAS_FUNC(symv) (char *uplo, int *n, RealScalar *palpha, RealScalar *pa, int *lda, RealScalar *px, int *incx, RealScalar *pbeta, RealScalar *py, int *incy)
|
||||
int EIGEN_BLAS_FUNC(symv) (const char *uplo, const int *n, const RealScalar *palpha, const RealScalar *pa, const int *lda,
|
||||
const RealScalar *px, const int *incx, const RealScalar *pbeta, RealScalar *py, const int *incy)
|
||||
{
|
||||
typedef void (*functype)(int, const Scalar*, int, const Scalar*, Scalar*, Scalar);
|
||||
static const functype func[2] = {
|
||||
@ -20,11 +21,11 @@ int EIGEN_BLAS_FUNC(symv) (char *uplo, int *n, RealScalar *palpha, RealScalar *p
|
||||
(internal::selfadjoint_matrix_vector_product<Scalar,int,ColMajor,Lower,false,false>::run),
|
||||
};
|
||||
|
||||
Scalar* a = reinterpret_cast<Scalar*>(pa);
|
||||
Scalar* x = reinterpret_cast<Scalar*>(px);
|
||||
const Scalar* a = reinterpret_cast<const Scalar*>(pa);
|
||||
const Scalar* x = reinterpret_cast<const Scalar*>(px);
|
||||
Scalar* y = reinterpret_cast<Scalar*>(py);
|
||||
Scalar alpha = *reinterpret_cast<Scalar*>(palpha);
|
||||
Scalar beta = *reinterpret_cast<Scalar*>(pbeta);
|
||||
Scalar alpha = *reinterpret_cast<const Scalar*>(palpha);
|
||||
Scalar beta = *reinterpret_cast<const Scalar*>(pbeta);
|
||||
|
||||
// check arguments
|
||||
int info = 0;
|
||||
@ -39,7 +40,7 @@ int EIGEN_BLAS_FUNC(symv) (char *uplo, int *n, RealScalar *palpha, RealScalar *p
|
||||
if(*n==0)
|
||||
return 0;
|
||||
|
||||
Scalar* actual_x = get_compact_vector(x,*n,*incx);
|
||||
const Scalar* actual_x = get_compact_vector(x,*n,*incx);
|
||||
Scalar* actual_y = get_compact_vector(y,*n,*incy);
|
||||
|
||||
if(beta!=Scalar(1))
|
||||
@ -61,7 +62,7 @@ int EIGEN_BLAS_FUNC(symv) (char *uplo, int *n, RealScalar *palpha, RealScalar *p
|
||||
}
|
||||
|
||||
// C := alpha*x*x' + C
|
||||
int EIGEN_BLAS_FUNC(syr)(char *uplo, int *n, RealScalar *palpha, RealScalar *px, int *incx, RealScalar *pc, int *ldc)
|
||||
int EIGEN_BLAS_FUNC(syr)(const char *uplo, const int *n, const RealScalar *palpha, const RealScalar *px, const int *incx, RealScalar *pc, const int *ldc)
|
||||
{
|
||||
|
||||
typedef void (*functype)(int, Scalar*, int, const Scalar*, const Scalar*, const Scalar&);
|
||||
@ -72,9 +73,9 @@ int EIGEN_BLAS_FUNC(syr)(char *uplo, int *n, RealScalar *palpha, RealScalar *px,
|
||||
(selfadjoint_rank1_update<Scalar,int,ColMajor,Lower,false,Conj>::run),
|
||||
};
|
||||
|
||||
Scalar* x = reinterpret_cast<Scalar*>(px);
|
||||
const Scalar* x = reinterpret_cast<const Scalar*>(px);
|
||||
Scalar* c = reinterpret_cast<Scalar*>(pc);
|
||||
Scalar alpha = *reinterpret_cast<Scalar*>(palpha);
|
||||
Scalar alpha = *reinterpret_cast<const Scalar*>(palpha);
|
||||
|
||||
int info = 0;
|
||||
if(UPLO(*uplo)==INVALID) info = 1;
|
||||
@ -87,7 +88,7 @@ int EIGEN_BLAS_FUNC(syr)(char *uplo, int *n, RealScalar *palpha, RealScalar *px,
|
||||
if(*n==0 || alpha==Scalar(0)) return 1;
|
||||
|
||||
// if the increment is not 1, let's copy it to a temporary vector to enable vectorization
|
||||
Scalar* x_cpy = get_compact_vector(x,*n,*incx);
|
||||
const Scalar* x_cpy = get_compact_vector(x,*n,*incx);
|
||||
|
||||
int code = UPLO(*uplo);
|
||||
if(code>=2 || func[code]==0)
|
||||
@ -101,7 +102,7 @@ int EIGEN_BLAS_FUNC(syr)(char *uplo, int *n, RealScalar *palpha, RealScalar *px,
|
||||
}
|
||||
|
||||
// C := alpha*x*y' + alpha*y*x' + C
|
||||
int EIGEN_BLAS_FUNC(syr2)(char *uplo, int *n, RealScalar *palpha, RealScalar *px, int *incx, RealScalar *py, int *incy, RealScalar *pc, int *ldc)
|
||||
int EIGEN_BLAS_FUNC(syr2)(const char *uplo, const int *n, const RealScalar *palpha, const RealScalar *px, const int *incx, const RealScalar *py, const int *incy, RealScalar *pc, const int *ldc)
|
||||
{
|
||||
typedef void (*functype)(int, Scalar*, int, const Scalar*, const Scalar*, Scalar);
|
||||
static const functype func[2] = {
|
||||
@ -111,10 +112,10 @@ int EIGEN_BLAS_FUNC(syr2)(char *uplo, int *n, RealScalar *palpha, RealScalar *px
|
||||
(internal::rank2_update_selector<Scalar,int,Lower>::run),
|
||||
};
|
||||
|
||||
Scalar* x = reinterpret_cast<Scalar*>(px);
|
||||
Scalar* y = reinterpret_cast<Scalar*>(py);
|
||||
const Scalar* x = reinterpret_cast<const Scalar*>(px);
|
||||
const Scalar* y = reinterpret_cast<const Scalar*>(py);
|
||||
Scalar* c = reinterpret_cast<Scalar*>(pc);
|
||||
Scalar alpha = *reinterpret_cast<Scalar*>(palpha);
|
||||
Scalar alpha = *reinterpret_cast<const Scalar*>(palpha);
|
||||
|
||||
int info = 0;
|
||||
if(UPLO(*uplo)==INVALID) info = 1;
|
||||
@ -128,8 +129,8 @@ int EIGEN_BLAS_FUNC(syr2)(char *uplo, int *n, RealScalar *palpha, RealScalar *px
|
||||
if(alpha==Scalar(0))
|
||||
return 1;
|
||||
|
||||
Scalar* x_cpy = get_compact_vector(x,*n,*incx);
|
||||
Scalar* y_cpy = get_compact_vector(y,*n,*incy);
|
||||
const Scalar* x_cpy = get_compact_vector(x,*n,*incx);
|
||||
const Scalar* y_cpy = get_compact_vector(y,*n,*incy);
|
||||
|
||||
int code = UPLO(*uplo);
|
||||
if(code>=2 || func[code]==0)
|
||||
|
@ -11,6 +11,7 @@
|
||||
#define EIGEN_LAPACK_COMMON_H
|
||||
|
||||
#include "../blas/common.h"
|
||||
#include "../Eigen/src/misc/lapack.h"
|
||||
|
||||
#define EIGEN_LAPACK_FUNC(FUNC,ARGLIST) \
|
||||
extern "C" { int EIGEN_BLAS_FUNC(FUNC) ARGLIST; } \
|
||||
|
Loading…
Reference in New Issue
Block a user