You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

144 lines
3.5 KiB

  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. #include <Eigen/Core>
  12. #include <Eigen/Jacobi>
  13. #include <complex>
  14. #ifndef SCALAR
  15. #error the token SCALAR must be defined to compile this file
  16. #endif
  17. #include <Eigen/src/misc/blas.h>
  18. #define NOTR 0
  19. #define TR 1
  20. #define ADJ 2
  21. #define LEFT 0
  22. #define RIGHT 1
  23. #define UP 0
  24. #define LO 1
  25. #define NUNIT 0
  26. #define UNIT 1
  27. #define INVALID 0xff
  28. #define OP(X) ( ((X)=='N' || (X)=='n') ? NOTR \
  29. : ((X)=='T' || (X)=='t') ? TR \
  30. : ((X)=='C' || (X)=='c') ? ADJ \
  31. : INVALID)
  32. #define SIDE(X) ( ((X)=='L' || (X)=='l') ? LEFT \
  33. : ((X)=='R' || (X)=='r') ? RIGHT \
  34. : INVALID)
  35. #define UPLO(X) ( ((X)=='U' || (X)=='u') ? UP \
  36. : ((X)=='L' || (X)=='l') ? LO \
  37. : INVALID)
  38. #define DIAG(X) ( ((X)=='N' || (X)=='n') ? NUNIT \
  39. : ((X)=='U' || (X)=='u') ? UNIT \
  40. : INVALID)
  41. inline bool check_op(const char* op)
  42. {
  43. return OP(*op)!=0xff;
  44. }
  45. inline bool check_side(const char* side)
  46. {
  47. return SIDE(*side)!=0xff;
  48. }
  49. inline bool check_uplo(const char* uplo)
  50. {
  51. return UPLO(*uplo)!=0xff;
  52. }
  53. namespace Eigen {
  54. #include "BandTriangularSolver.h"
  55. #include "GeneralRank1Update.h"
  56. #include "PackedSelfadjointProduct.h"
  57. #include "PackedTriangularMatrixVector.h"
  58. #include "PackedTriangularSolverVector.h"
  59. #include "Rank2Update.h"
  60. }
  61. using namespace Eigen;
  62. typedef SCALAR Scalar;
  63. typedef NumTraits<Scalar>::Real RealScalar;
  64. typedef std::complex<RealScalar> Complex;
  65. enum
  66. {
  67. IsComplex = Eigen::NumTraits<SCALAR>::IsComplex,
  68. Conj = IsComplex
  69. };
  70. typedef Matrix<Scalar,Dynamic,Dynamic,ColMajor> PlainMatrixType;
  71. typedef Map<Matrix<Scalar,Dynamic,Dynamic,ColMajor>, 0, OuterStride<> > MatrixType;
  72. typedef Map<Matrix<Scalar,Dynamic,1>, 0, InnerStride<Dynamic> > StridedVectorType;
  73. typedef Map<Matrix<Scalar,Dynamic,1> > CompactVectorType;
  74. template<typename T>
  75. Map<Matrix<T,Dynamic,Dynamic,ColMajor>, 0, OuterStride<> >
  76. matrix(T* data, int rows, int cols, int stride)
  77. {
  78. return Map<Matrix<T,Dynamic,Dynamic,ColMajor>, 0, OuterStride<> >(data, rows, cols, OuterStride<>(stride));
  79. }
  80. template<typename T>
  81. Map<Matrix<T,Dynamic,1>, 0, InnerStride<Dynamic> > make_vector(T* data, int size, int incr)
  82. {
  83. return Map<Matrix<T,Dynamic,1>, 0, InnerStride<Dynamic> >(data, size, InnerStride<Dynamic>(incr));
  84. }
  85. template<typename T>
  86. Map<Matrix<T,Dynamic,1> > make_vector(T* data, int size)
  87. {
  88. return Map<Matrix<T,Dynamic,1> >(data, size);
  89. }
  90. template<typename T>
  91. T* get_compact_vector(T* x, int n, int incx)
  92. {
  93. if(incx==1)
  94. return x;
  95. T* ret = new Scalar[n];
  96. if(incx<0) make_vector(ret,n) = make_vector(x,n,-incx).reverse();
  97. else make_vector(ret,n) = make_vector(x,n, incx);
  98. return ret;
  99. }
  100. template<typename T>
  101. T* copy_back(T* x_cpy, T* x, int n, int incx)
  102. {
  103. if(x_cpy==x)
  104. return 0;
  105. if(incx<0) make_vector(x,n,-incx).reverse() = make_vector(x_cpy,n);
  106. else make_vector(x,n, incx) = make_vector(x_cpy,n);
  107. return x_cpy;
  108. }
  109. #define EIGEN_BLAS_FUNC(X) EIGEN_CAT(SCALAR_SUFFIX,X##_)
  110. #endif // EIGEN_BLAS_COMMON_H