p1788 0.1.0 → 1.0.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/.yardopts +1 -0
- data/LICENSE +674 -201
- data/README.md +19 -13
- data/ext/libieeep1788_copy/p1788/decoration/decoration.hpp +1 -1
- data/ext/p1788/extconf.rb +11 -6
- data/ext/p1788/figure.cc +1284 -0
- data/ext/p1788/figure.hh +294 -0
- data/ext/p1788/figure_wrapper.cc +1249 -0
- data/ext/p1788/p1788.cc +3948 -935
- data/ext/p1788/p1788.hh +102 -0
- data/lib/p1788/version.rb +1 -1
- data/lib/p1788.rb +12 -17
- data/p1788.gemspec +9 -4
- data/samples/figure.rb +23 -0
- data/samples/sivia.rb +122 -0
- metadata +9 -4
- data/AUTHORS +0 -6
data/ext/p1788/p1788.hh
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
/* Copyright (C) 2022 Théotime Bollengier <theotime.bollengier@ensta-bretagne.fr>
|
2
|
+
*
|
3
|
+
* This file is part of P1788. <https://gitlab.ensta-bretagne.fr/bollenth/p1788>
|
4
|
+
*
|
5
|
+
* P1788 is free software: you can redistribute it and/or modify it
|
6
|
+
* under the terms of the GNU General Public License as published
|
7
|
+
* by the Free Software Foundation, either version 3 of the License,
|
8
|
+
* or (at your option) any later version.
|
9
|
+
*
|
10
|
+
* P1788 is distributed in the hope that it will be useful,
|
11
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
13
|
+
* See the GNU General Public License for more details.
|
14
|
+
*
|
15
|
+
* You should have received a copy of the GNU General Public License
|
16
|
+
* along with P1788. If not, see <https://www.gnu.org/licenses/>.
|
17
|
+
*/
|
18
|
+
|
19
|
+
#ifndef P1788_HH
|
20
|
+
#define P1788_HH
|
21
|
+
|
22
|
+
#include <ruby.h>
|
23
|
+
#include <vector>
|
24
|
+
#include <string>
|
25
|
+
#include <p1788/p1788.hpp>
|
26
|
+
|
27
|
+
using Interval = p1788::infsup::interval<double, p1788::flavor::infsup::setbased::mpfr_bin_ieee754_flavor>;
|
28
|
+
using IntervalVector = std::vector<Interval>;
|
29
|
+
|
30
|
+
extern VALUE m_P1788;
|
31
|
+
extern VALUE c_Interval;
|
32
|
+
extern VALUE c_IntervalVector;
|
33
|
+
extern VALUE c_Figure;
|
34
|
+
|
35
|
+
extern const rb_data_type_t p1788_interval_type;
|
36
|
+
extern const rb_data_type_t p1788_vector_type;
|
37
|
+
|
38
|
+
|
39
|
+
extern ID id_to_s;
|
40
|
+
extern ID id_to_f;
|
41
|
+
extern ID id_to_i;
|
42
|
+
extern ID id_match;
|
43
|
+
extern ID id_brackets;
|
44
|
+
extern ID id_eqeq;
|
45
|
+
extern ID id_inspect;
|
46
|
+
extern ID id_join;
|
47
|
+
extern ID id_undefined;
|
48
|
+
extern ID id_both_empty;
|
49
|
+
extern ID id_first_empty;
|
50
|
+
extern ID id_second_empty;
|
51
|
+
extern ID id_before;
|
52
|
+
extern ID id_meets;
|
53
|
+
extern ID id_overlaps;
|
54
|
+
extern ID id_starts;
|
55
|
+
extern ID id_contained_by;
|
56
|
+
extern ID id_finishes;
|
57
|
+
extern ID id_equal;
|
58
|
+
extern ID id_finished_by;
|
59
|
+
extern ID id_contains;
|
60
|
+
extern ID id_started_by;
|
61
|
+
extern ID id_overlapped_by;
|
62
|
+
extern ID id_met_by;
|
63
|
+
extern ID id_after;
|
64
|
+
|
65
|
+
|
66
|
+
#define P1788_NEW_RB_INTERVAL(new_rb_obj, ...) \
|
67
|
+
do { \
|
68
|
+
Interval *isdp_ = new Interval(__VA_ARGS__); \
|
69
|
+
new_rb_obj = TypedData_Wrap_Struct(c_Interval, &p1788_interval_type, isdp_); \
|
70
|
+
} while (0)
|
71
|
+
|
72
|
+
|
73
|
+
inline Interval& p1788_interval_rb2ref(VALUE obj) {
|
74
|
+
Interval *i;
|
75
|
+
TypedData_Get_Struct(obj, Interval, &p1788_interval_type, i);
|
76
|
+
return *i;
|
77
|
+
}
|
78
|
+
|
79
|
+
|
80
|
+
inline IntervalVector& p1788_vector_rb2ref(VALUE obj) {
|
81
|
+
IntervalVector *v;
|
82
|
+
TypedData_Get_Struct(obj, IntervalVector, &p1788_vector_type, v);
|
83
|
+
return *v;
|
84
|
+
}
|
85
|
+
|
86
|
+
|
87
|
+
inline VALUE p1788_vector_alloc_from_pointer(IntervalVector *p) {
|
88
|
+
return TypedData_Wrap_Struct(c_IntervalVector, &p1788_vector_type, p);
|
89
|
+
}
|
90
|
+
|
91
|
+
|
92
|
+
inline bool is_an_interval_vector(VALUE obj) {
|
93
|
+
return (rb_class_of(obj) == c_IntervalVector);
|
94
|
+
}
|
95
|
+
|
96
|
+
|
97
|
+
Interval p1788_rbobj2interval(VALUE obj);
|
98
|
+
|
99
|
+
void Init_p1788_figure();
|
100
|
+
|
101
|
+
|
102
|
+
#endif /* P1788_HH */
|
data/lib/p1788/version.rb
CHANGED
data/lib/p1788.rb
CHANGED
@@ -1,24 +1,19 @@
|
|
1
|
+
# Copyright (C) 2022 Théotime Bollengier <theotime.bollengier@ensta-bretagne.fr>
|
1
2
|
#
|
2
|
-
#
|
3
|
+
# This file is part of P1788. <https://gitlab.ensta-bretagne.fr/bollenth/p1788>
|
3
4
|
#
|
4
|
-
#
|
5
|
+
# P1788 is free software: you can redistribute it and/or modify it
|
6
|
+
# under the terms of the GNU General Public License as published
|
7
|
+
# by the Free Software Foundation, either version 3 of the License,
|
8
|
+
# or (at your option) any later version.
|
5
9
|
#
|
6
|
-
#
|
10
|
+
# P1788 is distributed in the hope that it will be useful,
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
13
|
+
# See the GNU General Public License for more details.
|
7
14
|
#
|
8
|
-
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
12
|
-
# you may not use this file except in compliance with the License.
|
13
|
-
# You may obtain a copy of the License at
|
14
|
-
#
|
15
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
16
|
-
#
|
17
|
-
# Unless required by applicable law or agreed to in writing, software
|
18
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
19
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
20
|
-
# See the License for the specific language governing permissions and
|
21
|
-
# limitations under the License.
|
15
|
+
# You should have received a copy of the GNU General Public License
|
16
|
+
# along with P1788. If not, see <https://www.gnu.org/licenses/>.
|
22
17
|
|
23
18
|
require_relative 'p1788/p1788'
|
24
19
|
require_relative 'p1788/version.rb'
|
data/p1788.gemspec
CHANGED
@@ -3,10 +3,10 @@ require File.expand_path('../lib/p1788/version.rb', __FILE__)
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = 'p1788'
|
5
5
|
s.version = P1788::VERSION
|
6
|
-
s.date = '2022-01-
|
6
|
+
s.date = '2022-01-27'
|
7
7
|
s.summary = 'P1788 is an interval arithmetic library'
|
8
8
|
s.description = 'P1788 is a Ruby C extension wrapping the libieeep1788 interval arithmetic library.'
|
9
|
-
s.license = '
|
9
|
+
s.license = 'GPL-3.0+'
|
10
10
|
s.authors = ['Théotime Bollengier']
|
11
11
|
s.email = 'theotime.bollengier@ensta-bretagne.fr'
|
12
12
|
s.homepage = 'https://gitlab.ensta-bretagne.fr/bollenth/p1788'
|
@@ -14,7 +14,6 @@ Gem::Specification.new do |s|
|
|
14
14
|
s.files = [
|
15
15
|
'LICENSE',
|
16
16
|
'NOTICE',
|
17
|
-
'AUTHORS',
|
18
17
|
'README.md',
|
19
18
|
'p1788.gemspec',
|
20
19
|
'.yardopts',
|
@@ -22,6 +21,10 @@ Gem::Specification.new do |s|
|
|
22
21
|
'lib/p1788/version.rb',
|
23
22
|
'ext/p1788/extconf.rb',
|
24
23
|
'ext/p1788/p1788.cc',
|
24
|
+
'ext/p1788/p1788.hh',
|
25
|
+
'ext/p1788/figure.cc',
|
26
|
+
'ext/p1788/figure.hh',
|
27
|
+
'ext/p1788/figure_wrapper.cc',
|
25
28
|
'ext/libieeep1788_copy/README',
|
26
29
|
'ext/libieeep1788_copy/p1788/LICENSE',
|
27
30
|
'ext/libieeep1788_copy/p1788/NOTICE',
|
@@ -66,7 +69,9 @@ Gem::Specification.new do |s|
|
|
66
69
|
'ext/libieeep1788_copy/p1788/util/mixed_type_traits.hpp',
|
67
70
|
'ext/libieeep1788_copy/p1788/util/mpfr_util.hpp',
|
68
71
|
'ext/libieeep1788_copy/p1788/util/mpfr_var.hpp',
|
69
|
-
'ext/libieeep1788_copy/p1788/util/mpfr_var_impl.hpp'
|
72
|
+
'ext/libieeep1788_copy/p1788/util/mpfr_var_impl.hpp',
|
73
|
+
'samples/figure.rb',
|
74
|
+
'samples/sivia.rb'
|
70
75
|
]
|
71
76
|
end
|
72
77
|
|
data/samples/figure.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'p1788'
|
4
|
+
include P1788
|
5
|
+
|
6
|
+
nbbox = 100
|
7
|
+
x = IntervalVector.new(nbbox){|i| 2*Interval[i.to_f/nbbox, (i+1.0)/nbbox]-1}
|
8
|
+
b = x.map{|ix| IntervalVector[ix, ix**2]}
|
9
|
+
c = x.map{|ix| IntervalVector[ix, sqrt(ix)]}
|
10
|
+
|
11
|
+
f = Figure.new
|
12
|
+
f.background_color = 'W'
|
13
|
+
f.width = 720
|
14
|
+
f.xlabel = "Horizontal axis label"
|
15
|
+
f.ylabel = "Vertical axis label"
|
16
|
+
f.title = "Lorem ipsum title"
|
17
|
+
f.draw_boxes(b, 'k[g]')
|
18
|
+
f.draw_boxes(c, 'k[R]')
|
19
|
+
pp f.nice_range
|
20
|
+
f.write 'fig.png'
|
21
|
+
f.write 'fig.svg'
|
22
|
+
f.write 'fig.pdf'
|
23
|
+
|
data/samples/sivia.rb
ADDED
@@ -0,0 +1,122 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'p1788'
|
4
|
+
include P1788
|
5
|
+
|
6
|
+
def sivia(initial_box, epsilon, &test)
|
7
|
+
l = [initial_box]
|
8
|
+
x_in = []
|
9
|
+
x_on = []
|
10
|
+
x_out = []
|
11
|
+
until l.empty? do
|
12
|
+
b = l.pop
|
13
|
+
case test.call(b)
|
14
|
+
when true
|
15
|
+
x_in << b
|
16
|
+
when false
|
17
|
+
x_out << b
|
18
|
+
else
|
19
|
+
if b.max_width <= epsilon then
|
20
|
+
x_on << b
|
21
|
+
else
|
22
|
+
l += b.bisect
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
return [x_in, x_on, x_out]
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
################################################################################
|
31
|
+
|
32
|
+
ib = IntervalVector[-1.5..1.5, -1.5 .. 1.5]
|
33
|
+
|
34
|
+
bin, bon, bout = sivia(ib, 0.025) do |b|
|
35
|
+
(b[0]**2 + b[1]**2).sqrt.inclusion_test(0.7..1)
|
36
|
+
end
|
37
|
+
|
38
|
+
f = Figure.new
|
39
|
+
f.width = 512
|
40
|
+
f.xrange = ib.first
|
41
|
+
f.yrange = ib.last
|
42
|
+
f.draw_boxes(bout, 'w')
|
43
|
+
f.draw_boxes(bin, 'k[g]')
|
44
|
+
f.draw_boxes(bon, 'k[y]')
|
45
|
+
f.write_png 'donut.png'
|
46
|
+
|
47
|
+
################################################################################
|
48
|
+
|
49
|
+
ib = IntervalVector[[-2, 2], [-2, 2]]
|
50
|
+
|
51
|
+
bin, bon, bout = sivia(ib, 0.05) do |b|
|
52
|
+
((b[0]-0.4)**5 + (b[1] - 0.3)**5).inclusion_test(1..2)
|
53
|
+
end
|
54
|
+
|
55
|
+
f = Figure.new
|
56
|
+
f.width = 512
|
57
|
+
f.xrange = ib.first
|
58
|
+
f.yrange = ib.last
|
59
|
+
f.draw_boxes(bout, 'w')
|
60
|
+
f.draw_boxes(bin, 'k[g]')
|
61
|
+
f.draw_boxes(bon, 'k[y]')
|
62
|
+
f.write_png 'pow5.png'
|
63
|
+
|
64
|
+
################################################################################
|
65
|
+
|
66
|
+
ib = IntervalVector[-3..3, -3..3]
|
67
|
+
dstbox = IntervalVector[[-4, -2], [4, 9], [7, 11]]
|
68
|
+
y = IntervalVector.new(3)
|
69
|
+
|
70
|
+
bin, bon, bout = sivia(ib, 0.04) do |b|
|
71
|
+
[-1, 1, 2].each_with_index do |t, i|
|
72
|
+
y[i] = (t*b[0])**2 + t*b[1]**2 + sin(b[0] + t*b[1])
|
73
|
+
end
|
74
|
+
y.inclusion_test(dstbox)
|
75
|
+
end
|
76
|
+
|
77
|
+
f = Figure.new
|
78
|
+
f.width = 512
|
79
|
+
f.xrange = ib.first
|
80
|
+
f.yrange = ib.last
|
81
|
+
f.draw_boxes(bout, 'w')
|
82
|
+
f.draw_boxes(bin, 'k[g]')
|
83
|
+
f.draw_boxes(bon, 'k[y]')
|
84
|
+
f.write_png 'smiley.png'
|
85
|
+
|
86
|
+
################################################################################
|
87
|
+
|
88
|
+
ib = IntervalVector[[-0.5, 3], [-3, 0.5]]
|
89
|
+
l = 0.2
|
90
|
+
|
91
|
+
bin, bon, bout = sivia(ib, 0.02) do |b|
|
92
|
+
(exp(b[0]*b[1]) - sin(b[0]-b[1])).inclusion_test(-l..l)
|
93
|
+
end
|
94
|
+
|
95
|
+
f = Figure.new
|
96
|
+
f.width = 512
|
97
|
+
f.set_range ib
|
98
|
+
f.draw_boxes(bout, 'w')
|
99
|
+
f.draw_boxes(bin, 'k[g]')
|
100
|
+
f.draw_boxes(bon, 'k[y]')
|
101
|
+
f.write_png 'expsin.png'
|
102
|
+
|
103
|
+
################################################################################
|
104
|
+
|
105
|
+
ib = IntervalVector[[-6, 2], [-3, 3]]
|
106
|
+
dsti = Interval[0.325, Float::INFINITY]
|
107
|
+
|
108
|
+
bin, bon, bout = sivia(ib, 0.05) do |b|
|
109
|
+
(sin(b[0]**2 + b[1]**2) / (exp(b[0]) + b[1]**2)).inclusion_test(dsti)
|
110
|
+
end
|
111
|
+
|
112
|
+
f = Figure.new
|
113
|
+
f.width = 512
|
114
|
+
f.set_range ib
|
115
|
+
f.draw_boxes(bout, 'w')
|
116
|
+
f.draw_boxes(bin, 'k[g]')
|
117
|
+
f.draw_boxes(bon, 'k[y]')
|
118
|
+
f.write_png 'sinexp.png'
|
119
|
+
puts f.allocated_size
|
120
|
+
f.reset!
|
121
|
+
puts f.allocated_size
|
122
|
+
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: p1788
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Théotime Bollengier
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-01-
|
11
|
+
date: 2022-01-27 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: P1788 is a Ruby C extension wrapping the libieeep1788 interval arithmetic
|
14
14
|
library.
|
@@ -19,7 +19,6 @@ extensions:
|
|
19
19
|
extra_rdoc_files: []
|
20
20
|
files:
|
21
21
|
- ".yardopts"
|
22
|
-
- AUTHORS
|
23
22
|
- LICENSE
|
24
23
|
- NOTICE
|
25
24
|
- README.md
|
@@ -69,13 +68,19 @@ files:
|
|
69
68
|
- ext/libieeep1788_copy/p1788/util/mpfr_var_impl.hpp
|
70
69
|
- ext/libieeep1788_copy/p1788/version.hpp
|
71
70
|
- ext/p1788/extconf.rb
|
71
|
+
- ext/p1788/figure.cc
|
72
|
+
- ext/p1788/figure.hh
|
73
|
+
- ext/p1788/figure_wrapper.cc
|
72
74
|
- ext/p1788/p1788.cc
|
75
|
+
- ext/p1788/p1788.hh
|
73
76
|
- lib/p1788.rb
|
74
77
|
- lib/p1788/version.rb
|
75
78
|
- p1788.gemspec
|
79
|
+
- samples/figure.rb
|
80
|
+
- samples/sivia.rb
|
76
81
|
homepage: https://gitlab.ensta-bretagne.fr/bollenth/p1788
|
77
82
|
licenses:
|
78
|
-
-
|
83
|
+
- GPL-3.0+
|
79
84
|
metadata: {}
|
80
85
|
post_install_message:
|
81
86
|
rdoc_options: []
|