ruby-mpfi 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +4 -0
- data/Manifest.txt +62 -0
- data/PostInstall.txt +7 -0
- data/README.rdoc +48 -0
- data/Rakefile +26 -0
- data/ext/mpfi/extconf.rb +10 -0
- data/ext/mpfi/func_mpfi_extention.c +52 -0
- data/ext/mpfi/func_mpfi_extention.h +2 -0
- data/ext/mpfi/make_c_source.rb +115 -0
- data/ext/mpfi/ruby_mpfi.c +1452 -0
- data/ext/mpfi/ruby_mpfi.h +39 -0
- data/ext/mpfi/ruby_mpfr.h +38 -0
- data/ext/mpfi/yasnippet_mpfi.el +44 -0
- data/ext/mpfi_complex/mpfi/extconf.rb +10 -0
- data/ext/mpfi_complex/mpfi/func_mpfi_extention.h +2 -0
- data/ext/mpfi_complex/mpfi/func_ruby_mpfi_complex.c +130 -0
- data/ext/mpfi_complex/mpfi/func_ruby_mpfi_complex.h +35 -0
- data/ext/mpfi_complex/mpfi/ruby_mpfi.h +39 -0
- data/ext/mpfi_complex/mpfi/ruby_mpfi_complex.c +217 -0
- data/ext/mpfi_complex/mpfi/ruby_mpfi_complex.h +15 -0
- data/ext/mpfi_complex/mpfi/ruby_mpfr.h +38 -0
- data/ext/mpfi_matrix/mpfi/extconf.rb +9 -0
- data/ext/mpfi_matrix/mpfi/func_mpfi_extention.h +2 -0
- data/ext/mpfi_matrix/mpfi/func_mpfi_matrix.c +795 -0
- data/ext/mpfi_matrix/mpfi/func_mpfi_matrix.h +103 -0
- data/ext/mpfi_matrix/mpfi/func_mpfr_matrix.h +72 -0
- data/ext/mpfi_matrix/mpfi/func_ruby_mpfi_complex.h +35 -0
- data/ext/mpfi_matrix/mpfi/ruby_mpfi.h +39 -0
- data/ext/mpfi_matrix/mpfi/ruby_mpfi_complex.h +15 -0
- data/ext/mpfi_matrix/mpfi/ruby_mpfi_matrix.c +1200 -0
- data/ext/mpfi_matrix/mpfi/ruby_mpfi_matrix.h +13 -0
- data/ext/mpfi_matrix/mpfi/ruby_mpfr.h +38 -0
- data/ext/mpfi_matrix/mpfi/ruby_mpfr_matrix.h +13 -0
- data/lib/mpfi/matrix.rb +188 -0
- data/lib/mpfi/version.rb +3 -0
- data/ruby-mpfi.gemspec +35 -0
- data/script/console +10 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/spec/mpfi/generate_number_module.rb +48 -0
- data/spec/mpfi/mpfi_alloc_spec.rb +55 -0
- data/spec/mpfi/mpfi_diam_arithmetic_spec.rb +25 -0
- data/spec/mpfi/mpfi_interval_arithmetic_spec.rb +105 -0
- data/spec/mpfi/mpfi_interval_functions_spec.rb +95 -0
- data/spec/mpfi/mpfi_math_functions_spec.rb +16 -0
- data/spec/mpfi/mpfi_set_operation_spec.rb +102 -0
- data/spec/mpfi/ruby-mpfi_spec.rb +11 -0
- data/spec/mpfi/spec_helper.rb +10 -0
- data/spec/mpfi_complex/spec_helper.rb +10 -0
- data/spec/mpfi_matrix/generate_matrix_arguments.rb +65 -0
- data/spec/mpfi_matrix/mpfi_matrix_alloc_spec.rb +134 -0
- data/spec/mpfi_matrix/mpfi_matrix_arithmetic_spec.rb +156 -0
- data/spec/mpfi_matrix/mpfi_matrix_interval_func_spec.rb +30 -0
- data/spec/mpfi_matrix/mpfi_matrix_set_element_spec.rb +55 -0
- data/spec/mpfi_matrix/mpfi_matrix_set_operation_spec.rb +71 -0
- data/spec/mpfi_matrix/mpfi_matrix_string_spec.rb +32 -0
- data/spec/mpfi_matrix/mpfi_matrix_subdivision_spec.rb +14 -0
- data/spec/mpfi_matrix/mpfi_square_matrix_spec.rb +37 -0
- data/spec/mpfi_matrix/mpfi_vector_spec.rb +15 -0
- data/spec/mpfi_matrix/spec_helper.rb +19 -0
- data/spec/spec.opts +1 -0
- data/tasks/extconf.rake +36 -0
- metadata +132 -0
data/History.txt
ADDED
data/Manifest.txt
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
History.txt
|
2
|
+
Manifest.txt
|
3
|
+
PostInstall.txt
|
4
|
+
README.rdoc
|
5
|
+
Rakefile
|
6
|
+
ext/mpfi/extconf.rb
|
7
|
+
ext/mpfi/func_mpfi_extention.c
|
8
|
+
ext/mpfi/func_mpfi_extention.h
|
9
|
+
ext/mpfi/make_c_source.rb
|
10
|
+
ext/mpfi/ruby_mpfi.c
|
11
|
+
ext/mpfi/ruby_mpfi.h
|
12
|
+
ext/mpfi/ruby_mpfr.h
|
13
|
+
ext/mpfi/yasnippet_mpfi.el
|
14
|
+
ext/mpfi_complex/mpfi/extconf.rb
|
15
|
+
ext/mpfi_complex/mpfi/func_mpfi_extention.h
|
16
|
+
ext/mpfi_complex/mpfi/func_ruby_mpfi_complex.c
|
17
|
+
ext/mpfi_complex/mpfi/func_ruby_mpfi_complex.h
|
18
|
+
ext/mpfi_complex/mpfi/ruby_mpfi.h
|
19
|
+
ext/mpfi_complex/mpfi/ruby_mpfi_complex.c
|
20
|
+
ext/mpfi_complex/mpfi/ruby_mpfi_complex.h
|
21
|
+
ext/mpfi_complex/mpfi/ruby_mpfr.h
|
22
|
+
ext/mpfi_matrix/mpfi/extconf.rb
|
23
|
+
ext/mpfi_matrix/mpfi/func_mpfi_extention.h
|
24
|
+
ext/mpfi_matrix/mpfi/func_mpfi_matrix.c
|
25
|
+
ext/mpfi_matrix/mpfi/func_mpfi_matrix.h
|
26
|
+
ext/mpfi_matrix/mpfi/func_mpfr_matrix.h
|
27
|
+
ext/mpfi_matrix/mpfi/func_ruby_mpfi_complex.h
|
28
|
+
ext/mpfi_matrix/mpfi/ruby_mpfi.h
|
29
|
+
ext/mpfi_matrix/mpfi/ruby_mpfi_complex.h
|
30
|
+
ext/mpfi_matrix/mpfi/ruby_mpfi_matrix.c
|
31
|
+
ext/mpfi_matrix/mpfi/ruby_mpfi_matrix.h
|
32
|
+
ext/mpfi_matrix/mpfi/ruby_mpfr.h
|
33
|
+
ext/mpfi_matrix/mpfi/ruby_mpfr_matrix.h
|
34
|
+
lib/mpfi/matrix.rb
|
35
|
+
lib/mpfi/version.rb
|
36
|
+
ruby-mpfi.gemspec
|
37
|
+
script/console
|
38
|
+
script/destroy
|
39
|
+
script/generate
|
40
|
+
spec/mpfi/generate_number_module.rb
|
41
|
+
spec/mpfi/mpfi_alloc_spec.rb
|
42
|
+
spec/mpfi/mpfi_diam_arithmetic_spec.rb
|
43
|
+
spec/mpfi/mpfi_interval_arithmetic_spec.rb
|
44
|
+
spec/mpfi/mpfi_interval_functions_spec.rb
|
45
|
+
spec/mpfi/mpfi_math_functions_spec.rb
|
46
|
+
spec/mpfi/mpfi_set_operation_spec.rb
|
47
|
+
spec/mpfi/ruby-mpfi_spec.rb
|
48
|
+
spec/mpfi/spec_helper.rb
|
49
|
+
spec/mpfi_complex/spec_helper.rb
|
50
|
+
spec/mpfi_matrix/generate_matrix_arguments.rb
|
51
|
+
spec/mpfi_matrix/mpfi_matrix_alloc_spec.rb
|
52
|
+
spec/mpfi_matrix/mpfi_matrix_arithmetic_spec.rb
|
53
|
+
spec/mpfi_matrix/mpfi_matrix_interval_func_spec.rb
|
54
|
+
spec/mpfi_matrix/mpfi_matrix_set_element_spec.rb
|
55
|
+
spec/mpfi_matrix/mpfi_matrix_set_operation_spec.rb
|
56
|
+
spec/mpfi_matrix/mpfi_matrix_string_spec.rb
|
57
|
+
spec/mpfi_matrix/mpfi_matrix_subdivision_spec.rb
|
58
|
+
spec/mpfi_matrix/mpfi_square_matrix_spec.rb
|
59
|
+
spec/mpfi_matrix/mpfi_vector_spec.rb
|
60
|
+
spec/mpfi_matrix/spec_helper.rb
|
61
|
+
spec/spec.opts
|
62
|
+
tasks/extconf.rake
|
data/PostInstall.txt
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
= ruby-mpfi
|
2
|
+
|
3
|
+
* http://github.com/#{github_username}/#{project_name}
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
FIX (describe your package)
|
8
|
+
|
9
|
+
== FEATURES/PROBLEMS:
|
10
|
+
|
11
|
+
* FIX (list of features or problems)
|
12
|
+
|
13
|
+
== SYNOPSIS:
|
14
|
+
|
15
|
+
FIX (code sample of usage)
|
16
|
+
|
17
|
+
== REQUIREMENTS:
|
18
|
+
|
19
|
+
* FIX (list of requirements)
|
20
|
+
|
21
|
+
== INSTALL:
|
22
|
+
|
23
|
+
* FIX (sudo gem install, anything else)
|
24
|
+
|
25
|
+
== LICENSE:
|
26
|
+
|
27
|
+
(The MIT License)
|
28
|
+
|
29
|
+
Copyright (c) 2009 FIXME full name
|
30
|
+
|
31
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
32
|
+
a copy of this software and associated documentation files (the
|
33
|
+
'Software'), to deal in the Software without restriction, including
|
34
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
35
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
36
|
+
permit persons to whom the Software is furnished to do so, subject to
|
37
|
+
the following conditions:
|
38
|
+
|
39
|
+
The above copyright notice and this permission notice shall be
|
40
|
+
included in all copies or substantial portions of the Software.
|
41
|
+
|
42
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
43
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
44
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
45
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
46
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
47
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
48
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
gem 'hoe', '>= 2.1.0'
|
3
|
+
require 'hoe'
|
4
|
+
require 'fileutils'
|
5
|
+
require './lib/mpfi/version.rb'
|
6
|
+
|
7
|
+
Hoe.plugin :newgem
|
8
|
+
# Hoe.plugin :website
|
9
|
+
# Hoe.plugin :cucumberfeatures
|
10
|
+
|
11
|
+
# Generate all the Rake tasks
|
12
|
+
# Run 'rake -T' to see list of generated tasks (from gem root directory)
|
13
|
+
$hoe = Hoe.spec 'ruby-mpfi' do
|
14
|
+
self.developer 'Takayuki YAMAGUCHI', 'd@ytak.info'
|
15
|
+
self.post_install_message = 'PostInstall.txt' # TODO remove if post-install message not required
|
16
|
+
self.rubyforge_name = self.name # TODO this is default value
|
17
|
+
# self.extra_deps = [['activesupport','>= 2.0.2']]
|
18
|
+
self.spec_extras[:extensions] = ["ext/mpfi/extconf.rb", "ext/mpfi_complex/mpfi/extconf.rb", "ext/mpfi_matrix/mpfi/extconf.rb"]
|
19
|
+
end
|
20
|
+
|
21
|
+
require 'newgem/tasks'
|
22
|
+
Dir['tasks/**/*.rake'].each { |t| load t }
|
23
|
+
|
24
|
+
# TODO - want other tests/tasks run by default? Add them to the list
|
25
|
+
# remove_task :default
|
26
|
+
# task :default => [:spec, :features]
|
data/ext/mpfi/extconf.rb
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'mkmf'
|
2
|
+
|
3
|
+
$CFLAGS += " -Wall"
|
4
|
+
|
5
|
+
dir_config("mpfr")
|
6
|
+
dir_config("mpfi")
|
7
|
+
dir_config("gmp")
|
8
|
+
if have_header('mpfr.h') && have_library('mpfr') && have_header('mpfi.h') && have_library('mpfi') && have_header('gmp.h') && have_library('gmp')
|
9
|
+
create_makefile("mpfi")
|
10
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
#include <mpfr.h>
|
2
|
+
#include <mpfi.h>
|
3
|
+
#include <mpfi_io.h>
|
4
|
+
#include "ruby_mpfi.h"
|
5
|
+
#include "func_mpfi_extention.h"
|
6
|
+
|
7
|
+
void mpfi_mid_interval(mpfi_t ret, mpfi_t x){
|
8
|
+
mpfr_t left, right;
|
9
|
+
mpfr_init2(left, mpfi_get_prec(x));
|
10
|
+
mpfr_init2(right, mpfi_get_prec(x));
|
11
|
+
|
12
|
+
mpfr_add(left, r_mpfi_left_ptr(x), r_mpfi_right_ptr(x), GMP_RNDD);
|
13
|
+
mpfr_add(right, r_mpfi_left_ptr(x), r_mpfi_right_ptr(x), GMP_RNDU);
|
14
|
+
|
15
|
+
mpfr_div_ui(r_mpfi_left_ptr(ret), left, 2, GMP_RNDD);
|
16
|
+
mpfr_div_ui(r_mpfi_right_ptr(ret), right, 2, GMP_RNDU);
|
17
|
+
|
18
|
+
mpfr_clear(left);
|
19
|
+
mpfr_clear(right);
|
20
|
+
}
|
21
|
+
|
22
|
+
/* Retrun 0 if this function puts subdivision to *ret. */
|
23
|
+
/* Otherwise, return -1. */
|
24
|
+
int mpfi_subdivision(int num, mpfi_t *ret, mpfi_t x){
|
25
|
+
int i, ret_val = -1;
|
26
|
+
mpfr_t l;
|
27
|
+
mpfr_init(l);
|
28
|
+
mpfr_sub(l, r_mpfi_right_ptr(x), r_mpfi_left_ptr(x), GMP_RNDD);
|
29
|
+
mpfr_div_si(l, l, num, GMP_RNDD);
|
30
|
+
|
31
|
+
mpfr_t x_diam;
|
32
|
+
mpfr_init(x_diam);
|
33
|
+
mpfi_diam_abs(x_diam, x);
|
34
|
+
if(mpfr_cmp(x_diam, l) > 0){
|
35
|
+
mpfr_set(r_mpfi_left_ptr(*ret), r_mpfi_left_ptr(x), GMP_RNDN);
|
36
|
+
mpfr_add(r_mpfi_right_ptr(*ret), r_mpfi_left_ptr(*ret), l, GMP_RNDU);
|
37
|
+
|
38
|
+
for(i = 1; i < num - 1; i ++){
|
39
|
+
mpfr_set(r_mpfi_left_ptr(*ret + i), r_mpfi_right_ptr(*ret + i - 1), GMP_RNDN);
|
40
|
+
mpfr_add(r_mpfi_right_ptr(*ret + i), r_mpfi_left_ptr(*ret + i), l, GMP_RNDU);
|
41
|
+
}
|
42
|
+
|
43
|
+
mpfr_set(r_mpfi_left_ptr(*ret + i), r_mpfi_right_ptr(*ret + i - 1), GMP_RNDN);
|
44
|
+
mpfr_set(r_mpfi_right_ptr(*ret + i), r_mpfi_right_ptr(x), GMP_RNDN);
|
45
|
+
ret_val = 0;
|
46
|
+
}
|
47
|
+
|
48
|
+
mpfr_clear(x_diam);
|
49
|
+
mpfr_clear(l);
|
50
|
+
return ret_val;
|
51
|
+
}
|
52
|
+
|
@@ -0,0 +1,115 @@
|
|
1
|
+
|
2
|
+
def make_sepcial_functions(one_arguments, no_argument)
|
3
|
+
one_arguments.each do |name|
|
4
|
+
puts <<SRC
|
5
|
+
static VALUE r_mpfi_math_#{name} (int argc, VALUE *argv, VALUE self){
|
6
|
+
R_MPFI *ptr_a0, *ptr_ret;
|
7
|
+
r_mpfi_get_convert_struct(argv[0], ptr_a0);
|
8
|
+
VALUE val_ret;
|
9
|
+
r_mpfi_make_struct_init2(val_ret, ptr_ret, r_mpfr_prec_from_optional_argument(1, 2, argc, argv));
|
10
|
+
r_mpfi_set_function_state(mpfi_#{name}(ptr_ret, ptr_a0));
|
11
|
+
return val_ret;
|
12
|
+
}
|
13
|
+
|
14
|
+
SRC
|
15
|
+
end
|
16
|
+
|
17
|
+
no_argument.each do |name|
|
18
|
+
puts <<SRC
|
19
|
+
static VALUE r_mpfi_math_#{name} (int argc, VALUE *argv, VALUE self){
|
20
|
+
R_MPFI *ptr_ret;
|
21
|
+
VALUE val_ret;
|
22
|
+
r_mpfi_make_struct_init2(val_ret, ptr_ret, r_mpfr_prec_from_optional_argument(0, 1, argc, argv));
|
23
|
+
r_mpfi_set_function_state(mpfi_#{name}(ptr_ret));
|
24
|
+
return val_ret;
|
25
|
+
}
|
26
|
+
|
27
|
+
SRC
|
28
|
+
end
|
29
|
+
|
30
|
+
(one_arguments + no_argument).each do |name|
|
31
|
+
puts %!rb_define_module_function(r_mpfi_math, "#{name}", r_mpfi_math_#{name}, -1);!
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
def make_comparison(positive_returned_value, non_zero_returned_value)
|
37
|
+
positive_returned_value.each do |name|
|
38
|
+
puts <<SRC
|
39
|
+
static VALUE r_mpfi_#{name} (VALUE self){
|
40
|
+
R_MPFI *ptr_self;
|
41
|
+
r_mpfi_get_struct(ptr_self, self);
|
42
|
+
if (mpfi_#{name}(ptr_self) > 0) {
|
43
|
+
return Qtrue;
|
44
|
+
}else{
|
45
|
+
return Qnil;
|
46
|
+
}
|
47
|
+
}
|
48
|
+
|
49
|
+
SRC
|
50
|
+
end
|
51
|
+
|
52
|
+
non_zero_returned_value.each do |name|
|
53
|
+
puts <<SRC
|
54
|
+
static VALUE r_mpfi_#{name} (VALUE self){
|
55
|
+
R_MPFI *ptr_self;
|
56
|
+
r_mpfi_get_struct(ptr_self, self);
|
57
|
+
if (mpfi_#{name}(ptr_self) != 0) {
|
58
|
+
return Qtrue;
|
59
|
+
}else{
|
60
|
+
return Qnil;
|
61
|
+
}
|
62
|
+
}
|
63
|
+
|
64
|
+
SRC
|
65
|
+
end
|
66
|
+
|
67
|
+
(positive_returned_value + non_zero_returned_value).each do |name|
|
68
|
+
puts %!rb_define_module_function(r_mpfi_class, "#{name}", r_mpfi_#{name}, 0);!
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
# Parse options.
|
73
|
+
require 'optparse'
|
74
|
+
|
75
|
+
help_message =<<HELP
|
76
|
+
Make C source for extended library mpfr.
|
77
|
+
HELP
|
78
|
+
|
79
|
+
category = nil
|
80
|
+
|
81
|
+
begin
|
82
|
+
OptionParser.new(help_message) do |opt|
|
83
|
+
# on(short [, klass [, pat [, desc]]]) {|v| ...}
|
84
|
+
# on(long [, klass [, pat [, desc]]) {|v| ...}
|
85
|
+
# on(short, long [, klass [, pat [, desc]]]) {|v| ...}
|
86
|
+
opt.on('--special') { |v| category = :special }
|
87
|
+
opt.on('--comparison') { |v| category = :comparison }
|
88
|
+
opt.parse!(ARGV)
|
89
|
+
end
|
90
|
+
rescue OptionParser::InvalidOption
|
91
|
+
$stderr.print <<MES
|
92
|
+
error: Invalid Option
|
93
|
+
#{help_message}
|
94
|
+
MES
|
95
|
+
exit(2)
|
96
|
+
rescue OptionParser::InvalidArgument
|
97
|
+
$stderr.print <<MES
|
98
|
+
error: Invalid Argument
|
99
|
+
#{help_message}
|
100
|
+
MES
|
101
|
+
exit(2)
|
102
|
+
end
|
103
|
+
|
104
|
+
case category
|
105
|
+
when :special
|
106
|
+
one_arguments = ['log', 'exp', 'exp2', 'cos', 'sin', 'tan', 'acos', 'asin', 'atan', 'cosh', 'sinh', 'tanh',
|
107
|
+
'acosh', 'asinh', 'atanh', 'log1p', 'expm1', 'log2', 'log10']
|
108
|
+
no_argument = ['const_log2', 'const_pi', 'const_euler']
|
109
|
+
make_sepcial_functions(one_arguments, no_argument)
|
110
|
+
when :comparison
|
111
|
+
positive_returned_value = ['is_pos', 'is_strictly_pos', 'is_nonneg', 'is_neg', 'is_strictly_neg', 'is_nonpos', 'is_zero']
|
112
|
+
non_zero_returned_value = ['nan_p', 'inf_p', 'bounded_p']
|
113
|
+
make_comparison(positive_returned_value, non_zero_returned_value)
|
114
|
+
end
|
115
|
+
|