mirror of
https://gitlab.com/libeigen/eigen.git
synced 2026-04-10 11:34:33 +08:00
Clang-format tests, examples, libraries, benchmarks, etc.
This commit is contained in:
committed by
Rasmus Munk Larsen
parent
3252ecc7a4
commit
46e9cdb7fe
@@ -9,39 +9,41 @@
|
||||
|
||||
#include "common.h"
|
||||
|
||||
int EIGEN_BLAS_FUNC(axpy)(const int *n, const RealScalar *palpha, const RealScalar *px, const int *incx, RealScalar *py, const int *incy)
|
||||
{
|
||||
const Scalar* x = reinterpret_cast<const Scalar*>(px);
|
||||
Scalar* y = reinterpret_cast<Scalar*>(py);
|
||||
Scalar alpha = *reinterpret_cast<const Scalar*>(palpha);
|
||||
int EIGEN_BLAS_FUNC(axpy)(const int *n, const RealScalar *palpha, const RealScalar *px, const int *incx, RealScalar *py,
|
||||
const int *incy) {
|
||||
const Scalar *x = reinterpret_cast<const Scalar *>(px);
|
||||
Scalar *y = reinterpret_cast<Scalar *>(py);
|
||||
Scalar alpha = *reinterpret_cast<const Scalar *>(palpha);
|
||||
|
||||
if(*n<=0) return 0;
|
||||
if (*n <= 0) return 0;
|
||||
|
||||
if(*incx==1 && *incy==1) make_vector(y,*n) += alpha * make_vector(x,*n);
|
||||
else if(*incx>0 && *incy>0) make_vector(y,*n,*incy) += alpha * make_vector(x,*n,*incx);
|
||||
else if(*incx>0 && *incy<0) make_vector(y,*n,-*incy).reverse() += alpha * make_vector(x,*n,*incx);
|
||||
else if(*incx<0 && *incy>0) make_vector(y,*n,*incy) += alpha * make_vector(x,*n,-*incx).reverse();
|
||||
else if(*incx<0 && *incy<0) make_vector(y,*n,-*incy).reverse() += alpha * make_vector(x,*n,-*incx).reverse();
|
||||
if (*incx == 1 && *incy == 1)
|
||||
make_vector(y, *n) += alpha * make_vector(x, *n);
|
||||
else if (*incx > 0 && *incy > 0)
|
||||
make_vector(y, *n, *incy) += alpha * make_vector(x, *n, *incx);
|
||||
else if (*incx > 0 && *incy < 0)
|
||||
make_vector(y, *n, -*incy).reverse() += alpha * make_vector(x, *n, *incx);
|
||||
else if (*incx < 0 && *incy > 0)
|
||||
make_vector(y, *n, *incy) += alpha * make_vector(x, *n, -*incx).reverse();
|
||||
else if (*incx < 0 && *incy < 0)
|
||||
make_vector(y, *n, -*incy).reverse() += alpha * make_vector(x, *n, -*incx).reverse();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int EIGEN_BLAS_FUNC(copy)(int *n, RealScalar *px, int *incx, RealScalar *py, int *incy)
|
||||
{
|
||||
if(*n<=0) return 0;
|
||||
int EIGEN_BLAS_FUNC(copy)(int *n, RealScalar *px, int *incx, RealScalar *py, int *incy) {
|
||||
if (*n <= 0) return 0;
|
||||
|
||||
Scalar* x = reinterpret_cast<Scalar*>(px);
|
||||
Scalar* y = reinterpret_cast<Scalar*>(py);
|
||||
Scalar *x = reinterpret_cast<Scalar *>(px);
|
||||
Scalar *y = reinterpret_cast<Scalar *>(py);
|
||||
|
||||
// be careful, *incx==0 is allowed !!
|
||||
if(*incx==1 && *incy==1)
|
||||
make_vector(y,*n) = make_vector(x,*n);
|
||||
else
|
||||
{
|
||||
if(*incx<0) x = x - (*n-1)*(*incx);
|
||||
if(*incy<0) y = y - (*n-1)*(*incy);
|
||||
for(int i=0;i<*n;++i)
|
||||
{
|
||||
if (*incx == 1 && *incy == 1)
|
||||
make_vector(y, *n) = make_vector(x, *n);
|
||||
else {
|
||||
if (*incx < 0) x = x - (*n - 1) * (*incx);
|
||||
if (*incy < 0) y = y - (*n - 1) * (*incy);
|
||||
for (int i = 0; i < *n; ++i) {
|
||||
*y = *x;
|
||||
x += *incx;
|
||||
y += *incy;
|
||||
@@ -51,94 +53,91 @@ int EIGEN_BLAS_FUNC(copy)(int *n, RealScalar *px, int *incx, RealScalar *py, int
|
||||
return 0;
|
||||
}
|
||||
|
||||
int EIGEN_BLAS_FUNC(rotg)(RealScalar *pa, RealScalar *pb, RealScalar *pc, RealScalar *ps)
|
||||
{
|
||||
using std::sqrt;
|
||||
int EIGEN_BLAS_FUNC(rotg)(RealScalar *pa, RealScalar *pb, RealScalar *pc, RealScalar *ps) {
|
||||
using std::abs;
|
||||
using std::sqrt;
|
||||
|
||||
Scalar& a = *reinterpret_cast<Scalar*>(pa);
|
||||
Scalar& b = *reinterpret_cast<Scalar*>(pb);
|
||||
RealScalar* c = pc;
|
||||
Scalar* s = reinterpret_cast<Scalar*>(ps);
|
||||
Scalar &a = *reinterpret_cast<Scalar *>(pa);
|
||||
Scalar &b = *reinterpret_cast<Scalar *>(pb);
|
||||
RealScalar *c = pc;
|
||||
Scalar *s = reinterpret_cast<Scalar *>(ps);
|
||||
|
||||
#if !ISCOMPLEX
|
||||
Scalar r,z;
|
||||
#if !ISCOMPLEX
|
||||
Scalar r, z;
|
||||
Scalar aa = abs(a);
|
||||
Scalar ab = abs(b);
|
||||
if((aa+ab)==Scalar(0))
|
||||
{
|
||||
if ((aa + ab) == Scalar(0)) {
|
||||
*c = 1;
|
||||
*s = 0;
|
||||
r = 0;
|
||||
z = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
r = sqrt(a*a + b*b);
|
||||
Scalar amax = aa>ab ? a : b;
|
||||
r = amax>0 ? r : -r;
|
||||
*c = a/r;
|
||||
*s = b/r;
|
||||
} else {
|
||||
r = sqrt(a * a + b * b);
|
||||
Scalar amax = aa > ab ? a : b;
|
||||
r = amax > 0 ? r : -r;
|
||||
*c = a / r;
|
||||
*s = b / r;
|
||||
z = 1;
|
||||
if (aa > ab) z = *s;
|
||||
if (ab > aa && *c!=RealScalar(0))
|
||||
z = Scalar(1)/ *c;
|
||||
if (ab > aa && *c != RealScalar(0)) z = Scalar(1) / *c;
|
||||
}
|
||||
*pa = r;
|
||||
*pb = z;
|
||||
#else
|
||||
#else
|
||||
Scalar alpha;
|
||||
RealScalar norm,scale;
|
||||
if(abs(a)==RealScalar(0))
|
||||
{
|
||||
RealScalar norm, scale;
|
||||
if (abs(a) == RealScalar(0)) {
|
||||
*c = RealScalar(0);
|
||||
*s = Scalar(1);
|
||||
a = b;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
scale = abs(a) + abs(b);
|
||||
norm = scale*sqrt((numext::abs2(a/scale)) + (numext::abs2(b/scale)));
|
||||
alpha = a/abs(a);
|
||||
*c = abs(a)/norm;
|
||||
*s = alpha*numext::conj(b)/norm;
|
||||
a = alpha*norm;
|
||||
norm = scale * sqrt((numext::abs2(a / scale)) + (numext::abs2(b / scale)));
|
||||
alpha = a / abs(a);
|
||||
*c = abs(a) / norm;
|
||||
*s = alpha * numext::conj(b) / norm;
|
||||
a = alpha * norm;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// JacobiRotation<Scalar> r;
|
||||
// r.makeGivens(a,b);
|
||||
// *c = r.c();
|
||||
// *s = r.s();
|
||||
// JacobiRotation<Scalar> r;
|
||||
// r.makeGivens(a,b);
|
||||
// *c = r.c();
|
||||
// *s = r.s();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int EIGEN_BLAS_FUNC(scal)(int *n, RealScalar *palpha, RealScalar *px, int *incx)
|
||||
{
|
||||
if(*n<=0) return 0;
|
||||
int EIGEN_BLAS_FUNC(scal)(int *n, RealScalar *palpha, RealScalar *px, int *incx) {
|
||||
if (*n <= 0) return 0;
|
||||
|
||||
Scalar* x = reinterpret_cast<Scalar*>(px);
|
||||
Scalar alpha = *reinterpret_cast<Scalar*>(palpha);
|
||||
Scalar *x = reinterpret_cast<Scalar *>(px);
|
||||
Scalar alpha = *reinterpret_cast<Scalar *>(palpha);
|
||||
|
||||
if(*incx==1) make_vector(x,*n) *= alpha;
|
||||
else make_vector(x,*n,std::abs(*incx)) *= alpha;
|
||||
if (*incx == 1)
|
||||
make_vector(x, *n) *= alpha;
|
||||
else
|
||||
make_vector(x, *n, std::abs(*incx)) *= alpha;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int EIGEN_BLAS_FUNC(swap)(int *n, RealScalar *px, int *incx, RealScalar *py, int *incy)
|
||||
{
|
||||
if(*n<=0) return 0;
|
||||
int EIGEN_BLAS_FUNC(swap)(int *n, RealScalar *px, int *incx, RealScalar *py, int *incy) {
|
||||
if (*n <= 0) return 0;
|
||||
|
||||
Scalar* x = reinterpret_cast<Scalar*>(px);
|
||||
Scalar* y = reinterpret_cast<Scalar*>(py);
|
||||
Scalar *x = reinterpret_cast<Scalar *>(px);
|
||||
Scalar *y = reinterpret_cast<Scalar *>(py);
|
||||
|
||||
if(*incx==1 && *incy==1) make_vector(y,*n).swap(make_vector(x,*n));
|
||||
else if(*incx>0 && *incy>0) make_vector(y,*n,*incy).swap(make_vector(x,*n,*incx));
|
||||
else if(*incx>0 && *incy<0) make_vector(y,*n,-*incy).reverse().swap(make_vector(x,*n,*incx));
|
||||
else if(*incx<0 && *incy>0) make_vector(y,*n,*incy).swap(make_vector(x,*n,-*incx).reverse());
|
||||
else if(*incx<0 && *incy<0) make_vector(y,*n,-*incy).reverse().swap(make_vector(x,*n,-*incx).reverse());
|
||||
if (*incx == 1 && *incy == 1)
|
||||
make_vector(y, *n).swap(make_vector(x, *n));
|
||||
else if (*incx > 0 && *incy > 0)
|
||||
make_vector(y, *n, *incy).swap(make_vector(x, *n, *incx));
|
||||
else if (*incx > 0 && *incy < 0)
|
||||
make_vector(y, *n, -*incy).reverse().swap(make_vector(x, *n, *incx));
|
||||
else if (*incx < 0 && *incy > 0)
|
||||
make_vector(y, *n, *incy).swap(make_vector(x, *n, -*incx).reverse());
|
||||
else if (*incx < 0 && *incy < 0)
|
||||
make_vector(y, *n, -*incy).reverse().swap(make_vector(x, *n, -*incx).reverse());
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user