-
Notifications
You must be signed in to change notification settings - Fork 6
/
ConfirmedPPolynomial.cuh
93 lines (81 loc) · 2.73 KB
/
ConfirmedPPolynomial.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
//
// Created by davidxu on 22-8-2.
//
#ifndef GPU_POISSONRECON_CONFIRMEDPPOLYNOMIAL_CUH
#define GPU_POISSONRECON_CONFIRMEDPPOLYNOMIAL_CUH
#include "PPolynomial.cuh"
template<int Degree,int PolyCount>
class ConfirmedPPolynomial{
public:
StartingPolynomial<Degree> polys[PolyCount];
__host__ __device__ ConfirmedPPolynomial(void){
for(int i=0;i<PolyCount;++i){
polys[i].start=0;
for(int j=0;j<=Degree;++j){
polys[i].p.coefficients[j]=0;
}
}
}
__host__ __device__ ConfirmedPPolynomial(const ConfirmedPPolynomial& cpy){
for(int i=0;i<PolyCount;++i)
polys[i]=cpy.polys[i];
}
__host__ __device__ ~ConfirmedPPolynomial(void){}
// __host__ __device__ ConfirmedPPolynomial scale(const float& s) const{
// ConfirmedPPolynomial ret;
// for(int i=0;i<PolyCount;++i)
// ret.polys[i]=polys[i].scale(s);
// return ret;
// }
__host__ __device__ ConfirmedPPolynomial shift(const float& t) const{
ConfirmedPPolynomial ret;
for(int i=0;i<PolyCount;++i){
ret.polys[i].start=polys[i].start+t;
for(int k=0;k<=Degree;k++){
float temp=1;
for(int j=k;j>=0;j--){
ret.polys[i].p.coefficients[j]+=polys[i].p.coefficients[k]*temp;
temp*=-t*j;
temp/=(k-j+1);
}
}
}
return ret;
}
__host__ __device__ ConfirmedPPolynomial(const PPolynomial<Degree>& cpy){
int tp=PolyCount<cpy.polyCount?PolyCount:cpy.polyCount;
for(int i=0;i<tp;++i){
polys[i].start=cpy.polys[i].start;
for(int j=0;j<=Degree;j++){
polys[i].p.coefficients[j]=cpy.polys[i].p.coefficients[j];
}
// polys[i]=cpy.polys[i];
}
}
__host__ __device__ ConfirmedPPolynomial& operator =(const PPolynomial<Degree>& cpy){
int tp=PolyCount<cpy.polyCount?PolyCount:cpy.polyCount;
for(int i=0;i<tp;++i){
polys[i].start=cpy.polys[i].start;
for(int j=0;j<=Degree;j++){
polys[i].p.coefficients[j]=cpy.polys[i].p.coefficients[j];
}
// polys[i]=cpy.polys[i];
}
return *this;
}
};
template<int Degree,int PolyCount>
__device__ float value(const ConfirmedPPolynomial<Degree,PolyCount> &cp,const float &val){
float res=0;
for(int i=0;i<PolyCount && val > cp.polys[i].start;++i){
float temp=1;
float v=0;
for(int j=0;j<=Degree;++j){
v+=temp * cp.polys[i].p.coefficients[j];
temp*=val;
}
res+=v;
}
return res;
}
#endif //GPU_POISSONRECON_CONFIRMEDPPOLYNOMIAL_CUH