Commit 42bb075caa062b5ee0f3556eee84f37733dac5f3

Authored by Jiaming Guo
1 parent 9dc73a42

last changes for tensor-code project. add operator for struct matrix.

Showing 2 changed files with 13 additions and 3 deletions   Show diff stats
stim/math/matrix.h
@@ -64,6 +64,16 @@ struct matrix @@ -64,6 +64,16 @@ struct matrix
64 64
65 return *this; 65 return *this;
66 } 66 }
  67 +
  68 + // M - rhs*I
  69 + CUDA_CALLABLE matrix<T, N> operator-(T rhs)
  70 + {
  71 + for(int i=0; i<N; i++)
  72 + for(int j=0 ; j<N; j++)
  73 + if(i == j)
  74 + M[i*N+j] -= rhs;
  75 + return *this;
  76 + }
67 77
68 template<typename Y> 78 template<typename Y>
69 vec<Y> operator*(vec<Y> rhs){ 79 vec<Y> operator*(vec<Y> rhs){
stim/math/tensor3.h
@@ -80,11 +80,11 @@ namespace stim { @@ -80,11 +80,11 @@ namespace stim {
80 stim::matrix<T, 3> M2 = matrix_sym<T, 3>::mat(); 80 stim::matrix<T, 3> M2 = matrix_sym<T, 3>::mat();
81 stim::matrix<T, 3> M3 = matrix_sym<T, 3>::mat(); // fill a tensor with symmetric values 81 stim::matrix<T, 3> M3 = matrix_sym<T, 3>::mat(); // fill a tensor with symmetric values
82 82
83 - M1.operator_minus(M1, lambda[0]); // M1 = A - lambda[0] * I 83 + M1 = M1 - lambda[0]; // M1 = A - lambda[0] * I
84 84
85 - M2.operator_minus(M2, lambda[1]); // M2 = A - lambda[1] * I 85 + M2 = M2 - lambda[1]; // M2 = A - lambda[1] * I
86 86
87 - M3.operator_minus(M3, lambda[2]); // M3 = A - lambda[2] * I 87 + M3 = M3 - lambda[2]; // M3 = A - lambda[2] * I
88 88
89 T Mod = 0; // module of one column 89 T Mod = 0; // module of one column
90 90