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.

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