57729e5b
David Mayerich
changed directory...
|
1
2
3
4
5
6
|
#ifndef RTS_MATRIX_H
#define RTS_MATRIX_H
//#include "rts/vector.h"
#include <string.h>
#include <iostream>
|
a9275be5
David Mayerich
added vector fiel...
|
7
|
#include "vector.h"
|
d609550e
David Mayerich
fixed bug in plan...
|
8
|
#include "../cuda/callable.h"
|
57729e5b
David Mayerich
changed directory...
|
9
|
|
8a86bd56
David Mayerich
changed rts names...
|
10
|
namespace stim{
|
57729e5b
David Mayerich
changed directory...
|
11
12
13
14
15
16
17
|
template <class T, int N>
struct matrix
{
//the matrix will be stored in column-major order (compatible with OpenGL)
T M[N*N];
|
d609550e
David Mayerich
fixed bug in plan...
|
18
|
CUDA_CALLABLE matrix()
|
57729e5b
David Mayerich
changed directory...
|
19
20
21
22
23
24
25
26
27
|
{
for(int r=0; r<N; r++)
for(int c=0; c<N; c++)
if(r == c)
(*this)(r, c) = 1;
else
(*this)(r, c) = 0;
}
|
d609550e
David Mayerich
fixed bug in plan...
|
28
|
CUDA_CALLABLE T& operator()(int row, int col)
|
57729e5b
David Mayerich
changed directory...
|
29
30
31
32
|
{
return M[col * N + row];
}
|
d609550e
David Mayerich
fixed bug in plan...
|
33
|
CUDA_CALLABLE matrix<T, N> operator=(T rhs)
|
57729e5b
David Mayerich
changed directory...
|
34
35
36
37
38
39
40
41
|
{
int Nsq = N*N;
for(int i=0; i<Nsq; i++)
M[i] = rhs;
return *this;
}
|
ecfd14df
David Mayerich
implemented D fie...
|
42
43
|
template<typename Y>
CUDA_CALLABLE vec<Y, N> operator*(vec<Y, N> rhs)
|
57729e5b
David Mayerich
changed directory...
|
44
|
{
|
ecfd14df
David Mayerich
implemented D fie...
|
45
|
vec<Y, N> result;
|
57729e5b
David Mayerich
changed directory...
|
46
47
48
49
50
51
52
53
|
for(int r=0; r<N; r++)
for(int c=0; c<N; c++)
result[r] += (*this)(r, c) * rhs[c];
return result;
}
|
d609550e
David Mayerich
fixed bug in plan...
|
54
|
CUDA_CALLABLE std::string toStr()
|
57729e5b
David Mayerich
changed directory...
|
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
{
std::stringstream ss;
for(int r = 0; r < N; r++)
{
ss<<"| ";
for(int c=0; c<N; c++)
{
ss<<(*this)(r, c)<<" ";
}
ss<<"|"<<std::endl;
}
return ss.str();
}
};
} //end namespace rts
template <typename T, int N>
|
ef70330e
David Mayerich
changed rts to stim
|
79
|
std::ostream& operator<<(std::ostream& os, stim::matrix<T, N> M)
|
57729e5b
David Mayerich
changed directory...
|
80
81
82
83
84
85
86
87
88
89
|
{
os<<M.toStr();
return os;
}
//#if __GNUC__ > 3 && __GNUC_MINOR__ > 7
//template<class T, int N> using rtsMatrix = rts::matrix<T, N>;
//#endif
#endif
|