2009-09-25 19:08:39 +08:00
|
|
|
// This file is part of Eigen, a lightweight C++ template library
|
|
|
|
// for linear algebra.
|
|
|
|
//
|
2010-10-09 05:31:57 +08:00
|
|
|
// Copyright (C) 2009-2010 Gael Guennebaud <gael.guennebaud@inria.fr>
|
2009-09-25 19:08:39 +08:00
|
|
|
//
|
|
|
|
// Eigen is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU Lesser General Public
|
|
|
|
// License as published by the Free Software Foundation; either
|
|
|
|
// version 3 of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// Alternatively, you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU General Public License as
|
|
|
|
// published by the Free Software Foundation; either version 2 of
|
|
|
|
// the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
|
|
// FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Lesser General Public
|
|
|
|
// License and a copy of the GNU General Public License along with
|
|
|
|
// Eigen. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
#ifndef EIGEN_BLAS_COMMON_H
|
|
|
|
#define EIGEN_BLAS_COMMON_H
|
|
|
|
|
2010-03-02 02:06:07 +08:00
|
|
|
#include <iostream>
|
2010-07-17 19:49:43 +08:00
|
|
|
#include <complex>
|
2010-03-02 02:06:07 +08:00
|
|
|
|
2009-09-25 19:08:39 +08:00
|
|
|
#ifndef SCALAR
|
|
|
|
#error the token SCALAR must be defined to compile this file
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C"
|
|
|
|
{
|
|
|
|
#endif
|
|
|
|
|
2010-03-02 02:06:07 +08:00
|
|
|
#include "../bench/btl/libs/C_BLAS/blas.h"
|
2009-09-25 19:08:39 +08:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define NOTR 0
|
|
|
|
#define TR 1
|
|
|
|
#define ADJ 2
|
|
|
|
|
|
|
|
#define LEFT 0
|
|
|
|
#define RIGHT 1
|
|
|
|
|
|
|
|
#define UP 0
|
|
|
|
#define LO 1
|
|
|
|
|
|
|
|
#define NUNIT 0
|
|
|
|
#define UNIT 1
|
|
|
|
|
2010-11-04 05:03:12 +08:00
|
|
|
#define INVALID 0xff
|
|
|
|
|
2009-09-25 19:08:39 +08:00
|
|
|
#define OP(X) ( ((X)=='N' || (X)=='n') ? NOTR \
|
|
|
|
: ((X)=='T' || (X)=='t') ? TR \
|
|
|
|
: ((X)=='C' || (X)=='c') ? ADJ \
|
2010-11-04 05:03:12 +08:00
|
|
|
: INVALID)
|
2009-09-25 19:08:39 +08:00
|
|
|
|
|
|
|
#define SIDE(X) ( ((X)=='L' || (X)=='l') ? LEFT \
|
|
|
|
: ((X)=='R' || (X)=='r') ? RIGHT \
|
2010-11-04 05:03:12 +08:00
|
|
|
: INVALID)
|
2009-09-25 19:08:39 +08:00
|
|
|
|
|
|
|
#define UPLO(X) ( ((X)=='U' || (X)=='u') ? UP \
|
|
|
|
: ((X)=='L' || (X)=='l') ? LO \
|
2010-11-04 05:03:12 +08:00
|
|
|
: INVALID)
|
2009-09-25 19:08:39 +08:00
|
|
|
|
|
|
|
#define DIAG(X) ( ((X)=='N' || (X)=='N') ? NUNIT \
|
|
|
|
: ((X)=='U' || (X)=='u') ? UNIT \
|
2010-11-04 05:03:12 +08:00
|
|
|
: INVALID)
|
|
|
|
|
|
|
|
|
|
|
|
inline bool check_op(const char* op)
|
|
|
|
{
|
|
|
|
return OP(*op)!=0xff;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool check_side(const char* side)
|
|
|
|
{
|
|
|
|
return SIDE(*side)!=0xff;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool check_uplo(const char* uplo)
|
|
|
|
{
|
|
|
|
return UPLO(*uplo)!=0xff;
|
|
|
|
}
|
2009-09-25 19:08:39 +08:00
|
|
|
|
|
|
|
#include <Eigen/Core>
|
|
|
|
#include <Eigen/Jacobi>
|
|
|
|
using namespace Eigen;
|
|
|
|
|
2010-03-02 02:06:07 +08:00
|
|
|
typedef SCALAR Scalar;
|
|
|
|
typedef NumTraits<Scalar>::Real RealScalar;
|
|
|
|
typedef std::complex<RealScalar> Complex;
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
IsComplex = Eigen::NumTraits<SCALAR>::IsComplex,
|
|
|
|
Conj = IsComplex
|
|
|
|
};
|
|
|
|
|
2010-07-17 05:30:06 +08:00
|
|
|
typedef Map<Matrix<Scalar,Dynamic,Dynamic,ColMajor>, 0, OuterStride<> > MatrixType;
|
2010-03-02 02:06:07 +08:00
|
|
|
typedef Map<Matrix<Scalar,Dynamic,1>, 0, InnerStride<Dynamic> > StridedVectorType;
|
|
|
|
typedef Map<Matrix<Scalar,Dynamic,1> > CompactVectorType;
|
|
|
|
|
2009-09-25 19:08:39 +08:00
|
|
|
template<typename T>
|
2010-07-17 05:30:06 +08:00
|
|
|
Map<Matrix<T,Dynamic,Dynamic,ColMajor>, 0, OuterStride<> >
|
2009-09-25 19:08:39 +08:00
|
|
|
matrix(T* data, int rows, int cols, int stride)
|
|
|
|
{
|
2010-07-17 05:30:06 +08:00
|
|
|
return Map<Matrix<T,Dynamic,Dynamic,ColMajor>, 0, OuterStride<> >(data, rows, cols, OuterStride<>(stride));
|
2009-09-25 19:08:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T>
|
2010-03-02 02:06:07 +08:00
|
|
|
Map<Matrix<T,Dynamic,1>, 0, InnerStride<Dynamic> > vector(T* data, int size, int incr)
|
2009-09-25 19:08:39 +08:00
|
|
|
{
|
2010-03-02 02:06:07 +08:00
|
|
|
return Map<Matrix<T,Dynamic,1>, 0, InnerStride<Dynamic> >(data, size, InnerStride<Dynamic>(incr));
|
2009-09-25 19:08:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T>
|
2010-03-02 02:06:07 +08:00
|
|
|
Map<Matrix<T,Dynamic,1> > vector(T* data, int size)
|
2009-09-25 19:08:39 +08:00
|
|
|
{
|
|
|
|
return Map<Matrix<T,Dynamic,1> >(data, size);
|
|
|
|
}
|
|
|
|
|
2010-11-19 23:51:52 +08:00
|
|
|
template<typename T>
|
|
|
|
T* get_compact_vector(T* x, int n, int incx)
|
|
|
|
{
|
|
|
|
if(incx==1)
|
|
|
|
return x;
|
2010-11-23 01:49:12 +08:00
|
|
|
|
2010-11-19 23:51:52 +08:00
|
|
|
T* ret = new Scalar[n];
|
|
|
|
if(incx<0) vector(ret,n) = vector(x,n,-incx).reverse();
|
|
|
|
else vector(ret,n) = vector(x,n, incx);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-11-20 00:22:43 +08:00
|
|
|
template<typename T>
|
|
|
|
T* copy_back(T* x_cpy, T* x, int n, int incx)
|
|
|
|
{
|
|
|
|
if(x_cpy==x)
|
|
|
|
return 0;
|
2010-11-23 01:49:12 +08:00
|
|
|
|
2010-11-20 00:22:43 +08:00
|
|
|
if(incx<0) vector(x,n,-incx).reverse() = vector(x_cpy,n);
|
|
|
|
else vector(x,n, incx) = vector(x_cpy,n);
|
|
|
|
return x_cpy;
|
|
|
|
}
|
|
|
|
|
2009-09-25 19:08:39 +08:00
|
|
|
#define EIGEN_BLAS_FUNC(X) EIGEN_CAT(SCALAR_SUFFIX,X##_)
|
|
|
|
|
|
|
|
#endif // EIGEN_BLAS_COMMON_H
|