pspline 5.0.5 → 5.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +5 -5
- data/README.md +44 -43
- data/Rakefile +6 -6
- data/bin/console +14 -14
- data/bin/setup +8 -8
- data/ext/pspline/basis.cpp +394 -351
- data/ext/pspline/example/exbspline.rb +57 -57
- data/ext/pspline/example/excspline.rb +57 -57
- data/ext/pspline/example/exdspline.rb +55 -55
- data/ext/pspline/example/exfspline.rb +44 -44
- data/ext/pspline/example/exfspline1.rb +40 -40
- data/ext/pspline/example/exfspline2.rb +68 -68
- data/ext/pspline/example/exfspline3.rb +64 -64
- data/ext/pspline/example/exmspline.rb +68 -68
- data/ext/pspline/example/expspline.rb +29 -29
- data/ext/pspline/example/expspline1.rb +29 -29
- data/ext/pspline/example/expspline2.rb +47 -47
- data/ext/pspline/example/exqspline.rb +31 -31
- data/ext/pspline/example/exqspline1.rb +31 -31
- data/ext/pspline/example/exqspline2.rb +50 -50
- data/ext/pspline/example/exqspline3.rb +51 -51
- data/ext/pspline/example/exqspline4.rb +35 -35
- data/ext/pspline/example/exrspline.rb +34 -34
- data/ext/pspline/example/exrspline1.rb +34 -34
- data/ext/pspline/example/exrspline2.rb +44 -44
- data/ext/pspline/example/exsspline.rb +35 -35
- data/ext/pspline/example/exsspline1.rb +35 -35
- data/ext/pspline/example/extspline.rb +54 -54
- data/ext/pspline/extconf.rb +7 -7
- data/ext/pspline/fft.cpp +27 -552
- data/ext/pspline/include/basis/basis.h +145 -137
- data/ext/pspline/include/basis/fft.h +188 -152
- data/ext/pspline/include/basis/fft_complex.h +215 -0
- data/ext/pspline/include/basis/fft_real.h +625 -0
- data/ext/pspline/include/basis/gabs.h +35 -0
- data/ext/pspline/include/basis/marray_class_ext.h +568 -0
- data/ext/pspline/include/basis/marray_ext.h +100 -0
- data/ext/pspline/include/basis/matrix_luc_ext.h +300 -0
- data/ext/pspline/include/basis/matrix_lud_ext.h +298 -0
- data/ext/pspline/include/basis/poly.h +454 -0
- data/ext/pspline/include/basis/poly_array.h +1030 -1568
- data/ext/pspline/include/basis/pspline.h +806 -642
- data/ext/pspline/include/basis/real.h +526 -0
- data/ext/pspline/include/basis/real_inline.h +442 -0
- data/ext/pspline/include/basis/spline.h +83 -0
- data/ext/pspline/include/basis/uspline.h +251 -210
- data/ext/pspline/include/basis/util.h +122 -656
- data/ext/pspline/include/bspline.h +71 -377
- data/ext/pspline/include/bspline_Config.h +8 -2
- data/ext/pspline/include/real_config.h +3 -0
- data/ext/pspline/pspline.cpp +1236 -1038
- data/ext/pspline/real.cpp +1607 -0
- data/ext/pspline/real_const.cpp +585 -0
- data/lib/pspline.rb +71 -71
- data/lib/pspline/version.rb +1 -1
- data/pspline.gemspec +25 -25
- metadata +17 -5
- data/ext/pspline/plotsub.cpp +0 -139
- data/ext/pspline/util.cpp +0 -483
|
@@ -1,210 +1,251 @@
|
|
|
1
|
-
#ifndef
|
|
2
|
-
#define
|
|
3
|
-
|
|
4
|
-
template <typename T = double> struct Func { int jbn, jis; T val; };
|
|
5
|
-
template <typename T = double> struct Bound { int
|
|
6
|
-
template <typename T = double> using Factor = T(*)(T);
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
{
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
{
|
|
19
|
-
|
|
20
|
-
int
|
|
21
|
-
int
|
|
22
|
-
|
|
23
|
-
T
|
|
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
|
-
int
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
int
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
int
|
|
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
|
-
int
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
1
|
+
#ifndef _USPLINE_4_H_INCLUDED_
|
|
2
|
+
#define _USPLINE_4_H_INCLUDED_
|
|
3
|
+
|
|
4
|
+
template <typename T = double> struct Func { int jbn, jis; real<T> val; };
|
|
5
|
+
template <typename T = double> struct Bound { int jbn, pos; real<T> val; };
|
|
6
|
+
template <typename T = double> using Factor = real<T>(*)(const real<T>&);
|
|
7
|
+
template <typename T = double> class FTerm
|
|
8
|
+
{
|
|
9
|
+
int R, N;
|
|
10
|
+
int *pos; T *val;
|
|
11
|
+
public:
|
|
12
|
+
FTerm(int r, int n) : R(r), N(n), pos(new int[r*2]), val(new T[r*(n+1)]) {}
|
|
13
|
+
FTerm(const FTerm&) = delete;
|
|
14
|
+
~FTerm() { delete[] pos; delete[] val; }
|
|
15
|
+
FTerm& operator = (const FTerm&) = delete;
|
|
16
|
+
real<T> operator [] (int i) const { return real<T>((size_t)N, &val[i*(N+1)], 0); }
|
|
17
|
+
int order(int i) const { return pos[i]; }
|
|
18
|
+
int& order(int i) { return pos[i]; }
|
|
19
|
+
int point(int i) const { return pos[i+R]; }
|
|
20
|
+
int& point(int i) { return pos[i+R]; }
|
|
21
|
+
int degree(int i) const { return pos[i+R]; }
|
|
22
|
+
int& degree(int i) { return pos[i+R]; }
|
|
23
|
+
Func<T> operator () (int i) const
|
|
24
|
+
{
|
|
25
|
+
Func<T> result;
|
|
26
|
+
result.jbn = pos[i];
|
|
27
|
+
result.jis = pos[i+R];
|
|
28
|
+
result.val = (*this)[i];
|
|
29
|
+
return result;
|
|
30
|
+
}
|
|
31
|
+
int Atom() const { return N; }
|
|
32
|
+
int Size() const { return R; }
|
|
33
|
+
};
|
|
34
|
+
template <typename T> using FBcon = FTerm<T>;
|
|
35
|
+
|
|
36
|
+
/*******************************************************************************
|
|
37
|
+
uspline<T>{base_spline*[N]}
|
|
38
|
+
*******************************************************************************/
|
|
39
|
+
template <typename T = double> class uspline : base_spline<T>
|
|
40
|
+
{
|
|
41
|
+
|
|
42
|
+
varray<T> *data;
|
|
43
|
+
|
|
44
|
+
// 汎関数線型項
|
|
45
|
+
void hankansu1(const Func<T>& F, varray<T>& hr)
|
|
46
|
+
{
|
|
47
|
+
const varray<T>& q = *this->knots;
|
|
48
|
+
size_t A = q.atom();
|
|
49
|
+
int K = this->rank, J = K - 1;
|
|
50
|
+
int Imax = this->imax;
|
|
51
|
+
varray<T> B((size_t)K, A);
|
|
52
|
+
int ks = this->basic(q[Imax], K, B);
|
|
53
|
+
int kset = ks + J;
|
|
54
|
+
varray<T> ac((size_t)Imax, A); real<T> sum(A);
|
|
55
|
+
for (int i = 0; i < Imax; ++i) {
|
|
56
|
+
for (int j = 0; j < Imax; ++j) ac[j] = T(0.0);
|
|
57
|
+
ac[i] = T(1.0);
|
|
58
|
+
for (int j = 0; j < Imax; ++j)
|
|
59
|
+
ac[j] = (j > 0 ? ac[j-1] : T(0.0)) + ac[j] * (q[j+K] - q[j]) / T(K);
|
|
60
|
+
sum = T(0.0);
|
|
61
|
+
for (int j = ks; j <= kset; ++j)
|
|
62
|
+
sum += ac[j] * B[j - ks];
|
|
63
|
+
hr[i] += F.val * sum;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// 汎関数2乗項
|
|
68
|
+
void hankansu2(const Func<T>& F, marray<T>& hl)
|
|
69
|
+
{
|
|
70
|
+
const varray<T>& q = *this->knots;
|
|
71
|
+
int K = this->rank, J = K - 1;
|
|
72
|
+
int Imax = this->imax;
|
|
73
|
+
T ld[K*2];
|
|
74
|
+
for (int l = 0; l < K*2; ++l) {
|
|
75
|
+
if (l == 0)
|
|
76
|
+
ld[l] = 1.0;
|
|
77
|
+
else
|
|
78
|
+
ld[l] = ld[l-1] * l;
|
|
79
|
+
}
|
|
80
|
+
int jb = F.jbn;
|
|
81
|
+
for (int l = 0; l < Imax; ++l) {
|
|
82
|
+
int ql = l + J;
|
|
83
|
+
real<T> t = q[ql];
|
|
84
|
+
parray<T> fl = this->bases(t, J);
|
|
85
|
+
int ks = fl(0), kset = ks + J;
|
|
86
|
+
for (int i = ks; i <= kset; ++i) {
|
|
87
|
+
for (int j = ks; j <= kset; ++j) {
|
|
88
|
+
for (int r = jb; r < K; ++r) {
|
|
89
|
+
int rb = r - jb;
|
|
90
|
+
real<T> Bik = fl[r][i - ks];
|
|
91
|
+
for (int s = jb; s < K; ++s) {
|
|
92
|
+
int sb = s - jb;
|
|
93
|
+
real<T> Bjk = fl[s][j - ks];
|
|
94
|
+
int lm = rb + sb + 1;
|
|
95
|
+
real<T> Ql = pow(q[ql+1] - q[ql], lm);
|
|
96
|
+
real<T> p = Bik * Bjk * Ql / (ld[rb] * ld[sb] * lm);
|
|
97
|
+
hl[i][j] += F.val * p;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
void gyoretu_ritz(const marray<T>& hl, marray<T>& Bd)
|
|
106
|
+
{
|
|
107
|
+
int Imax = this->imax;
|
|
108
|
+
for (int l = 0; l < Imax; ++l) {
|
|
109
|
+
for (int i = 0; i < Imax; ++i)
|
|
110
|
+
Bd[l][i] = 2.0 * hl[l][i];
|
|
111
|
+
Bd[Imax][l] = -hl[Imax][l];
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
void zyoken(int lcc, int *ibd, const FBcon<T>& Bs, marray<T>& Bd, const varray<T>& Dx, varray<T>& Dy)
|
|
116
|
+
{
|
|
117
|
+
int K = this->rank, J = K - 1;
|
|
118
|
+
int Imax = this->imax;
|
|
119
|
+
size_t A = Dx.atom();
|
|
120
|
+
varray<T> B((size_t)K, A);
|
|
121
|
+
for (int l = 0; l < lcc; l++) {
|
|
122
|
+
real<T> t = Dx[Bs.point(l)];
|
|
123
|
+
int jb = Bs.order(l);
|
|
124
|
+
int ks = this->basic(t, K, B, -jb);
|
|
125
|
+
int kset = ks + J;
|
|
126
|
+
for (int i = 0; i < Imax; i++)
|
|
127
|
+
Bd[ibd[l]][i] = (i < ks || kset < i) ? 0.0 : B[i - ks];
|
|
128
|
+
Dy[ibd[l]] = Bs[l];
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
public:
|
|
133
|
+
|
|
134
|
+
uspline() : data(NULL) {}
|
|
135
|
+
|
|
136
|
+
~uspline() {delete data;}
|
|
137
|
+
|
|
138
|
+
uspline(const FTerm<T>& df, const FBcon<T>& bf, int *lbd, int n, const varray<T>& x, int j, int d = 0)
|
|
139
|
+
: base_spline<T>(n, x, j, d)
|
|
140
|
+
{
|
|
141
|
+
int R = df.Size(), L = bf.Size();
|
|
142
|
+
size_t A = df.Atom();
|
|
143
|
+
int Imax = this->imax;
|
|
144
|
+
auto hl = marray<T>(Imax+1, Imax, A); auto hr = hl[Imax];
|
|
145
|
+
auto Bd = marray<T>(Imax+1, Imax, A); auto Dy = Bd[Imax];
|
|
146
|
+
for (int i = 0; i <= Imax; ++i)
|
|
147
|
+
for (int j = 0; j < Imax; ++j)
|
|
148
|
+
hl[i][j] = T();
|
|
149
|
+
for (int term = 0; term < R; ++term) {
|
|
150
|
+
Func<T> def = df(term);
|
|
151
|
+
if (def.jis == 2)
|
|
152
|
+
hankansu2(def, hl);
|
|
153
|
+
else
|
|
154
|
+
hankansu1(def, hr);
|
|
155
|
+
}
|
|
156
|
+
gyoretu_ritz(hl, Bd);
|
|
157
|
+
zyoken(L, lbd, bf, Bd, x, Dy);
|
|
158
|
+
data = new varray<T>((size_t)Imax, A);
|
|
159
|
+
marray_view<T> B(*Bd, Imax, Imax, A);
|
|
160
|
+
marray_lu_view<T> lu(B);
|
|
161
|
+
lu.solve(Dy, *data);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
real<T> operator [] (const real<T>& t) const { return this->apply(t, *data); }
|
|
165
|
+
|
|
166
|
+
}; // end of uspline;
|
|
167
|
+
|
|
168
|
+
/*******************************************************************************
|
|
169
|
+
nspline<T>{base_spline*[N]}
|
|
170
|
+
*******************************************************************************/
|
|
171
|
+
template <typename T> class nspline : base_spline<T>
|
|
172
|
+
{
|
|
173
|
+
varray<T> *data;
|
|
174
|
+
|
|
175
|
+
// 微分方程式左辺
|
|
176
|
+
void sa_hen(const varray<T>& Dx, const FTerm<T>& F, const Factor<T> *C, marray<T>& Bd)
|
|
177
|
+
{
|
|
178
|
+
int R = F.Size();
|
|
179
|
+
int K = this->rank, J = K - 1;
|
|
180
|
+
size_t A = F.Atom();
|
|
181
|
+
int Imax = this->imax;
|
|
182
|
+
varray<T> B((size_t)K, A);
|
|
183
|
+
for (int l = 0; l < Imax; ++l) {
|
|
184
|
+
real<T> t = Dx[l];
|
|
185
|
+
for (int k = 0; k < R; ++k) {
|
|
186
|
+
real<T> c = C[k](t);
|
|
187
|
+
int jb = F.order(k);
|
|
188
|
+
int ks = this->basic(t, K, B, -jb);
|
|
189
|
+
int kset = ks + J;
|
|
190
|
+
for (int i = 0; i < Imax; ++i)
|
|
191
|
+
Bd[l][i] += c * ((ks <= i && i <= kset) ? B[i - ks] : 0.0);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// 微分方程式右辺
|
|
197
|
+
void u_hen(Factor<T> f, int Imax, const varray<T>& Dx, varray<T>& Dy)
|
|
198
|
+
{
|
|
199
|
+
for (int i = 0; i < Imax; ++i) Dy[i] = f(Dx[i]);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
void zyoken(const FBcon<T>& Bs, int *ibd, marray<T>& Bd, const varray<T>& Dx, varray<T>& Dy)
|
|
203
|
+
{
|
|
204
|
+
int L = Bs.Size();
|
|
205
|
+
int K = this->rank, J = K - 1;
|
|
206
|
+
size_t A = Bs.Atom();
|
|
207
|
+
int Imax = this->imax;
|
|
208
|
+
varray<T> B((size_t)K, A);
|
|
209
|
+
for (int l = 0; l < L; l++) {
|
|
210
|
+
real<T> t = Dx[Bs.point(l)];
|
|
211
|
+
int jb = Bs.order(l);
|
|
212
|
+
int ks = this->basic(t, K, B, -jb);
|
|
213
|
+
int kset = ks + J;
|
|
214
|
+
for (int i = 0; i < Imax; i++)
|
|
215
|
+
Bd[ibd[l]][i] = (i < ks || kset < i) ? 0.0 : B[i - ks];
|
|
216
|
+
Dy[ibd[l]] = Bs[l];
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
public:
|
|
221
|
+
|
|
222
|
+
nspline() : data(NULL) {}
|
|
223
|
+
|
|
224
|
+
~nspline(){ delete data; }
|
|
225
|
+
|
|
226
|
+
nspline(const FTerm<T>& df, const Factor<T> *uf, const FBcon<T>& bf, int *lbd, int n, const varray<T>& x, int j, int d = 0)
|
|
227
|
+
: base_spline<T>(n, x, j, d)
|
|
228
|
+
{
|
|
229
|
+
int R = df.Size();
|
|
230
|
+
size_t A = df.Atom();
|
|
231
|
+
int Imax = this->imax;
|
|
232
|
+
auto Bd = marray<T>(Imax+1, Imax, A); auto Dy = Bd[Imax];
|
|
233
|
+
for (int i = 0; i <= Imax; ++i)
|
|
234
|
+
for (int j = 0; j < Imax; ++j)
|
|
235
|
+
Bd[i][j] = T(0.0);
|
|
236
|
+
sa_hen(x, df, uf, Bd);
|
|
237
|
+
u_hen(uf[R], Imax, x, Dy);
|
|
238
|
+
zyoken(bf, lbd, Bd, x, Dy);
|
|
239
|
+
data = new varray<T>((size_t)Imax, A);
|
|
240
|
+
marray_view<T> B(*Bd, Imax, Imax, A);
|
|
241
|
+
marray_lu_view<T> lu(B);
|
|
242
|
+
lu.solve(Dy, *data);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
real<T> operator [] (const real<T>& t) const { return this->apply(t, *data); }
|
|
246
|
+
|
|
247
|
+
real<T> operator () (const real<T>& t, int Jbn = 0) const { return this->apply(t, *data, Jbn); }
|
|
248
|
+
|
|
249
|
+
}; // end of nspline
|
|
250
|
+
|
|
251
|
+
#endif
|