Commit 19a3973bce6e9705a5137787e529abcf024596e2

Authored by David Mayerich
1 parent 33171769

updates to matrix code to support symmetric matrices and tensors

Showing 1 changed file with 22 additions and 0 deletions   Show diff stats
stim/math/matrix.h
... ... @@ -37,6 +37,20 @@ struct matrix
37 37 return *this;
38 38 }
39 39  
  40 + //create a symmetric matrix given the rhs values, given in column-major order
  41 + CUDA_CALLABLE matrix<T, N> setsym(T rhs[(N*N+N)/2]){
  42 + const size_t L = (N*N+N)/2; //store the number of values
  43 +
  44 + size_t r, c;
  45 + r = c = 0;
  46 + for(size_t i = 0; i < L; i++){ //for each value
  47 + if(r == c) M[c * n + r] = rhs[i];
  48 + else M[c*n + r] = M[r * N + c] = rhs[i];
  49 + r++;
  50 + if(r == N) r = ++c;
  51 + }
  52 + }
  53 +
40 54 CUDA_CALLABLE T& operator()(int row, int col)
41 55 {
42 56 return M[col * N + row];
... ... @@ -91,6 +105,14 @@ struct matrix
91 105  
92 106 return ss.str();
93 107 }
  108 +
  109 + static matrix<T, N> identity() {
  110 + matrix<T, N> I;
  111 + I = 0;
  112 + for (size_t i = 0; i < N; i++)
  113 + I.M[i * N + i] = 1;
  114 + return I;
  115 + }
94 116 };
95 117  
96 118 } //end namespace rts
... ...