From 4270c62812016c71db82e4d780108bb3b7c0d539 Mon Sep 17 00:00:00 2001 From: Christoph Hertzberg Date: Mon, 15 Apr 2019 17:18:03 +0200 Subject: Split the implementation of i?amax/min into two. Based on PR-627 by Sameer Agarwal. Like the Netlib reference implementation, I*AMAX now uses the L1-norm instead of the L2-norm for each element. Changed I*MIN accordingly. --- blas/level1_cplx_impl.h | 22 ++++++++++++++++++++++ blas/level1_impl.h | 22 ---------------------- blas/level1_real_impl.h | 22 ++++++++++++++++++++++ 3 files changed, 44 insertions(+), 22 deletions(-) (limited to 'blas') diff --git a/blas/level1_cplx_impl.h b/blas/level1_cplx_impl.h index 4ac457175..6c7edd7eb 100644 --- a/blas/level1_cplx_impl.h +++ b/blas/level1_cplx_impl.h @@ -36,6 +36,28 @@ RealScalar EIGEN_CAT(REAL_SCALAR_SUFFIX, EIGEN_BLAS_FUNC(asum))(int *n, RealScal else return make_vector(x,*n,std::abs(*incx)).unaryExpr().sum(); } +int EIGEN_CAT(i, EIGEN_BLAS_FUNC(amax))(int *n, RealScalar *px, int *incx) +{ + if(*n<=0) return 0; + Scalar* x = reinterpret_cast(px); + + DenseIndex ret; + if(*incx==1) make_vector(x,*n).unaryExpr().maxCoeff(&ret); + else make_vector(x,*n,std::abs(*incx)).unaryExpr().maxCoeff(&ret); + return int(ret)+1; +} + +int EIGEN_CAT(i, EIGEN_BLAS_FUNC(amin))(int *n, RealScalar *px, int *incx) +{ + if(*n<=0) return 0; + Scalar* x = reinterpret_cast(px); + + DenseIndex ret; + if(*incx==1) make_vector(x,*n).unaryExpr().minCoeff(&ret); + else make_vector(x,*n,std::abs(*incx)).unaryExpr().minCoeff(&ret); + return int(ret)+1; +} + // computes a dot product of a conjugated vector with another vector. int EIGEN_BLAS_FUNC(dotcw)(int *n, RealScalar *px, int *incx, RealScalar *py, int *incy, RealScalar* pres) { diff --git a/blas/level1_impl.h b/blas/level1_impl.h index d3ee03477..71bd534b7 100644 --- a/blas/level1_impl.h +++ b/blas/level1_impl.h @@ -51,28 +51,6 @@ int EIGEN_BLAS_FUNC(copy)(int *n, RealScalar *px, int *incx, RealScalar *py, int return 0; } -int EIGEN_CAT(i, EIGEN_BLAS_FUNC(amax))(int *n, RealScalar *px, int *incx) -{ - if(*n<=0) return 0; - Scalar* x = reinterpret_cast(px); - - DenseIndex ret; - if(*incx==1) make_vector(x,*n).cwiseAbs().maxCoeff(&ret); - else make_vector(x,*n,std::abs(*incx)).cwiseAbs().maxCoeff(&ret); - return int(ret)+1; -} - -int EIGEN_CAT(i, EIGEN_BLAS_FUNC(amin))(int *n, RealScalar *px, int *incx) -{ - if(*n<=0) return 0; - Scalar* x = reinterpret_cast(px); - - DenseIndex ret; - if(*incx==1) make_vector(x,*n).cwiseAbs().minCoeff(&ret); - else make_vector(x,*n,std::abs(*incx)).cwiseAbs().minCoeff(&ret); - return int(ret)+1; -} - int EIGEN_BLAS_FUNC(rotg)(RealScalar *pa, RealScalar *pb, RealScalar *pc, RealScalar *ps) { using std::sqrt; diff --git a/blas/level1_real_impl.h b/blas/level1_real_impl.h index 02586d519..c58771125 100644 --- a/blas/level1_real_impl.h +++ b/blas/level1_real_impl.h @@ -23,6 +23,28 @@ RealScalar EIGEN_BLAS_FUNC(asum)(int *n, RealScalar *px, int *incx) else return make_vector(x,*n,std::abs(*incx)).cwiseAbs().sum(); } +int EIGEN_CAT(i, EIGEN_BLAS_FUNC(amax))(int *n, RealScalar *px, int *incx) +{ + if(*n<=0) return 0; + Scalar* x = reinterpret_cast(px); + + DenseIndex ret; + if(*incx==1) make_vector(x,*n).cwiseAbs().maxCoeff(&ret); + else make_vector(x,*n,std::abs(*incx)).cwiseAbs().maxCoeff(&ret); + return int(ret)+1; +} + +int EIGEN_CAT(i, EIGEN_BLAS_FUNC(amin))(int *n, RealScalar *px, int *incx) +{ + if(*n<=0) return 0; + Scalar* x = reinterpret_cast(px); + + DenseIndex ret; + if(*incx==1) make_vector(x,*n).cwiseAbs().minCoeff(&ret); + else make_vector(x,*n,std::abs(*incx)).cwiseAbs().minCoeff(&ret); + return int(ret)+1; +} + // computes a vector-vector dot product. Scalar EIGEN_BLAS_FUNC(dot)(int *n, RealScalar *px, int *incx, RealScalar *py, int *incy) { -- cgit v1.2.3