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.

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