#ifndef STIM_MATRIX_SQ_H #define STIM_MATRIX_SQ_H //#include "rts/vector.h" #include #include #include #include #include namespace stim{ template struct matrix_sq { //the matrix will be stored in column-major order (compatible with OpenGL) T M[N*N]; CUDA_CALLABLE matrix_sq() { for(int r=0; r set(T rhs[N*N]) { memcpy(M, rhs, sizeof(T)*N*N); return *this; } //create a symmetric matrix given the rhs values, given in column-major order CUDA_CALLABLE void 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]; } CUDA_CALLABLE matrix_sq operator=(T rhs) { int Nsq = N*N; for(int i=0; i operator-(T rhs) { for(int i=0; i operator/(T rhs) { for(int i=0; i vec operator*(vec rhs){ unsigned int M = rhs.size(); vec result; result.resize(M); for(int r=0; r CUDA_CALLABLE vec3 operator*(vec3 rhs){ vec3 result; for(int r=0; r<3; r++) for(int c=0; c<3; c++) result[r] += (*this)(r, c) * rhs[c]; return result; } std::string toStr() { std::stringstream ss; for(int r = 0; r < N; r++) { ss << "| "; for(int c=0; c identity() { matrix_sq I; I = 0; for (size_t i = 0; i < N; i++) I.M[i * N + i] = 1; return I; } }; } //end namespace rts template std::ostream& operator<<(std::ostream& os, stim::matrix_sq M) { os< 3 && __GNUC_MINOR__ > 7 //template using rtsMatrix = rts::matrix; //#endif #endif