common.h
Go to the documentation of this file.
00001 // This file is part of Eigen, a lightweight C++ template library
00002 // for linear algebra.
00003 //
00004 // Copyright (C) 2009-2010 Gael Guennebaud <gael.guennebaud@inria.fr>
00005 //
00006 // Eigen is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 3 of the License, or (at your option) any later version.
00010 //
00011 // Alternatively, you can redistribute it and/or
00012 // modify it under the terms of the GNU General Public License as
00013 // published by the Free Software Foundation; either version 2 of
00014 // the License, or (at your option) any later version.
00015 //
00016 // Eigen is distributed in the hope that it will be useful, but WITHOUT ANY
00017 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00018 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License or the
00019 // GNU General Public License for more details.
00020 //
00021 // You should have received a copy of the GNU Lesser General Public
00022 // License and a copy of the GNU General Public License along with
00023 // Eigen. If not, see <http://www.gnu.org/licenses/>.
00024 
00025 #ifndef EIGEN_BLAS_COMMON_H
00026 #define EIGEN_BLAS_COMMON_H
00027 
00028 #include <iostream>
00029 #include <complex>
00030 
00031 #ifndef SCALAR
00032 #error the token SCALAR must be defined to compile this file
00033 #endif
00034 
00035 #ifdef __cplusplus
00036 extern "C"
00037 {
00038 #endif
00039 
00040 #include "../bench/btl/libs/C_BLAS/blas.h"
00041 
00042 #ifdef __cplusplus
00043 }
00044 #endif
00045 
00046 #define NOTR    0
00047 #define TR      1
00048 #define ADJ     2
00049 
00050 #define LEFT    0
00051 #define RIGHT   1
00052 
00053 #define UP      0
00054 #define LO      1
00055 
00056 #define NUNIT   0
00057 #define UNIT    1
00058 
00059 #define INVALID 0xff
00060 
00061 #define OP(X)   (   ((X)=='N' || (X)=='n') ? NOTR   \
00062                   : ((X)=='T' || (X)=='t') ? TR     \
00063                   : ((X)=='C' || (X)=='c') ? ADJ    \
00064                   : INVALID)
00065 
00066 #define SIDE(X) (   ((X)=='L' || (X)=='l') ? LEFT   \
00067                   : ((X)=='R' || (X)=='r') ? RIGHT  \
00068                   : INVALID)
00069 
00070 #define UPLO(X) (   ((X)=='U' || (X)=='u') ? UP     \
00071                   : ((X)=='L' || (X)=='l') ? LO     \
00072                   : INVALID)
00073 
00074 #define DIAG(X) (   ((X)=='N' || (X)=='N') ? NUNIT  \
00075                   : ((X)=='U' || (X)=='u') ? UNIT   \
00076                   : INVALID)
00077 
00078 
00079 inline bool check_op(const char* op)
00080 {
00081   return OP(*op)!=0xff;
00082 }
00083 
00084 inline bool check_side(const char* side)
00085 {
00086   return SIDE(*side)!=0xff;
00087 }
00088 
00089 inline bool check_uplo(const char* uplo)
00090 {
00091   return UPLO(*uplo)!=0xff;
00092 }
00093 
00094 #include <Eigen/Core>
00095 #include <Eigen/Jacobi>
00096 using namespace Eigen;
00097 
00098 typedef SCALAR Scalar;
00099 typedef NumTraits<Scalar>::Real RealScalar;
00100 typedef std::complex<RealScalar> Complex;
00101 
00102 enum
00103 {
00104   IsComplex = Eigen::NumTraits<SCALAR>::IsComplex,
00105   Conj = IsComplex
00106 };
00107 
00108 typedef Matrix<Scalar,Dynamic,Dynamic,ColMajor> PlainMatrixType;
00109 typedef Map<Matrix<Scalar,Dynamic,Dynamic,ColMajor>, 0, OuterStride<> > MatrixType;
00110 typedef Map<Matrix<Scalar,Dynamic,1>, 0, InnerStride<Dynamic> > StridedVectorType;
00111 typedef Map<Matrix<Scalar,Dynamic,1> > CompactVectorType;
00112 
00113 template<typename T>
00114 Map<Matrix<T,Dynamic,Dynamic,ColMajor>, 0, OuterStride<> >
00115 matrix(T* data, int rows, int cols, int stride)
00116 {
00117   return Map<Matrix<T,Dynamic,Dynamic,ColMajor>, 0, OuterStride<> >(data, rows, cols, OuterStride<>(stride));
00118 }
00119 
00120 template<typename T>
00121 Map<Matrix<T,Dynamic,1>, 0, InnerStride<Dynamic> > vector(T* data, int size, int incr)
00122 {
00123   return Map<Matrix<T,Dynamic,1>, 0, InnerStride<Dynamic> >(data, size, InnerStride<Dynamic>(incr));
00124 }
00125 
00126 template<typename T>
00127 Map<Matrix<T,Dynamic,1> > vector(T* data, int size)
00128 {
00129   return Map<Matrix<T,Dynamic,1> >(data, size);
00130 }
00131 
00132 template<typename T>
00133 T* get_compact_vector(T* x, int n, int incx)
00134 {
00135   if(incx==1)
00136     return x;
00137 
00138   T* ret = new Scalar[n];
00139   if(incx<0) vector(ret,n) = vector(x,n,-incx).reverse();
00140   else       vector(ret,n) = vector(x,n, incx);
00141   return ret;
00142 }
00143 
00144 template<typename T>
00145 T* copy_back(T* x_cpy, T* x, int n, int incx)
00146 {
00147   if(x_cpy==x)
00148     return 0;
00149 
00150   if(incx<0) vector(x,n,-incx).reverse() = vector(x_cpy,n);
00151   else       vector(x,n, incx)           = vector(x_cpy,n);
00152   return x_cpy;
00153 }
00154 
00155 #define EIGEN_BLAS_FUNC(X) EIGEN_CAT(SCALAR_SUFFIX,X##_)
00156 
00157 #endif // EIGEN_BLAS_COMMON_H


libicr
Author(s): Robert Krug
autogenerated on Mon Jan 6 2014 11:32:35