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
4.1 KiB

  1. //=====================================================
  2. // Copyright (C) 2008 Gael Guennebaud <gael.guennebaud@inria.fr>
  3. //=====================================================
  4. //
  5. // This program is free software; you can redistribute it and/or
  6. // modify it under the terms of the GNU General Public License
  7. // as published by the Free Software Foundation; either version 2
  8. // of the License, or (at your option) any later version.
  9. //
  10. // This program is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. // GNU General Public License for more details.
  14. // You should have received a copy of the GNU General Public License
  15. // along with this program; if not, write to the Free Software
  16. // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  17. //
  18. #ifndef MTL4_INTERFACE_HH
  19. #define MTL4_INTERFACE_HH
  20. #include <boost/numeric/mtl/mtl.hpp>
  21. #include <boost/numeric/mtl/utility/range_generator.hpp>
  22. // #include <boost/numeric/mtl/operation/cholesky.hpp>
  23. #include <vector>
  24. using namespace mtl;
  25. template<class real>
  26. class mtl4_interface {
  27. public :
  28. typedef real real_type ;
  29. typedef std::vector<real> stl_vector;
  30. typedef std::vector<stl_vector > stl_matrix;
  31. typedef mtl::dense2D<real, mtl::matrix::parameters<mtl::tag::col_major> > gene_matrix;
  32. typedef mtl::dense_vector<real> gene_vector;
  33. static inline std::string name() { return "mtl4"; }
  34. static void free_matrix(gene_matrix & A, int N){
  35. return ;
  36. }
  37. static void free_vector(gene_vector & B){
  38. return ;
  39. }
  40. static inline void matrix_from_stl(gene_matrix & A, stl_matrix & A_stl){
  41. A.change_dim(A_stl[0].size(), A_stl.size());
  42. for (int j=0; j<A_stl.size() ; j++){
  43. for (int i=0; i<A_stl[j].size() ; i++){
  44. A(i,j) = A_stl[j][i];
  45. }
  46. }
  47. }
  48. static inline void vector_from_stl(gene_vector & B, stl_vector & B_stl){
  49. B.change_dim(B_stl.size());
  50. for (int i=0; i<B_stl.size() ; i++){
  51. B[i] = B_stl[i];
  52. }
  53. }
  54. static inline void vector_to_stl(gene_vector & B, stl_vector & B_stl){
  55. for (int i=0; i<B_stl.size() ; i++){
  56. B_stl[i] = B[i];
  57. }
  58. }
  59. static inline void matrix_to_stl(gene_matrix & A, stl_matrix & A_stl){
  60. int N=A_stl.size();
  61. for (int j=0;j<N;j++){
  62. A_stl[j].resize(N);
  63. for (int i=0;i<N;i++){
  64. A_stl[j][i] = A(i,j);
  65. }
  66. }
  67. }
  68. static inline void matrix_matrix_product(const gene_matrix & A, const gene_matrix & B, gene_matrix & X, int N){
  69. X = (A*B);
  70. // morton_dense<double, doppled_64_row_mask> C(N,N);
  71. // C = B;
  72. // X = (A*C);
  73. }
  74. static inline void transposed_matrix_matrix_product(const gene_matrix & A, const gene_matrix & B, gene_matrix & X, int N){
  75. X = (trans(A)*trans(B));
  76. }
  77. // static inline void ata_product(const gene_matrix & A, gene_matrix & X, int N){
  78. // X = (trans(A)*A);
  79. // }
  80. static inline void aat_product(const gene_matrix & A, gene_matrix & X, int N){
  81. X = (A*trans(A));
  82. }
  83. static inline void matrix_vector_product(gene_matrix & A, gene_vector & B, gene_vector & X, int N){
  84. X = (A*B);
  85. }
  86. static inline void atv_product(gene_matrix & A, gene_vector & B, gene_vector & X, int N){
  87. X = (trans(A)*B);
  88. }
  89. static inline void axpy(const real coef, const gene_vector & X, gene_vector & Y, int N){
  90. Y += coef * X;
  91. }
  92. static inline void axpby(real a, const gene_vector & X, real b, gene_vector & Y, int N){
  93. Y = a*X + b*Y;
  94. }
  95. // static inline void cholesky(const gene_matrix & X, gene_matrix & C, int N){
  96. // C = X;
  97. // recursive_cholesky(C);
  98. // }
  99. // static inline void lu_decomp(const gene_matrix & X, gene_matrix & R, int N){
  100. // R = X;
  101. // std::vector<int> ipvt(N);
  102. // lu_factor(R, ipvt);
  103. // }
  104. static inline void trisolve_lower(const gene_matrix & L, const gene_vector& B, gene_vector & X, int N){
  105. X = lower_trisolve(L, B);
  106. }
  107. static inline void copy_matrix(const gene_matrix & source, gene_matrix & cible, int N){
  108. cible = source;
  109. }
  110. static inline void copy_vector(const gene_vector & source, gene_vector & cible, int N){
  111. cible = source;
  112. }
  113. };
  114. #endif