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.9 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 BLAZE_INTERFACE_HH
  19. #define BLAZE_INTERFACE_HH
  20. #include <blaze/Math.h>
  21. #include <blaze/Blaze.h>
  22. // using namespace blaze;
  23. #include <vector>
  24. template<class real>
  25. class blaze_interface {
  26. public :
  27. typedef real real_type ;
  28. typedef std::vector<real> stl_vector;
  29. typedef std::vector<stl_vector > stl_matrix;
  30. typedef blaze::DynamicMatrix<real,blaze::columnMajor> gene_matrix;
  31. typedef blaze::DynamicVector<real> gene_vector;
  32. static inline std::string name() { return "blaze"; }
  33. static void free_matrix(gene_matrix & A, int N){
  34. return ;
  35. }
  36. static void free_vector(gene_vector & B){
  37. return ;
  38. }
  39. static inline void matrix_from_stl(gene_matrix & A, stl_matrix & A_stl){
  40. A.resize(A_stl[0].size(), A_stl.size());
  41. for (int j=0; j<A_stl.size() ; j++){
  42. for (int i=0; i<A_stl[j].size() ; i++){
  43. A(i,j) = A_stl[j][i];
  44. }
  45. }
  46. }
  47. static inline void vector_from_stl(gene_vector & B, stl_vector & B_stl){
  48. B.resize(B_stl.size());
  49. for (int i=0; i<B_stl.size() ; i++){
  50. B[i] = B_stl[i];
  51. }
  52. }
  53. static inline void vector_to_stl(gene_vector & B, stl_vector & B_stl){
  54. for (int i=0; i<B_stl.size() ; i++){
  55. B_stl[i] = B[i];
  56. }
  57. }
  58. static inline void matrix_to_stl(gene_matrix & A, stl_matrix & A_stl){
  59. int N=A_stl.size();
  60. for (int j=0;j<N;j++){
  61. A_stl[j].resize(N);
  62. for (int i=0;i<N;i++){
  63. A_stl[j][i] = A(i,j);
  64. }
  65. }
  66. }
  67. static inline void matrix_matrix_product(const gene_matrix & A, const gene_matrix & B, gene_matrix & X, int N){
  68. X = (A*B);
  69. }
  70. static inline void transposed_matrix_matrix_product(const gene_matrix & A, const gene_matrix & B, gene_matrix & X, int N){
  71. X = (trans(A)*trans(B));
  72. }
  73. static inline void ata_product(const gene_matrix & A, gene_matrix & X, int N){
  74. X = (trans(A)*A);
  75. }
  76. static inline void aat_product(const gene_matrix & A, gene_matrix & X, int N){
  77. X = (A*trans(A));
  78. }
  79. static inline void matrix_vector_product(gene_matrix & A, gene_vector & B, gene_vector & X, int N){
  80. X = (A*B);
  81. }
  82. static inline void atv_product(gene_matrix & A, gene_vector & B, gene_vector & X, int N){
  83. X = (trans(A)*B);
  84. }
  85. static inline void axpy(const real coef, const gene_vector & X, gene_vector & Y, int N){
  86. Y += coef * X;
  87. }
  88. static inline void axpby(real a, const gene_vector & X, real b, gene_vector & Y, int N){
  89. Y = a*X + b*Y;
  90. }
  91. // static inline void cholesky(const gene_matrix & X, gene_matrix & C, int N){
  92. // C = X;
  93. // recursive_cholesky(C);
  94. // }
  95. // static inline void lu_decomp(const gene_matrix & X, gene_matrix & R, int N){
  96. // R = X;
  97. // std::vector<int> ipvt(N);
  98. // lu_factor(R, ipvt);
  99. // }
  100. // static inline void trisolve_lower(const gene_matrix & L, const gene_vector& B, gene_vector & X, int N){
  101. // X = lower_trisolve(L, B);
  102. // }
  103. static inline void copy_matrix(const gene_matrix & source, gene_matrix & cible, int N){
  104. cible = source;
  105. }
  106. static inline void copy_vector(const gene_vector & source, gene_vector & cible, int N){
  107. cible = source;
  108. }
  109. };
  110. #endif