common.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. // This file is part of Eigen, a lightweight C++ template library
  2. // for linear algebra.
  3. //
  4. // Copyright (C) 2009-2015 Gael Guennebaud <gael.guennebaud@inria.fr>
  5. //
  6. // This Source Code Form is subject to the terms of the Mozilla
  7. // Public License v. 2.0. If a copy of the MPL was not distributed
  8. // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
  9. #ifndef EIGEN_BLAS_COMMON_H
  10. #define EIGEN_BLAS_COMMON_H
  11. #ifdef __GNUC__
  12. # if __GNUC__<5
  13. // GCC < 5.0 does not like the global Scalar typedef
  14. // we just keep shadow-warnings disabled permanently
  15. # define EIGEN_PERMANENTLY_DISABLE_STUPID_WARNINGS
  16. # endif
  17. #endif
  18. #include "../Eigen/Core"
  19. #include "../Eigen/Jacobi"
  20. #include <complex>
  21. #ifndef SCALAR
  22. #error the token SCALAR must be defined to compile this file
  23. #endif
  24. #include "../Eigen/src/misc/blas.h"
  25. #define NOTR 0
  26. #define TR 1
  27. #define ADJ 2
  28. #define LEFT 0
  29. #define RIGHT 1
  30. #define UP 0
  31. #define LO 1
  32. #define NUNIT 0
  33. #define UNIT 1
  34. #define INVALID 0xff
  35. #define OP(X) ( ((X)=='N' || (X)=='n') ? NOTR \
  36. : ((X)=='T' || (X)=='t') ? TR \
  37. : ((X)=='C' || (X)=='c') ? ADJ \
  38. : INVALID)
  39. #define SIDE(X) ( ((X)=='L' || (X)=='l') ? LEFT \
  40. : ((X)=='R' || (X)=='r') ? RIGHT \
  41. : INVALID)
  42. #define UPLO(X) ( ((X)=='U' || (X)=='u') ? UP \
  43. : ((X)=='L' || (X)=='l') ? LO \
  44. : INVALID)
  45. #define DIAG(X) ( ((X)=='N' || (X)=='n') ? NUNIT \
  46. : ((X)=='U' || (X)=='u') ? UNIT \
  47. : INVALID)
  48. inline bool check_op(const char* op)
  49. {
  50. return OP(*op)!=0xff;
  51. }
  52. inline bool check_side(const char* side)
  53. {
  54. return SIDE(*side)!=0xff;
  55. }
  56. inline bool check_uplo(const char* uplo)
  57. {
  58. return UPLO(*uplo)!=0xff;
  59. }
  60. namespace Eigen {
  61. #include "BandTriangularSolver.h"
  62. #include "GeneralRank1Update.h"
  63. #include "PackedSelfadjointProduct.h"
  64. #include "PackedTriangularMatrixVector.h"
  65. #include "PackedTriangularSolverVector.h"
  66. #include "Rank2Update.h"
  67. }
  68. using namespace Eigen;
  69. typedef SCALAR Scalar;
  70. typedef NumTraits<Scalar>::Real RealScalar;
  71. typedef std::complex<RealScalar> Complex;
  72. enum
  73. {
  74. IsComplex = Eigen::NumTraits<SCALAR>::IsComplex,
  75. Conj = IsComplex
  76. };
  77. typedef Matrix<Scalar,Dynamic,Dynamic,ColMajor> PlainMatrixType;
  78. typedef Map<Matrix<Scalar,Dynamic,Dynamic,ColMajor>, 0, OuterStride<> > MatrixType;
  79. typedef Map<const Matrix<Scalar,Dynamic,Dynamic,ColMajor>, 0, OuterStride<> > ConstMatrixType;
  80. typedef Map<Matrix<Scalar,Dynamic,1>, 0, InnerStride<Dynamic> > StridedVectorType;
  81. typedef Map<Matrix<Scalar,Dynamic,1> > CompactVectorType;
  82. template<typename T>
  83. Map<Matrix<T,Dynamic,Dynamic,ColMajor>, 0, OuterStride<> >
  84. matrix(T* data, int rows, int cols, int stride)
  85. {
  86. return Map<Matrix<T,Dynamic,Dynamic,ColMajor>, 0, OuterStride<> >(data, rows, cols, OuterStride<>(stride));
  87. }
  88. template<typename T>
  89. Map<const Matrix<T,Dynamic,Dynamic,ColMajor>, 0, OuterStride<> >
  90. matrix(const T* data, int rows, int cols, int stride)
  91. {
  92. return Map<const Matrix<T,Dynamic,Dynamic,ColMajor>, 0, OuterStride<> >(data, rows, cols, OuterStride<>(stride));
  93. }
  94. template<typename T>
  95. Map<Matrix<T,Dynamic,1>, 0, InnerStride<Dynamic> > make_vector(T* data, int size, int incr)
  96. {
  97. return Map<Matrix<T,Dynamic,1>, 0, InnerStride<Dynamic> >(data, size, InnerStride<Dynamic>(incr));
  98. }
  99. template<typename T>
  100. Map<const Matrix<T,Dynamic,1>, 0, InnerStride<Dynamic> > make_vector(const T* data, int size, int incr)
  101. {
  102. return Map<const Matrix<T,Dynamic,1>, 0, InnerStride<Dynamic> >(data, size, InnerStride<Dynamic>(incr));
  103. }
  104. template<typename T>
  105. Map<Matrix<T,Dynamic,1> > make_vector(T* data, int size)
  106. {
  107. return Map<Matrix<T,Dynamic,1> >(data, size);
  108. }
  109. template<typename T>
  110. Map<const Matrix<T,Dynamic,1> > make_vector(const T* data, int size)
  111. {
  112. return Map<const Matrix<T,Dynamic,1> >(data, size);
  113. }
  114. template<typename T>
  115. T* get_compact_vector(T* x, int n, int incx)
  116. {
  117. if(incx==1)
  118. return x;
  119. typename Eigen::internal::remove_const<T>::type* ret = new Scalar[n];
  120. if(incx<0) make_vector(ret,n) = make_vector(x,n,-incx).reverse();
  121. else make_vector(ret,n) = make_vector(x,n, incx);
  122. return ret;
  123. }
  124. template<typename T>
  125. T* copy_back(T* x_cpy, T* x, int n, int incx)
  126. {
  127. if(x_cpy==x)
  128. return 0;
  129. if(incx<0) make_vector(x,n,-incx).reverse() = make_vector(x_cpy,n);
  130. else make_vector(x,n, incx) = make_vector(x_cpy,n);
  131. return x_cpy;
  132. }
  133. #ifndef EIGEN_BLAS_FUNC_SUFFIX
  134. #define EIGEN_BLAS_FUNC_SUFFIX _
  135. #endif
  136. #define EIGEN_BLAS_FUNC(X) EIGEN_CAT(SCALAR_SUFFIX, EIGEN_CAT(X, EIGEN_BLAS_FUNC_SUFFIX))
  137. #endif // EIGEN_BLAS_COMMON_H