-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathConfirmedVector.cuh
164 lines (144 loc) · 4.62 KB
/
ConfirmedVector.cuh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
//
// Created by davidxu on 22-8-3.
//
#ifndef GPU_POISSONRECON_CONFIRMEDVECTOR_CUH
#define GPU_POISSONRECON_CONFIRMEDVECTOR_CUH
template<int Size,class T>
class ConfirmedVector
{
public:
__host__ __device__ ConfirmedVector(void){}
__host__ __device__ ConfirmedVector( const ConfirmedVector<Size,T>& V ){
for(int i=0;i<Size;++i){
m_pV[i]=V.m_pV[i];
}
}
__host__ __device__ ConfirmedVector( const T *array){
for(int i=0;i<Size;++i){
m_pV[i]=array[i];
}
}
__host__ __device__ const T& operator () (int i) const{
return m_pV[i];
}
__host__ __device__ T& operator () (int i){
return m_pV[i];
}
__host__ __device__ const T& operator [] (int i) const{
return m_pV[i];
}
__host__ __device__ T& operator [] (int i){
return m_pV[i];
}
/** m_pV[0...m_N-1] are set to zero
* m_N doesn't change */
void SetZero(){
for(int i=0;i<Size;++i){
m_pV[i]=0;
}
}
__host__ __device__ int Dimensions() const{
return Size;
}
__host__ __device__ ConfirmedVector operator * (const T& A) const{
ConfirmedVector ret;
for (int i=0; i<Size; i++)
ret.m_pV[i] = this->m_pV[i] * A;
return ret;
}
__host__ __device__ ConfirmedVector operator / (const T& A) const{
ConfirmedVector ret;
for (int i=0; i<Size; i++)
ret.m_pV[i] = this->m_pV[i] / A;
return ret;
}
/** the same size as *this */
__host__ __device__ ConfirmedVector operator - (const ConfirmedVector& V) const{
ConfirmedVector ret;
for (int i=0; i<Size; i++)
ret.m_pV[i] = m_pV[i] - V.m_pV[i];
return ret;
}
__host__ __device__ ConfirmedVector operator + (const ConfirmedVector& V) const{
ConfirmedVector ret;
for (int i=0; i<Size; i++)
V.m_pV[i] = m_pV[i] + V.m_pV[i];
return ret;
}
__host__ __device__ ConfirmedVector& operator *= (const T& A){
for (int i=0; i<Size; i++)
m_pV[i] *= A;
return *this;
}
__host__ __device__ ConfirmedVector& operator /= (const T& A){
for (int i=0; i<Size; i++)
m_pV[i] /= A;
return *this;
}
__host__ __device__ ConfirmedVector& operator += (const ConfirmedVector& V){
for (int i=0; i<Size; i++)
m_pV[i] += V.m_pV[i];
return *this;
}
__host__ __device__ ConfirmedVector& operator -= (const ConfirmedVector& V){
for (int i=0; i<Size; i++)
m_pV[i] -= V.m_pV[i];
return *this;
}
__host__ __device__ ConfirmedVector& AddScaled(const ConfirmedVector& V,const T& scale){
for (int i=0; i<Size; i++)
m_pV[i] += V.m_pV[i]*scale;
return *this;
}
__host__ __device__ ConfirmedVector& SubtractScaled(const ConfirmedVector& V,const T& scale){
for (int i=0; i<Size; i++)
m_pV[i] -= V.m_pV[i]*scale;
return *this;
}
/** $out will be the same size as V1 */
__host__ __device__ static void Add(const ConfirmedVector& V1,const T& scale1,const ConfirmedVector& V2,const T& scale2,ConfirmedVector& Out){
for (int i=0; i<Size; i++)
Out.m_pV[i]=V1.m_pV[i]*scale1+V2.m_pV[i]*scale2;
}
__host__ __device__ static void Add(const ConfirmedVector& V1,const T& scale1,const ConfirmedVector& V2,ConfirmedVector& Out){
for (int i=0; i<Size; i++)
Out.m_pV[i]=V1.m_pV[i]*scale1+V2.m_pV[i];
}
__host__ __device__ ConfirmedVector operator - () const{
ConfirmedVector ret;
for (int i=0; i<Size; i++)
ret.m_pV[i] = -m_pV[i];
return ret;
}
__host__ __device__ ConfirmedVector& operator = (const ConfirmedVector& V){
for(int i=0;i<Size;++i){
m_pV[i]=V.m_pV[i];
}
return *this;
}
__host__ __device__ T Dot( const ConfirmedVector& V ) const{
T V0 = T(0);
for (int i=0; i<Size; i++)
V0 += m_pV[i]*V.m_pV[i];
return V0;
}
__host__ __device__ T Length() const{
T N = T(0);
for (int i = 0; i<Size; i++)
N += m_pV[i]*m_pV[i];
return sqrt(N);
}
__host__ __device__ T Norm( size_t Ln ) const{
T N = T(0);
for (int i = 0; i<Size; i++)
N += pow(m_pV[i], (T)Ln);
return pow(N, (T)1.0/Ln);
}
__host__ __device__ void Normalize(){
T N = 1.0f/Norm(2);
for (int i = 0; i<Size; i++)
m_pV[i] *= N;
}
T m_pV[Size];
};
#endif //GPU_POISSONRECON_CONFIRMEDVECTOR_CUH