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
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 1f7cd8119c7e0de6c4f6a72d40a7a40c170835ec
|
|
4
|
+
data.tar.gz: e8a52f742dc9fb6ead4d2676ebee54f2e12a2cda
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5905c1d7434b3ce52b8502f418ec027f63a02c0f21de53c584dc455b79fdee10db99e64f5597674712c926bd679be88971c308aa3b5aac40fb08efecc77f4378
|
|
7
|
+
data.tar.gz: 03acfcff0d95f0762c69cd4d1a16d0ae6a82d3dd189793bd24f6db6229cfdb8c0082f4b19eebdca608d16ef2c12e8672f3960dc11277057b27e677208667734a
|
data/Gemfile
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
source 'https://rubygems.org'
|
|
2
|
-
|
|
3
|
-
# Specify your gem's dependencies in pspline.gemspec
|
|
4
|
-
gemspec
|
|
5
|
-
gem "rake-compiler"
|
|
1
|
+
source 'https://rubygems.org'
|
|
2
|
+
|
|
3
|
+
# Specify your gem's dependencies in pspline.gemspec
|
|
4
|
+
gemspec
|
|
5
|
+
gem "rake-compiler"
|
data/README.md
CHANGED
|
@@ -1,43 +1,44 @@
|
|
|
1
|
-
# Pspline
|
|
2
|
-
|
|
3
|
-
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/pspline`. To experiment with that code, run `bin/console` for an interactive prompt.
|
|
4
|
-
|
|
5
|
-
## Installation
|
|
6
|
-
|
|
7
|
-
Add this line to your application's Gemfile:
|
|
8
|
-
|
|
9
|
-
```ruby
|
|
10
|
-
gem 'pspline'
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
And then execute:
|
|
14
|
-
|
|
15
|
-
$ bundle
|
|
16
|
-
|
|
17
|
-
Or install it yourself as:
|
|
18
|
-
|
|
19
|
-
$ gem install pspline
|
|
20
|
-
|
|
21
|
-
## Usage
|
|
22
|
-
|
|
23
|
-
See pspline.wiki at https://github.com/vsp2old/pspline .
|
|
24
|
-
|
|
25
|
-
## Revision history
|
|
26
|
-
|
|
27
|
-
5.0.0 Upload for test.
|
|
28
|
-
5.0.1 Upload for test.
|
|
29
|
-
5.0.2 Upload for release.
|
|
30
|
-
5.0.3 Add class PSPLINE::Rfft, class PSPLINE::Cfft.
|
|
31
|
-
5.0.4 Add method line_integral.
|
|
32
|
-
5.0.5 Add Multiple Bspline.
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
1
|
+
# Pspline
|
|
2
|
+
|
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/pspline`. To experiment with that code, run `bin/console` for an interactive prompt.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Add this line to your application's Gemfile:
|
|
8
|
+
|
|
9
|
+
```ruby
|
|
10
|
+
gem 'pspline'
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
And then execute:
|
|
14
|
+
|
|
15
|
+
$ bundle
|
|
16
|
+
|
|
17
|
+
Or install it yourself as:
|
|
18
|
+
|
|
19
|
+
$ gem install pspline
|
|
20
|
+
|
|
21
|
+
## Usage
|
|
22
|
+
|
|
23
|
+
See pspline.wiki at https://github.com/vsp2old/pspline .
|
|
24
|
+
|
|
25
|
+
## Revision history
|
|
26
|
+
|
|
27
|
+
5.0.0 Upload for test.
|
|
28
|
+
5.0.1 Upload for test.
|
|
29
|
+
5.0.2 Upload for release.
|
|
30
|
+
5.0.3 Add class PSPLINE::Rfft, class PSPLINE::Cfft.
|
|
31
|
+
5.0.4 Add method line_integral.
|
|
32
|
+
5.0.5 Add Multiple Bspline.
|
|
33
|
+
5.1.0 4 double precision arithmetic.
|
|
34
|
+
|
|
35
|
+
## Development
|
|
36
|
+
|
|
37
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
|
38
|
+
|
|
39
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
|
40
|
+
|
|
41
|
+
## Contributing
|
|
42
|
+
|
|
43
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/vsp2old/pspline .
|
|
44
|
+
|
data/Rakefile
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
require "bundler/gem_tasks"
|
|
2
|
-
require "rake/extensiontask"
|
|
3
|
-
|
|
4
|
-
Rake::ExtensionTask.new "pspline" do |ext|
|
|
5
|
-
ext.lib_dir = "lib/pspline"
|
|
6
|
-
end
|
|
1
|
+
require "bundler/gem_tasks"
|
|
2
|
+
require "rake/extensiontask"
|
|
3
|
+
|
|
4
|
+
Rake::ExtensionTask.new "pspline" do |ext|
|
|
5
|
+
ext.lib_dir = "lib/pspline"
|
|
6
|
+
end
|
data/bin/console
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
#!/usr/bin/env ruby
|
|
2
|
-
|
|
3
|
-
require "bundler/setup"
|
|
4
|
-
require "pspline"
|
|
5
|
-
|
|
6
|
-
# You can add fixtures and/or initialization code here to make experimenting
|
|
7
|
-
# with your gem easier. You can also use a different console, if you like.
|
|
8
|
-
|
|
9
|
-
# (If you use this, don't forget to add pry to your Gemfile!)
|
|
10
|
-
# require "pry"
|
|
11
|
-
# Pry.start
|
|
12
|
-
|
|
13
|
-
require "irb"
|
|
14
|
-
IRB.start
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require "bundler/setup"
|
|
4
|
+
require "pspline"
|
|
5
|
+
|
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
|
8
|
+
|
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
|
10
|
+
# require "pry"
|
|
11
|
+
# Pry.start
|
|
12
|
+
|
|
13
|
+
require "irb"
|
|
14
|
+
IRB.start
|
data/bin/setup
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
#!/usr/bin/env bash
|
|
2
|
-
set -euo pipefail
|
|
3
|
-
IFS=$'\n\t'
|
|
4
|
-
set -vx
|
|
5
|
-
|
|
6
|
-
bundle install
|
|
7
|
-
|
|
8
|
-
# Do any other automated setup that you need to do here
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
set -euo pipefail
|
|
3
|
+
IFS=$'\n\t'
|
|
4
|
+
set -vx
|
|
5
|
+
|
|
6
|
+
bundle install
|
|
7
|
+
|
|
8
|
+
# Do any other automated setup that you need to do here
|
data/ext/pspline/basis.cpp
CHANGED
|
@@ -1,351 +1,394 @@
|
|
|
1
|
-
#include
|
|
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
|
-
if (
|
|
66
|
-
int j =
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
b[
|
|
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
|
-
if (s
|
|
113
|
-
for (int i = 0; i < m; i++)
|
|
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
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
s
|
|
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
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
{
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
for (int
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
1
|
+
#include "bspline.h"
|
|
2
|
+
|
|
3
|
+
/*******************************************************************************
|
|
4
|
+
de Boor-Cox の漸化式によるB−スプライン関数値の計算
|
|
5
|
+
k: Bスプラインの階数(j+1)
|
|
6
|
+
q: 節点の配列
|
|
7
|
+
c: Bスプラインの基底数
|
|
8
|
+
t: データ点の座標(q[j] <= t <= q[cox])
|
|
9
|
+
d: d > 0 ? スプライン階数 : 微分階数
|
|
10
|
+
*******************************************************************************/
|
|
11
|
+
template <typename P, typename T>
|
|
12
|
+
// P = varray<double>, T = poly<double>;
|
|
13
|
+
int deboor(int k, const P& q, int c, const T& t, P& b, int& kset, int d)
|
|
14
|
+
{
|
|
15
|
+
static const T eps(1.0e-10);
|
|
16
|
+
|
|
17
|
+
int h = c-1, i = k-1, j, K = d > 0 ? d : k, L = k + d;
|
|
18
|
+
|
|
19
|
+
while (i < h) { if(q[i] <= t && t < q[i+1]) break; i++; }
|
|
20
|
+
kset = i; if (q[h] <= t && t < q[c] + eps) kset = h;
|
|
21
|
+
b[0] = 1.0;
|
|
22
|
+
for (j = 1; j < K; ++j) {
|
|
23
|
+
if (L > 0) --L;
|
|
24
|
+
b[j] = 0.0;
|
|
25
|
+
for (i = 0; i < j; ++i) {
|
|
26
|
+
h = j - i;
|
|
27
|
+
T q1 = q[kset + h] - t;
|
|
28
|
+
T q2 = t - q[kset - i];
|
|
29
|
+
T dt = q1 + q2;
|
|
30
|
+
T a = 0.0; if (dt > 0.0) a = b[h-1] / dt;
|
|
31
|
+
if (L > 0) {
|
|
32
|
+
b[ h ] += a * q2; // 決定項
|
|
33
|
+
b[h-1] = a * q1; // 準備項
|
|
34
|
+
} else {
|
|
35
|
+
a *= j;
|
|
36
|
+
b[ h ] += a; // 決定項
|
|
37
|
+
b[h-1] = -a; // 準備項
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return kset - j + 1;
|
|
42
|
+
}
|
|
43
|
+
/*******************************************************************************
|
|
44
|
+
de Boor-Cox の漸化式によるB−スプライン関数値の計算
|
|
45
|
+
K: Bスプラインの階数(j+1)
|
|
46
|
+
q: 節点の配列
|
|
47
|
+
cox: Bスプラインの基底数
|
|
48
|
+
t: データ点の座標(q[j] <= t <= q[cox])
|
|
49
|
+
J: 漸化式の適用回数
|
|
50
|
+
L: (0 >= L >= -j) ? 微分階数
|
|
51
|
+
*******************************************************************************/
|
|
52
|
+
template<typename P, typename T>
|
|
53
|
+
// P = varray<double>, T = poly<double>;
|
|
54
|
+
void deboor_cox(int K, const P& q, int cox, const T& t, P& b, int &kset, int J, int L)
|
|
55
|
+
{
|
|
56
|
+
static const T eps(1.0e-10);
|
|
57
|
+
|
|
58
|
+
int I = J + L;
|
|
59
|
+
int H = I + K + L;
|
|
60
|
+
if (J == 0 && I >= 0) {
|
|
61
|
+
int j = K - 1, c = cox - 1;
|
|
62
|
+
for(int i=j;i<c;++i)if(q[i]<=t && t<q[i+1]){kset=i;break;}
|
|
63
|
+
if(q[c]<=t && t<=q[cox]+eps){kset=c;}
|
|
64
|
+
b[0] = 1.0;
|
|
65
|
+
} else if (I >= 0 || H < 0) {
|
|
66
|
+
int j = J - (I < 0 ? I + 1 : 0);
|
|
67
|
+
const P& b0 = b[j+1];
|
|
68
|
+
deboor_cox(K, q, cox, t, const_cast<P&>(b0), kset, J-1, L+1);
|
|
69
|
+
b[j] = 0.0;
|
|
70
|
+
for(int i = 0; i < j; ++i) {
|
|
71
|
+
int h = j - i;
|
|
72
|
+
T q1 = q[kset + h] - t;
|
|
73
|
+
T q2 = t - q[kset - i];
|
|
74
|
+
T dt = q1 + q2;
|
|
75
|
+
T a = 0.0; if (dt > 0.0) a = b0[h-1] / dt;
|
|
76
|
+
if (L >= 0) {
|
|
77
|
+
b[ h ] += a * q2;
|
|
78
|
+
b[h-1] = a * q1;
|
|
79
|
+
} else {
|
|
80
|
+
a *= j;
|
|
81
|
+
b[ h ] += a;
|
|
82
|
+
b[h-1] = -a;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
/*******************************************************************************
|
|
88
|
+
シェーンバーグ・ホイットニー条件を満たす節点の設定
|
|
89
|
+
q0, ..., qj, qk, ..., qi, ..., qc-1, qc, ..., qc+j
|
|
90
|
+
x0, ..., x0, | , ..., | , ..., | , xn-1, ..., xn-1
|
|
91
|
+
(x0+xk)/2 (xi-k+xi)/2 (xn-k-1+xn-1)/2
|
|
92
|
+
q : 節点の配列
|
|
93
|
+
m : 節点配列の長さ (c + k)
|
|
94
|
+
c : スプライン基底の個数
|
|
95
|
+
n : データ点の個数
|
|
96
|
+
k : スプライン階数 (k <= n)
|
|
97
|
+
d : 境界条件数 (d < k)
|
|
98
|
+
s : 周期
|
|
99
|
+
x : データ点の配列(x == NULL: パラメトリックスプラインを示す)
|
|
100
|
+
ms :
|
|
101
|
+
*******************************************************************************/
|
|
102
|
+
template<typename T>
|
|
103
|
+
void setten(varray<T>& q, int m, int c, int n, int k, int d, int s, const varray<T>& x, const int *ms = NULL)
|
|
104
|
+
{
|
|
105
|
+
if (s == 0)
|
|
106
|
+
for (int i = 0; i < m; i++)
|
|
107
|
+
if ((T*)x) /* シェーンバーグ・ホイットニー条件 */
|
|
108
|
+
q[i] = i < k ? x[0] : i < c ? (x[i-k] + x[i-d]) / 2.0 : x[n-1];
|
|
109
|
+
else /* パラメトリック */
|
|
110
|
+
q[i] = i < k ? 0.0 : i < c ? real<T>(T(i)) - real<T>(T(k + d)) / 2.0 : real<T>(T(n - 1));
|
|
111
|
+
else
|
|
112
|
+
if (s > 0) /* 周期境界条件による節点の設定 */
|
|
113
|
+
for (int i = 0; i < m; i++) {
|
|
114
|
+
int j = i - k + 1;
|
|
115
|
+
if ((T*)x)
|
|
116
|
+
q[i] = j < 0 ? x[0] + x[j+s] - x[s] : j <= s ? x[j] : x[s] + x[j-s] - x[0];
|
|
117
|
+
else
|
|
118
|
+
q[i] = j;
|
|
119
|
+
}
|
|
120
|
+
else
|
|
121
|
+
if (ms) {
|
|
122
|
+
int k0 = k, k1, n0, n1;
|
|
123
|
+
varray<T> p(q), y(x);
|
|
124
|
+
while (s++) {
|
|
125
|
+
n1 = *ms++; k1 = *ms++; n0 = n1 + 1;
|
|
126
|
+
setten(p, n0, n0, n0, k0, 0, 0, y, NULL);
|
|
127
|
+
p = p[n0]; m -= n0; c -= n0; n -= n1; k0 = k1; y = y[n1];
|
|
128
|
+
}
|
|
129
|
+
setten(p, m, c, n, k0, c - n, 0, y, NULL);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
/*******************************************************************************
|
|
133
|
+
初期化(d == 0 ? 境界条件のないスプライン補間)
|
|
134
|
+
n: データ点の個数
|
|
135
|
+
x: データ点の座標 x[0,...,n-1]
|
|
136
|
+
j: スプラインの次数(スプライン階数 K = j + 1)
|
|
137
|
+
d: d >= 0 ? データ点に追加される境界条件数 : 周期境界条件(d = T - n - 1)
|
|
138
|
+
T: 周期(境界条件数 = d + K)
|
|
139
|
+
d > j : 多重節点の付加、m = {n1, k1, ... }
|
|
140
|
+
*******************************************************************************/
|
|
141
|
+
template <typename T>
|
|
142
|
+
base_spline<T>::base_spline(int n, const varray<T>& x, int j, int d, int *m)
|
|
143
|
+
{
|
|
144
|
+
int s = 0;
|
|
145
|
+
if (d > j) { s = j - d; d = 0; }
|
|
146
|
+
// 周期境界条件フラグ
|
|
147
|
+
shuki = d < 0 ? 1 : 0;
|
|
148
|
+
// スプライン階数
|
|
149
|
+
rank = j + 1;
|
|
150
|
+
// スプライン次数
|
|
151
|
+
jisu = j;
|
|
152
|
+
// 周期(データ点の個数)
|
|
153
|
+
imax = n + d + shuki;
|
|
154
|
+
// Bスプライン関数基底の個数
|
|
155
|
+
icox = imax + jisu * shuki;
|
|
156
|
+
// 節点の個数
|
|
157
|
+
maxq = icox + rank;
|
|
158
|
+
// 節点の配列
|
|
159
|
+
knots = new varray<T>(size_t(maxq), x.atom());
|
|
160
|
+
// 節点の配列を初期化
|
|
161
|
+
setten(*knots, maxq, icox, n, rank, d, s + imax * shuki, x, m);
|
|
162
|
+
}
|
|
163
|
+
/*******************************************************************************
|
|
164
|
+
初期化
|
|
165
|
+
q: ノットベクトル
|
|
166
|
+
c: スプライン関数基底の個数
|
|
167
|
+
k: スプライン階数
|
|
168
|
+
s: 周期指定
|
|
169
|
+
*******************************************************************************/
|
|
170
|
+
template <typename T>
|
|
171
|
+
base_spline<T>::base_spline(const varray<T>& q, int k, int c, int s)
|
|
172
|
+
{
|
|
173
|
+
assert(s == 0 || s == 1);
|
|
174
|
+
assert(k - (k-1)*s <= c);
|
|
175
|
+
// 周期境界条件フラグ
|
|
176
|
+
shuki = s;
|
|
177
|
+
// スプライン階数
|
|
178
|
+
rank = k;
|
|
179
|
+
// スプライン次数
|
|
180
|
+
jisu = k - 1;
|
|
181
|
+
// 周期(データ点の個数)
|
|
182
|
+
imax = c - jisu * shuki;
|
|
183
|
+
// Bスプライン関数基底の個数
|
|
184
|
+
icox = c;
|
|
185
|
+
// 節点の個数
|
|
186
|
+
maxq = icox + rank;
|
|
187
|
+
// 節点の配列
|
|
188
|
+
knots = new varray<T>(size_t(maxq), q.atom());
|
|
189
|
+
// 節点の配列を初期化
|
|
190
|
+
for (int i = 0; i < maxq; i++) (*knots)[i] = q[i];
|
|
191
|
+
}
|
|
192
|
+
// コピーコンストラクター
|
|
193
|
+
template <typename T>
|
|
194
|
+
base_spline<T>::base_spline(const base_spline& b)
|
|
195
|
+
: imax(b.imax), icox(b.icox), rank(b.rank), jisu(b.jisu), shuki(b.shuki), maxq(b.maxq), knots(new varray<T>(*b.knots)) {}
|
|
196
|
+
// 代入オペレーター
|
|
197
|
+
template <typename T>
|
|
198
|
+
base_spline<T>& base_spline<T>::operator=(const base_spline& b)
|
|
199
|
+
{
|
|
200
|
+
if (this != &b) {
|
|
201
|
+
delete knots;
|
|
202
|
+
imax = b.imax; icox = b.icox; rank = b.rank; jisu = b.jisu; shuki = b.shuki; maxq = b.maxq;
|
|
203
|
+
knots = new varray<T>(*b.knots);
|
|
204
|
+
}
|
|
205
|
+
return *this;
|
|
206
|
+
}
|
|
207
|
+
/*******************************************************************************
|
|
208
|
+
Bスプライン関数値の計算 Bi,K(t): i = kset-jisu,...,kset
|
|
209
|
+
t: データ点の座標値
|
|
210
|
+
c,b: 結果を入れる配列(c:サイズ,b:配列へのポインタ)
|
|
211
|
+
j: j > 0 ? Bi,j(x) : j == 0 ? Bi,rank(x) : j < 0 ? D(-j)Bi,rank(x)
|
|
212
|
+
*******************************************************************************/
|
|
213
|
+
template <typename S>
|
|
214
|
+
int base_spline<S>::basic(const real<S>& t, int c, varray<S>& b, int j) const
|
|
215
|
+
{
|
|
216
|
+
int kset = 0, k = j > 0 ? j : rank;
|
|
217
|
+
assert(c >= k);
|
|
218
|
+
const varray<S>& bc = b[c - k];
|
|
219
|
+
int ks = deboor(rank, *knots, icox, t, const_cast<varray<S>&>(bc), kset, j);
|
|
220
|
+
if (c != k) {
|
|
221
|
+
int kmax = ((c - 1) == kset ? ks : c);
|
|
222
|
+
for (int i = 0; i < kmax; ++i)
|
|
223
|
+
b[i] = (ks <= i) && (i <= kset) ? bc[i - ks] : 0.0;
|
|
224
|
+
}
|
|
225
|
+
return ks;
|
|
226
|
+
}
|
|
227
|
+
/*******************************************************************************
|
|
228
|
+
係数行列の構成
|
|
229
|
+
*******************************************************************************/
|
|
230
|
+
template <typename T>
|
|
231
|
+
static void shuki_spline(int k, const varray<T>& b, int n, varray<T>& bc)
|
|
232
|
+
{
|
|
233
|
+
int j = k - 1;
|
|
234
|
+
int m = k / 2; /* m = Mjis = (Jisu+1)/2 = kai/2 */
|
|
235
|
+
int m_1 = j - m;
|
|
236
|
+
int i, o = n - m + 1;
|
|
237
|
+
for (i = 0; i < m; i++) bc[i] = b[i+m_1] + b[i+m_1+n];
|
|
238
|
+
for (i = m; i < o; i++) bc[i] = b[i+m_1];
|
|
239
|
+
for (i = o; i < n; i++) bc[i] = b[i+m_1] + b[i+m_1-n];
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
template <typename T>
|
|
243
|
+
void base_spline<T>::gyoretu(marray<T>& bd, int n, const varray<T>& x, const int *d) const
|
|
244
|
+
{
|
|
245
|
+
if (shuki == 0)
|
|
246
|
+
for (int j = 0; j < n; j++) {
|
|
247
|
+
varray<T> bc = bd.row(j);
|
|
248
|
+
basic(( (T*)x ? x[j] : real<T>(T(j)) ), imax, bc, (d ? -d[j] : 0));
|
|
249
|
+
}
|
|
250
|
+
else {
|
|
251
|
+
varray<T> b(size_t(icox), x.atom()); /* 周期スプライン係数行列の計算 */
|
|
252
|
+
for (int j = 0; j < n; j++) {
|
|
253
|
+
basic(( (T*)x ? x[j] : real<T>(T(j)) ), icox, b, (d ? -d[j] : 0));
|
|
254
|
+
varray<T> bc = bd.row(j);
|
|
255
|
+
shuki_spline(rank, b, imax, bc);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
template <typename T>
|
|
261
|
+
marray<T> base_spline<T>::gyoretu(const Int& a, const varray<T>& x, const int *d) const
|
|
262
|
+
{
|
|
263
|
+
size_t n = a[0];
|
|
264
|
+
marray<T> bd(n, n, a.atom());
|
|
265
|
+
gyoretu(bd, n, x, d);
|
|
266
|
+
return bd;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
template <typename T>
|
|
270
|
+
parray<T> base_spline<T>::basis(const real<T>& t, int jbn) const
|
|
271
|
+
{
|
|
272
|
+
int h = rank - (jbn < 0 ? jbn : 0);
|
|
273
|
+
int j = jbn < 0 ? h : -jbn;
|
|
274
|
+
varray<T> data(size_t(h), t.atom());
|
|
275
|
+
int kset, offset = deboor(rank, *knots, icox, t, data, kset, j);
|
|
276
|
+
parray<T> result(offset, h, 1, t.atom());
|
|
277
|
+
varray<T> m = result[0];
|
|
278
|
+
for (int i = 0; i < h; ++i) m[i] = data[i];
|
|
279
|
+
return result;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
template <typename T>
|
|
283
|
+
parray<T> base_spline<T>::bases(const real<T>& t, int jbn) const
|
|
284
|
+
{
|
|
285
|
+
int N = 1; for (int i = 2; i <= rank; i++) N += i;
|
|
286
|
+
varray<T> data(size_t(N), t.atom());
|
|
287
|
+
int kset; deboor_cox(rank, *knots, icox, t, data, kset, jisu);
|
|
288
|
+
int offset = kset - jisu, k = jbn + 1;
|
|
289
|
+
parray<T> result(offset, rank, k, t.atom());
|
|
290
|
+
for (int j = 0; j <= jbn; ++j) {
|
|
291
|
+
varray<T> m = result[j];
|
|
292
|
+
if (j > 0) deboor_cox(rank, *knots, icox, t, data, kset, rank-j, -rank);
|
|
293
|
+
for(int i = 0; i < rank; ++i) m[i] = data[i];
|
|
294
|
+
}
|
|
295
|
+
return result;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
template <typename S>
|
|
299
|
+
parray<S> base_spline<S>::sekibun(const real<S>& x, int Jsk) const
|
|
300
|
+
{
|
|
301
|
+
assert(Jsk < 0);
|
|
302
|
+
const varray<S>& q = *knots;
|
|
303
|
+
int K = rank, J = K - 1, R = K - Jsk;
|
|
304
|
+
varray<S> B(size_t(R), x.atom());
|
|
305
|
+
int kset, ks = deboor(K, q, icox, x, B, kset, R);
|
|
306
|
+
int offset = kset - J;
|
|
307
|
+
parray<S> pc(offset, K, 1, x.atom());
|
|
308
|
+
varray<S> ac(size_t(kset+1), x.atom()), sum = pc[0];
|
|
309
|
+
for (int i = 0; i < K; ++i) {
|
|
310
|
+
int Jsc = -Jsk;
|
|
311
|
+
for (int j = 0; j <= kset; ++j)
|
|
312
|
+
ac[j] = 0.0;
|
|
313
|
+
ac[i+offset] = 1;
|
|
314
|
+
while(Jsc) {
|
|
315
|
+
for (int j = 0; j <= kset; ++j)
|
|
316
|
+
ac[j] = (j > 0 ? ac[j-1] : 0.0) + ac[j] * (q[j+(R-Jsc)] - q[j]) / S(R-Jsc);
|
|
317
|
+
Jsc--;
|
|
318
|
+
} sum[i] = 0.0;
|
|
319
|
+
for (int j = (ks >= 0 ? ks : 0); j <= kset; ++j)
|
|
320
|
+
sum[i] += ac[j] * B[j - ks];
|
|
321
|
+
}
|
|
322
|
+
return pc;
|
|
323
|
+
}
|
|
324
|
+
/*******************************************************************************
|
|
325
|
+
微分係数の計算
|
|
326
|
+
*******************************************************************************/
|
|
327
|
+
template <typename S>
|
|
328
|
+
void base_spline<S>::bibun_keisu(int Jbn, marray<S>& ad) const
|
|
329
|
+
{
|
|
330
|
+
real<S> zk; int n = ad.cols();
|
|
331
|
+
const varray<S>& q = *knots;
|
|
332
|
+
|
|
333
|
+
for (int j = 0; j < Jbn; j++) {
|
|
334
|
+
varray<S> a0 = ad.row(j);
|
|
335
|
+
varray<S> a1 = ad.row(j+1);
|
|
336
|
+
a1[0] = 0.0;
|
|
337
|
+
for (int i = 1; i < n; i++) {
|
|
338
|
+
if ((zk = q[i+Jbn-j] - q[i]) != 0.0)
|
|
339
|
+
a1[i] = (Jbn-j)*(a0[i] - a0[i-1])/zk;
|
|
340
|
+
else
|
|
341
|
+
a1[i] = 0.0;
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
/*******************************************************************************
|
|
346
|
+
積分係数の計算
|
|
347
|
+
*******************************************************************************/
|
|
348
|
+
template <typename S>
|
|
349
|
+
static real<S> qvalue(int m, const varray<S>& q, int i, int j, int c)
|
|
350
|
+
{
|
|
351
|
+
int k = i - c + j;
|
|
352
|
+
return ((k < m) ? q[k] : qvalue(m, q, k, j, c)) + q[c] - q[j];
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
#define QVALUE(i) ((i)<m ? q[i] : shuki ? qvalue(m,q,i,jisu,icox) : q[m-1])
|
|
356
|
+
|
|
357
|
+
template <typename S>
|
|
358
|
+
void base_spline<S>::sekibun_keisu(int Jsk, marray<S>& ai) const
|
|
359
|
+
{
|
|
360
|
+
int ki = rank, m = Maxq(), n = ai.cols();
|
|
361
|
+
const varray<S>& q = *knots;
|
|
362
|
+
|
|
363
|
+
assert(n <= icox);
|
|
364
|
+
for (int js = 1; js <= Jsk; js++) {
|
|
365
|
+
real<S> a0 = ai.row((js-1)%2);
|
|
366
|
+
real<S> a1 = ai.row(js%2);
|
|
367
|
+
for (int j = 0; j < n; j++)
|
|
368
|
+
a1[j] = (j > 0 ? a1[j-1] : 0.0) + a0[j]*(QVALUE(j+ki)-q[j])/ki;
|
|
369
|
+
ki++;
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
template <typename S>
|
|
374
|
+
int base_spline<S>::Kset(const real<S>& x) const
|
|
375
|
+
{
|
|
376
|
+
static const S eps = S(1.0e-10);
|
|
377
|
+
|
|
378
|
+
int L = 0;
|
|
379
|
+
const varray<S>& q = *knots;
|
|
380
|
+
for(int i = jisu; i < icox; ++i)
|
|
381
|
+
if (q[i] <= x && x < q[i+1]){ L = i; break;}
|
|
382
|
+
if(q[icox-1] <= x && x <= q[icox]+eps){ L = icox-1;}
|
|
383
|
+
return L;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
template <typename S>
|
|
387
|
+
void base_spline<S>::print() const
|
|
388
|
+
{
|
|
389
|
+
printf("<K = %d, C = %d, I = %d, J = %d, S = %d\n", rank, icox, imax, jisu, shuki);
|
|
390
|
+
knots->print("%g>\n");
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
template class base_spline<double>;
|
|
394
|
+
|