From 19a3973bce6e9705a5137787e529abcf024596e2 Mon Sep 17 00:00:00 2001 From: David Date: Wed, 16 Nov 2016 14:44:00 -0600 Subject: [PATCH] updates to matrix code to support symmetric matrices and tensors --- stim/math/matrix.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+), 0 deletions(-) diff --git a/stim/math/matrix.h b/stim/math/matrix.h index 81d24e9..50a3b42 100644 --- a/stim/math/matrix.h +++ b/stim/math/matrix.h @@ -37,6 +37,20 @@ struct matrix return *this; } + //create a symmetric matrix given the rhs values, given in column-major order + CUDA_CALLABLE matrix setsym(T rhs[(N*N+N)/2]){ + const size_t L = (N*N+N)/2; //store the number of values + + size_t r, c; + r = c = 0; + for(size_t i = 0; i < L; i++){ //for each value + if(r == c) M[c * n + r] = rhs[i]; + else M[c*n + r] = M[r * N + c] = rhs[i]; + r++; + if(r == N) r = ++c; + } + } + CUDA_CALLABLE T& operator()(int row, int col) { return M[col * N + row]; @@ -91,6 +105,14 @@ struct matrix return ss.str(); } + + static matrix identity() { + matrix I; + I = 0; + for (size_t i = 0; i < N; i++) + I.M[i * N + i] = 1; + return I; + } }; } //end namespace rts -- libgit2 0.21.4