ruby-mpfi 0.0.9 → 0.0.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/mpfi/func_mpfi_extention.c +5 -7
- data/ext/mpfi/func_mpfi_extention.h +2 -2
- data/ext/mpfi/ruby_mpfi.c +181 -165
- data/ext/mpfi/ruby_mpfi.h +9 -9
- data/ext/mpfi_complex/mpfi/func_mpfi_extention.h +2 -2
- data/ext/mpfi_complex/mpfi/func_ruby_mpfi_complex.c +16 -16
- data/ext/mpfi_complex/mpfi/func_ruby_mpfi_complex.h +16 -16
- data/ext/mpfi_complex/mpfi/ruby_mpfi_complex.c +19 -21
- data/ext/mpfi_complex/mpfi/ruby_mpfi_complex.h +1 -1
- data/ext/mpfi_matrix/mpfi/func_mpfi_extention.h +2 -2
- data/ext/mpfi_matrix/mpfi/func_mpfi_matrix.c +113 -113
- data/ext/mpfi_matrix/mpfi/func_mpfi_matrix.h +46 -47
- data/ext/mpfi_matrix/mpfi/ruby_mpfi_matrix.c +198 -195
- data/ext/mpfi_matrix/mpfi/ruby_mpfi_matrix.h +2 -2
- data/lib/mpfi.rb +21 -0
- data/lib/mpfi/matrix.rb +109 -23
- data/lib/mpfi/version.rb +2 -2
- metadata +3 -2
data/ext/mpfi/ruby_mpfi.h
CHANGED
@@ -26,17 +26,17 @@ VALUE r_mpfi_class, r_mpfi_math;;
|
|
26
26
|
#define r_mpfi_left_ptr(c_var) (&((c_var)->left))
|
27
27
|
#define r_mpfi_right_ptr(c_var) (&((c_var)->right))
|
28
28
|
|
29
|
-
void r_mpfi_free(void *ptr);
|
30
|
-
VALUE r_mpfi_make_new_fi_obj(MPFI *ptr);
|
31
|
-
VALUE r_mpfi_new_fi_obj(VALUE obj);
|
32
|
-
void r_mpfi_set_robj(MPFI *ptr, VALUE obj);
|
29
|
+
void r_mpfi_free (void *ptr);
|
30
|
+
VALUE r_mpfi_make_new_fi_obj (MPFI *ptr);
|
31
|
+
VALUE r_mpfi_new_fi_obj (VALUE obj);
|
32
|
+
void r_mpfi_set_robj (MPFI *ptr, VALUE obj);
|
33
33
|
|
34
|
-
int r_mpfi_subdivision2(int num, MPFI *ret, mpfi_t x);
|
34
|
+
int r_mpfi_subdivision2 (int num, MPFI *ret, mpfi_t x);
|
35
35
|
|
36
|
-
void r_mpfi_set_function_state(int num);
|
37
|
-
VALUE r_mpfi_get_function_state(VALUE self);
|
36
|
+
void r_mpfi_set_function_state (int num);
|
37
|
+
VALUE r_mpfi_get_function_state (VALUE self);
|
38
38
|
|
39
|
-
void r_mpfi_load_string(MPFI *ptr_s, const char *dump);
|
40
|
-
char *r_mpfi_dump_to_string(MPFI *ptr_s);
|
39
|
+
void r_mpfi_load_string (MPFI *ptr_s, const char *dump);
|
40
|
+
char *r_mpfi_dump_to_string (MPFI *ptr_s);
|
41
41
|
|
42
42
|
#endif /* _RUBY_MPFI_H_ */
|
@@ -1,2 +1,2 @@
|
|
1
|
-
void mpfi_mid_interval(mpfi_t ret, mpfi_t x);
|
2
|
-
int mpfi_subdivision(int num, mpfi_t *ret, mpfi_t x);
|
1
|
+
void mpfi_mid_interval (mpfi_t ret, mpfi_t x);
|
2
|
+
int mpfi_subdivision (int num, mpfi_t *ret, mpfi_t x);
|
@@ -1,53 +1,53 @@
|
|
1
1
|
#include "func_ruby_mpfi_complex.h"
|
2
2
|
|
3
|
-
void mpfi_complex_init(MPFIComplex *x){
|
3
|
+
void mpfi_complex_init (MPFIComplex *x) {
|
4
4
|
x->re = ALLOC_N(MPFI, 1);
|
5
5
|
x->im = ALLOC_N(MPFI, 1);
|
6
6
|
mpfi_init(x->re);
|
7
7
|
mpfi_init(x->im);
|
8
8
|
}
|
9
9
|
|
10
|
-
void mpfi_complex_clear(MPFIComplex *x){
|
10
|
+
void mpfi_complex_clear (MPFIComplex *x) {
|
11
11
|
mpfi_clear(x->re);
|
12
12
|
mpfi_clear(x->im);
|
13
13
|
free(x->re);
|
14
14
|
free(x->im);
|
15
15
|
}
|
16
16
|
|
17
|
-
void mpfi_complex_set_zeros(MPFIComplex *x){
|
17
|
+
void mpfi_complex_set_zeros (MPFIComplex *x) {
|
18
18
|
mpfi_set_si(x->re, 0);
|
19
19
|
mpfi_set_si(x->im, 0);
|
20
20
|
}
|
21
21
|
|
22
|
-
void mpfi_complex_set_real_part(MPFIComplex *x, MPFI *a){
|
22
|
+
void mpfi_complex_set_real_part (MPFIComplex *x, MPFI *a) {
|
23
23
|
mpfi_set(x->re, a);
|
24
24
|
}
|
25
25
|
|
26
|
-
void mpfi_complex_set_imaginary_part(MPFIComplex *x, MPFI *a){
|
26
|
+
void mpfi_complex_set_imaginary_part (MPFIComplex *x, MPFI *a) {
|
27
27
|
mpfi_set(x->im, a);
|
28
28
|
}
|
29
29
|
|
30
|
-
void mpfi_complex_set(MPFIComplex *new, MPFIComplex *x){
|
30
|
+
void mpfi_complex_set (MPFIComplex *new, MPFIComplex *x) {
|
31
31
|
mpfi_set(new->re, x->re);
|
32
32
|
mpfi_set(new->im, x->im);
|
33
33
|
}
|
34
34
|
|
35
|
-
void mpfi_complex_conjugate(MPFIComplex *new, MPFIComplex *x){
|
35
|
+
void mpfi_complex_conjugate (MPFIComplex *new, MPFIComplex *x) {
|
36
36
|
mpfi_set(new->re, x->re);
|
37
37
|
mpfi_neg(new->im, x->im);
|
38
38
|
}
|
39
39
|
|
40
|
-
void mpfi_complex_add(MPFIComplex *new, MPFIComplex *x, MPFIComplex *y){
|
40
|
+
void mpfi_complex_add (MPFIComplex *new, MPFIComplex *x, MPFIComplex *y) {
|
41
41
|
mpfi_add(new->re, x->re, y->re);
|
42
42
|
mpfi_add(new->im, x->im, y->im);
|
43
43
|
}
|
44
44
|
|
45
|
-
void mpfi_complex_sub(MPFIComplex *new, MPFIComplex *x, MPFIComplex *y){
|
45
|
+
void mpfi_complex_sub (MPFIComplex *new, MPFIComplex *x, MPFIComplex *y) {
|
46
46
|
mpfi_sub(new->re, x->re, y->re);
|
47
47
|
mpfi_sub(new->im, x->im, y->im);
|
48
48
|
}
|
49
49
|
|
50
|
-
void mpfi_complex_mul(MPFIComplex *new, MPFIComplex *x, MPFIComplex *y){
|
50
|
+
void mpfi_complex_mul (MPFIComplex *new, MPFIComplex *x, MPFIComplex *y) {
|
51
51
|
MPFI *t1, *t2, *t_re;
|
52
52
|
r_mpfi_temp_alloc_init2(t1, mpfi_complex_get_prec(new));
|
53
53
|
r_mpfi_temp_alloc_init2(t2, mpfi_complex_get_prec(new));
|
@@ -68,7 +68,7 @@ void mpfi_complex_mul(MPFIComplex *new, MPFIComplex *x, MPFIComplex *y){
|
|
68
68
|
r_mpfi_temp_free(t_re);
|
69
69
|
}
|
70
70
|
|
71
|
-
void mpfi_complex_div(MPFIComplex *new, MPFIComplex *x, MPFIComplex *y){
|
71
|
+
void mpfi_complex_div (MPFIComplex *new, MPFIComplex *x, MPFIComplex *y) {
|
72
72
|
MPFI *t1, *t2, *t_re, *deno;
|
73
73
|
r_mpfi_temp_alloc_init2(t1, mpfi_complex_get_prec(new));
|
74
74
|
r_mpfi_temp_alloc_init2(t2, mpfi_complex_get_prec(new));
|
@@ -97,29 +97,29 @@ void mpfi_complex_div(MPFIComplex *new, MPFIComplex *x, MPFIComplex *y){
|
|
97
97
|
r_mpfi_temp_free(deno);
|
98
98
|
}
|
99
99
|
|
100
|
-
/* void mpfi_complex_mul_real(MPFIComplex *new, MPFIComplex *x, MPFI *y){ */
|
100
|
+
/* void mpfi_complex_mul_real (MPFIComplex *new, MPFIComplex *x, MPFI *y) { */
|
101
101
|
/* mpfi_mul(new->re, x->re, y); */
|
102
102
|
/* mpfi_mul(new->im, x->im, y); */
|
103
103
|
/* } */
|
104
104
|
|
105
|
-
/* void mpfi_complex_mul_pure_imaginary(MPFIComplex *new, MPFIComplex *x, MPFI *y){ */
|
105
|
+
/* void mpfi_complex_mul_pure_imaginary (MPFIComplex *new, MPFIComplex *x, MPFI *y) { */
|
106
106
|
/* mpfi_mul(new->re, x->im, y); */
|
107
107
|
/* mpfi_neg(new->re, new->re); */
|
108
108
|
/* mpfi_mul(new->im, x->re, y); */
|
109
109
|
/* } */
|
110
110
|
|
111
|
-
/* void mpfi_complex_div_real(MPFIComplex *new, MPFIComplex *x, MPFI *y){ */
|
111
|
+
/* void mpfi_complex_div_real (MPFIComplex *new, MPFIComplex *x, MPFI *y) { */
|
112
112
|
/* mpfi_div(new->re, x->re, y); */
|
113
113
|
/* mpfi_div(new->im, x->im, y); */
|
114
114
|
/* } */
|
115
115
|
|
116
|
-
/* void mpfi_complex_div_pure_imaginary(MPFIComplex *new, MPFIComplex *x, MPFI *y){ */
|
116
|
+
/* void mpfi_complex_div_pure_imaginary (MPFIComplex *new, MPFIComplex *x, MPFI *y) { */
|
117
117
|
/* mpfi_div(new->re, x->im, y); */
|
118
118
|
/* mpfi_div(new->im, x->re, y); */
|
119
119
|
/* mpfi_neg(new->im, new->im); */
|
120
120
|
/* } */
|
121
121
|
|
122
|
-
/* void mpfi_complex_abs(MPFI *new, MPFIComplex *x){ */
|
122
|
+
/* void mpfi_complex_abs (MPFI *new, MPFIComplex *x) { */
|
123
123
|
/* MPFI *tmp; */
|
124
124
|
/* r_mpfi_temp_alloc_init(tmp); */
|
125
125
|
/* mpfi_mul(tmp, x->re, x->re); */
|
@@ -16,20 +16,20 @@ typedef struct __MPFIComplex{
|
|
16
16
|
/* we implement mpfi_complex_get_prec assuming that they have same presition. */
|
17
17
|
#define mpfi_complex_get_prec(x) mpfi_get_prec(x->re)
|
18
18
|
|
19
|
-
void mpfi_complex_init(MPFIComplex *x);
|
20
|
-
void mpfi_complex_clear(MPFIComplex *x);
|
21
|
-
void mpfi_complex_set_zeros(MPFIComplex *x);
|
22
|
-
void mpfi_complex_set_real_part(MPFIComplex *x, MPFI *a);
|
23
|
-
void mpfi_complex_set_imaginary_part(MPFIComplex *x, MPFI *a);
|
24
|
-
void mpfi_complex_set(MPFIComplex *new, MPFIComplex *x);
|
25
|
-
void mpfi_complex_conjugate(MPFIComplex *new, MPFIComplex *x);
|
26
|
-
void mpfi_complex_add(MPFIComplex *new, MPFIComplex *x, MPFIComplex *y);
|
27
|
-
void mpfi_complex_sub(MPFIComplex *new, MPFIComplex *x, MPFIComplex *y);
|
28
|
-
void mpfi_complex_mul(MPFIComplex *new, MPFIComplex *x, MPFIComplex *y);
|
29
|
-
void mpfi_complex_div(MPFIComplex *new, MPFIComplex *x, MPFIComplex *y);
|
19
|
+
void mpfi_complex_init (MPFIComplex *x);
|
20
|
+
void mpfi_complex_clear (MPFIComplex *x);
|
21
|
+
void mpfi_complex_set_zeros (MPFIComplex *x);
|
22
|
+
void mpfi_complex_set_real_part (MPFIComplex *x, MPFI *a);
|
23
|
+
void mpfi_complex_set_imaginary_part (MPFIComplex *x, MPFI *a);
|
24
|
+
void mpfi_complex_set (MPFIComplex *new, MPFIComplex *x);
|
25
|
+
void mpfi_complex_conjugate (MPFIComplex *new, MPFIComplex *x);
|
26
|
+
void mpfi_complex_add (MPFIComplex *new, MPFIComplex *x, MPFIComplex *y);
|
27
|
+
void mpfi_complex_sub (MPFIComplex *new, MPFIComplex *x, MPFIComplex *y);
|
28
|
+
void mpfi_complex_mul (MPFIComplex *new, MPFIComplex *x, MPFIComplex *y);
|
29
|
+
void mpfi_complex_div (MPFIComplex *new, MPFIComplex *x, MPFIComplex *y);
|
30
30
|
|
31
|
-
/* void mpfi_complex_mul_real(MPFIComplex *new, MPFIComplex *x, MPFI *y); */
|
32
|
-
/* void mpfi_complex_mul_pure_imaginary(MPFIComplex *new, MPFIComplex *x, MPFI *y); */
|
33
|
-
/* void mpfi_complex_div_real(MPFIComplex *new, MPFIComplex *x, MPFI *y); */
|
34
|
-
/* void mpfi_complex_div_pure_imaginary(MPFIComplex *new, MPFIComplex *x, MPFI *y); */
|
35
|
-
/* void mpfi_complex_abs(MPFI *new, MPFIComplex *x); */
|
31
|
+
/* void mpfi_complex_mul_real (MPFIComplex *new, MPFIComplex *x, MPFI *y); */
|
32
|
+
/* void mpfi_complex_mul_pure_imaginary (MPFIComplex *new, MPFIComplex *x, MPFI *y); */
|
33
|
+
/* void mpfi_complex_div_real (MPFIComplex *new, MPFIComplex *x, MPFI *y); */
|
34
|
+
/* void mpfi_complex_div_pure_imaginary (MPFIComplex *new, MPFIComplex *x, MPFI *y); */
|
35
|
+
/* void mpfi_complex_abs (MPFI *new, MPFIComplex *x); */
|
@@ -2,19 +2,19 @@
|
|
2
2
|
|
3
3
|
static ID object_id;
|
4
4
|
|
5
|
-
void r_mpfi_complex_free(void *ptr){
|
5
|
+
void r_mpfi_complex_free(void *ptr) {
|
6
6
|
mpfi_complex_clear(ptr);
|
7
7
|
free(ptr);
|
8
8
|
}
|
9
9
|
|
10
10
|
/* Allocation function for MPF::Complex. */
|
11
|
-
static VALUE r_mpfi_complex_alloc (VALUE self){
|
11
|
+
static VALUE r_mpfi_complex_alloc (VALUE self) {
|
12
12
|
MPFIComplex *ptr;
|
13
13
|
r_mpfi_make_complex_struct(self, ptr);
|
14
14
|
return self;
|
15
15
|
}
|
16
16
|
|
17
|
-
static void r_mpfi_complex_set_initial_value(MPFIComplex *ptr, int argc, VALUE *argv)
|
17
|
+
static void r_mpfi_complex_set_initial_value (MPFIComplex *ptr, int argc, VALUE *argv)
|
18
18
|
{
|
19
19
|
mpfi_complex_init(ptr);
|
20
20
|
switch (argc) {
|
@@ -36,7 +36,7 @@ static void r_mpfi_complex_set_initial_value(MPFIComplex *ptr, int argc, VALUE *
|
|
36
36
|
}
|
37
37
|
|
38
38
|
/* Return new MPFI::Complex instance. The same arguments as MPFI::Complex.new is acceptable. */
|
39
|
-
static VALUE r_mpfi_complex_global_new(int argc, VALUE *argv, VALUE self)
|
39
|
+
static VALUE r_mpfi_complex_global_new (int argc, VALUE *argv, VALUE self)
|
40
40
|
{
|
41
41
|
MPFIComplex *ptr;
|
42
42
|
VALUE val;
|
@@ -46,7 +46,7 @@ static VALUE r_mpfi_complex_global_new(int argc, VALUE *argv, VALUE self)
|
|
46
46
|
}
|
47
47
|
|
48
48
|
/* Initialization function for MPF::Complex. */
|
49
|
-
static VALUE r_mpfi_complex_initialize (int argc, VALUE *argv, VALUE self){
|
49
|
+
static VALUE r_mpfi_complex_initialize (int argc, VALUE *argv, VALUE self) {
|
50
50
|
MPFIComplex *ptr;
|
51
51
|
r_mpfi_get_complex_struct(ptr, self);
|
52
52
|
r_mpfi_complex_set_initial_value(ptr, argc, argv);
|
@@ -54,7 +54,7 @@ static VALUE r_mpfi_complex_initialize (int argc, VALUE *argv, VALUE self){
|
|
54
54
|
}
|
55
55
|
|
56
56
|
/* initialize_copy */
|
57
|
-
static VALUE r_mpfi_complex_initialize_copy (VALUE self, VALUE other){
|
57
|
+
static VALUE r_mpfi_complex_initialize_copy (VALUE self, VALUE other) {
|
58
58
|
MPFIComplex *ptr_self, *ptr_other;
|
59
59
|
r_mpfi_get_complex_struct(ptr_self, self);
|
60
60
|
r_mpfi_get_complex_struct(ptr_other, other);
|
@@ -64,7 +64,7 @@ static VALUE r_mpfi_complex_initialize_copy (VALUE self, VALUE other){
|
|
64
64
|
}
|
65
65
|
|
66
66
|
/* Return real part. */
|
67
|
-
static VALUE r_mpfi_complex_real (VALUE self){
|
67
|
+
static VALUE r_mpfi_complex_real (VALUE self) {
|
68
68
|
MPFIComplex *ptr_self;
|
69
69
|
VALUE ret;
|
70
70
|
MPFI *ptr_ret;
|
@@ -75,7 +75,7 @@ static VALUE r_mpfi_complex_real (VALUE self){
|
|
75
75
|
}
|
76
76
|
|
77
77
|
/* Return imaginary part. */
|
78
|
-
static VALUE r_mpfi_complex_imaginary (VALUE self){
|
78
|
+
static VALUE r_mpfi_complex_imaginary (VALUE self) {
|
79
79
|
MPFIComplex *ptr_self;
|
80
80
|
VALUE ret;
|
81
81
|
MPFI *ptr_ret;
|
@@ -86,13 +86,13 @@ static VALUE r_mpfi_complex_imaginary (VALUE self){
|
|
86
86
|
}
|
87
87
|
|
88
88
|
/* If _p1_ is 0, return real part. If _p1_ is 1, return imaginary part. */
|
89
|
-
static VALUE r_mpfi_complex_element (VALUE self, VALUE arg){
|
89
|
+
static VALUE r_mpfi_complex_element (VALUE self, VALUE arg) {
|
90
90
|
MPFIComplex *ptr_self;
|
91
91
|
VALUE ret;
|
92
92
|
MPFI *ptr_ret;
|
93
93
|
r_mpfi_get_complex_struct(ptr_self, self);
|
94
94
|
r_mpfi_make_struct_init(ret, ptr_ret);
|
95
|
-
switch(NUM2INT(arg)){
|
95
|
+
switch (NUM2INT(arg)) {
|
96
96
|
case 0:
|
97
97
|
mpfi_set(ptr_ret, ptr_self->re);
|
98
98
|
break;
|
@@ -107,7 +107,7 @@ static VALUE r_mpfi_complex_element (VALUE self, VALUE arg){
|
|
107
107
|
}
|
108
108
|
|
109
109
|
/* Return conjugate complex number. */
|
110
|
-
static VALUE r_mpfi_complex_conjugate (VALUE self){
|
110
|
+
static VALUE r_mpfi_complex_conjugate (VALUE self) {
|
111
111
|
MPFIComplex *ptr_self, *ptr_ret;
|
112
112
|
VALUE ret;
|
113
113
|
r_mpfi_get_complex_struct(ptr_self, self);
|
@@ -116,7 +116,7 @@ static VALUE r_mpfi_complex_conjugate (VALUE self){
|
|
116
116
|
return ret;
|
117
117
|
}
|
118
118
|
|
119
|
-
/* static VALUE r_mpfi_complex_abs (VALUE self){ */
|
119
|
+
/* static VALUE r_mpfi_complex_abs (VALUE self) { */
|
120
120
|
/* MPFIComplex *ptr_self; */
|
121
121
|
/* r_mpfi_get_complex_struct(ptr_self, self); */
|
122
122
|
/* VALUE ret; */
|
@@ -128,7 +128,7 @@ static VALUE r_mpfi_complex_conjugate (VALUE self){
|
|
128
128
|
|
129
129
|
|
130
130
|
/* String for inspect. */
|
131
|
-
static VALUE r_mpfi_complex_inspect(VALUE self){
|
131
|
+
static VALUE r_mpfi_complex_inspect (VALUE self) {
|
132
132
|
MPFIComplex *ptr_s;
|
133
133
|
char *ret_str;
|
134
134
|
VALUE ret_val;
|
@@ -145,7 +145,7 @@ static VALUE r_mpfi_complex_inspect(VALUE self){
|
|
145
145
|
}
|
146
146
|
|
147
147
|
/* Return array including strings which the elements is converted to by _p1_. */
|
148
|
-
static VALUE r_mpfi_complex_str_ary(VALUE self, VALUE format_str){
|
148
|
+
static VALUE r_mpfi_complex_str_ary (VALUE self, VALUE format_str) {
|
149
149
|
MPFIComplex *ptr_self;
|
150
150
|
char *format, *tmp_str;
|
151
151
|
VALUE ret_val[2];
|
@@ -161,7 +161,7 @@ static VALUE r_mpfi_complex_str_ary(VALUE self, VALUE format_str){
|
|
161
161
|
}
|
162
162
|
|
163
163
|
/* Return _self_ + _p1_.*/
|
164
|
-
static VALUE r_mpfi_complex_add (VALUE self, VALUE other){
|
164
|
+
static VALUE r_mpfi_complex_add (VALUE self, VALUE other) {
|
165
165
|
MPFIComplex *ptr_self, *ptr_other, *ptr_ret;
|
166
166
|
VALUE ret;
|
167
167
|
r_mpfi_get_complex_struct(ptr_self, self);
|
@@ -172,7 +172,7 @@ static VALUE r_mpfi_complex_add (VALUE self, VALUE other){
|
|
172
172
|
}
|
173
173
|
|
174
174
|
/* Return _self_ - _p1_.*/
|
175
|
-
static VALUE r_mpfi_complex_sub (VALUE self, VALUE other){
|
175
|
+
static VALUE r_mpfi_complex_sub (VALUE self, VALUE other) {
|
176
176
|
MPFIComplex *ptr_self, *ptr_other, *ptr_ret;
|
177
177
|
VALUE ret;
|
178
178
|
r_mpfi_get_complex_struct(ptr_self, self);
|
@@ -183,7 +183,7 @@ static VALUE r_mpfi_complex_sub (VALUE self, VALUE other){
|
|
183
183
|
}
|
184
184
|
|
185
185
|
/* Return _self_ * _p1_.*/
|
186
|
-
static VALUE r_mpfi_complex_mul (VALUE self, VALUE other){
|
186
|
+
static VALUE r_mpfi_complex_mul (VALUE self, VALUE other) {
|
187
187
|
MPFIComplex *ptr_self, *ptr_other, *ptr_ret;
|
188
188
|
VALUE ret;
|
189
189
|
r_mpfi_get_complex_struct(ptr_self, self);
|
@@ -194,7 +194,7 @@ static VALUE r_mpfi_complex_mul (VALUE self, VALUE other){
|
|
194
194
|
}
|
195
195
|
|
196
196
|
/* Return _self_ / _p1_.*/
|
197
|
-
static VALUE r_mpfi_complex_div (VALUE self, VALUE other){
|
197
|
+
static VALUE r_mpfi_complex_div (VALUE self, VALUE other) {
|
198
198
|
MPFIComplex *ptr_self, *ptr_other, *ptr_ret;
|
199
199
|
VALUE ret;
|
200
200
|
r_mpfi_get_complex_struct(ptr_self, self);
|
@@ -205,7 +205,7 @@ static VALUE r_mpfi_complex_div (VALUE self, VALUE other){
|
|
205
205
|
}
|
206
206
|
|
207
207
|
|
208
|
-
void Init_complex(){
|
208
|
+
void Init_complex() {
|
209
209
|
VALUE tmp_mpfi_class = rb_define_class("MPFI", rb_cNumeric);
|
210
210
|
|
211
211
|
r_mpfi_complex = rb_define_class_under(tmp_mpfi_class, "Complex", rb_cObject);
|
@@ -237,6 +237,4 @@ void Init_complex(){
|
|
237
237
|
rb_define_alias(r_mpfi_complex, "/", "div");
|
238
238
|
|
239
239
|
object_id = rb_intern("object_id");
|
240
|
-
|
241
240
|
}
|
242
|
-
|
@@ -10,6 +10,6 @@
|
|
10
10
|
#define r_mpfi_complex_temp_alloc_init(mpfi_complex_var) { mpfi_complex_var = ALLOC_N(MPFIComplex, 1); mpfi_complex_init(mpfi_complex_var); }
|
11
11
|
#define r_mpfi_complex_temp_free(mpfi_complex_var) { mpfi_complex_clear(mpfi_complex_var); free(mpfi_complex_var); }
|
12
12
|
|
13
|
-
void r_mpfi_complex_free(void *ptr);
|
13
|
+
void r_mpfi_complex_free (void *ptr);
|
14
14
|
|
15
15
|
#endif
|
@@ -1,2 +1,2 @@
|
|
1
|
-
void mpfi_mid_interval(mpfi_t ret, mpfi_t x);
|
2
|
-
int mpfi_subdivision(int num, mpfi_t *ret, mpfi_t x);
|
1
|
+
void mpfi_mid_interval (mpfi_t ret, mpfi_t x);
|
2
|
+
int mpfi_subdivision (int num, mpfi_t *ret, mpfi_t x);
|
@@ -1,83 +1,83 @@
|
|
1
1
|
#include "ruby_mpfi_matrix.h"
|
2
2
|
|
3
|
-
void mpfi_matrix_init(MPFIMatrix *mat, int row, int column){
|
3
|
+
void mpfi_matrix_init (MPFIMatrix *mat, int row, int column) {
|
4
4
|
int i;
|
5
5
|
mat->row = row;
|
6
6
|
mat->column = column;
|
7
7
|
mat->size = row * column;
|
8
8
|
/* mat->data = (MPFI *)malloc(sizeof(MPFI) * mat->size); */
|
9
9
|
mat->data = ALLOC_N(MPFI, mat->size);
|
10
|
-
for(i = 0; i < mat->size; i++){
|
10
|
+
for (i = 0; i < mat->size; i++) {
|
11
11
|
mpfi_init(mat->data + i);
|
12
12
|
}
|
13
13
|
}
|
14
14
|
|
15
|
-
void mpfi_matrix_set_zeros(MPFIMatrix *mat){
|
15
|
+
void mpfi_matrix_set_zeros (MPFIMatrix *mat) {
|
16
16
|
int i;
|
17
|
-
for(i = 0; i < mat->size; i++){
|
17
|
+
for (i = 0; i < mat->size; i++) {
|
18
18
|
mpfi_set_si(mat->data + i, 0);
|
19
19
|
}
|
20
20
|
}
|
21
21
|
|
22
|
-
void mpfi_matrix_clear(MPFIMatrix *mat){
|
22
|
+
void mpfi_matrix_clear (MPFIMatrix *mat) {
|
23
23
|
int i;
|
24
|
-
for(i = 0; i < mat->size; i++){
|
24
|
+
for (i = 0; i < mat->size; i++) {
|
25
25
|
mpfi_clear(mat->data + i);
|
26
26
|
}
|
27
27
|
free(mat->data);
|
28
28
|
}
|
29
29
|
|
30
|
-
void mpfi_matrix_set_element(MPFIMatrix *mat, int row, int col, MPFI *a){
|
30
|
+
void mpfi_matrix_set_element (MPFIMatrix *mat, int row, int col, MPFI *a) {
|
31
31
|
mpfi_set(mpfi_matrix_get_element(mat, row, col), a);
|
32
32
|
}
|
33
33
|
|
34
|
-
void mpfi_matrix_set(MPFIMatrix *new, MPFIMatrix *x){
|
34
|
+
void mpfi_matrix_set (MPFIMatrix *new, MPFIMatrix *x) {
|
35
35
|
int i;
|
36
|
-
for(i = 0; i < x->size; i++){
|
36
|
+
for (i = 0; i < x->size; i++) {
|
37
37
|
mpfi_set(new->data + i, x->data + i);
|
38
38
|
}
|
39
39
|
}
|
40
40
|
|
41
|
-
void mpfi_matrix_swap(MPFIMatrix *x, MPFIMatrix *y){
|
41
|
+
void mpfi_matrix_swap (MPFIMatrix *x, MPFIMatrix *y) {
|
42
42
|
int i;
|
43
43
|
for (i = 0; i < x->size; i++) {
|
44
44
|
mpfi_swap(mpfi_matrix_get_ptr(x, i), mpfi_matrix_get_ptr(y, i));
|
45
45
|
}
|
46
46
|
}
|
47
47
|
|
48
|
-
void mpfi_matrix_row(MPFIMatrix *new, MPFIMatrix *x, int row){
|
48
|
+
void mpfi_matrix_row (MPFIMatrix *new, MPFIMatrix *x, int row) {
|
49
49
|
int i;
|
50
50
|
for (i = 0; i < x->column; i++) {
|
51
51
|
mpfi_set(new->data + i, mpfi_matrix_get_element(x, row, i));
|
52
52
|
}
|
53
53
|
}
|
54
54
|
|
55
|
-
void mpfi_matrix_column(MPFIMatrix *new, MPFIMatrix *x, int column){
|
55
|
+
void mpfi_matrix_column (MPFIMatrix *new, MPFIMatrix *x, int column) {
|
56
56
|
int i;
|
57
57
|
for (i = 0; i < x->row; i++) {
|
58
58
|
mpfi_set(new->data + i, mpfi_matrix_get_element(x, i, column));
|
59
59
|
}
|
60
60
|
}
|
61
61
|
|
62
|
-
void mpfi_matrix_transpose(MPFIMatrix *new, MPFIMatrix *x){
|
62
|
+
void mpfi_matrix_transpose (MPFIMatrix *new, MPFIMatrix *x) {
|
63
63
|
int i, j, index;
|
64
|
-
for(j = 0; j < x->column; j++){
|
64
|
+
for (j = 0; j < x->column; j++) {
|
65
65
|
index = j * x->row;
|
66
|
-
for(i = 0; i < x->row; i++){
|
66
|
+
for (i = 0; i < x->row; i++) {
|
67
67
|
mpfi_set(new->data + j + i * new->row, x->data + i + index);
|
68
68
|
}
|
69
69
|
}
|
70
70
|
}
|
71
71
|
|
72
|
-
void mpfi_matrix_neg(MPFIMatrix *new, MPFIMatrix *x){
|
72
|
+
void mpfi_matrix_neg (MPFIMatrix *new, MPFIMatrix *x) {
|
73
73
|
int i;
|
74
|
-
for(i = 0; i < x->size; i++){
|
74
|
+
for (i = 0; i < x->size; i++) {
|
75
75
|
mpfi_neg(new->data + i, x->data + i);
|
76
76
|
}
|
77
77
|
}
|
78
78
|
|
79
79
|
/* Return 0 if *x and *y has the same elements. Otherwise return 1. */
|
80
|
-
int mpfi_matrix_equal_p(MPFIMatrix *x, MPFIMatrix *y){
|
80
|
+
int mpfi_matrix_equal_p (MPFIMatrix *x, MPFIMatrix *y) {
|
81
81
|
int i, ret = 0;
|
82
82
|
if (x->column == y->column && x->row == y->row) {
|
83
83
|
for (i = 0; i < x->size; i++) {
|
@@ -87,65 +87,65 @@ int mpfi_matrix_equal_p(MPFIMatrix *x, MPFIMatrix *y){
|
|
87
87
|
break;
|
88
88
|
}
|
89
89
|
}
|
90
|
-
}else{
|
90
|
+
} else {
|
91
91
|
ret = 1;
|
92
92
|
}
|
93
93
|
return ret;
|
94
94
|
}
|
95
95
|
|
96
|
-
void mpfi_matrix_add(MPFIMatrix *new, MPFIMatrix *x, MPFIMatrix *y){
|
96
|
+
void mpfi_matrix_add (MPFIMatrix *new, MPFIMatrix *x, MPFIMatrix *y) {
|
97
97
|
int i, j, index;
|
98
|
-
for(j = 0; j < x->column; j++){
|
98
|
+
for (j = 0; j < x->column; j++) {
|
99
99
|
index = j * x->row;
|
100
|
-
for(i = 0; i < x->row; i++){
|
100
|
+
for (i = 0; i < x->row; i++) {
|
101
101
|
mpfi_add(new->data + i + index, x->data + i + index, y->data + i + index);
|
102
102
|
}
|
103
103
|
}
|
104
104
|
}
|
105
105
|
|
106
|
-
void mpfi_matrix_add_fr(MPFIMatrix *new, MPFIMatrix *x, MPFRMatrix *y){
|
106
|
+
void mpfi_matrix_add_fr (MPFIMatrix *new, MPFIMatrix *x, MPFRMatrix *y) {
|
107
107
|
int i, j, index;
|
108
|
-
for(j = 0; j < x->column; j++){
|
108
|
+
for (j = 0; j < x->column; j++) {
|
109
109
|
index = j * x->row;
|
110
|
-
for(i = 0; i < x->row; i++){
|
110
|
+
for (i = 0; i < x->row; i++) {
|
111
111
|
mpfi_add_fr(new->data + i + index, x->data + i + index, y->data + i + index);
|
112
112
|
}
|
113
113
|
}
|
114
114
|
}
|
115
115
|
|
116
|
-
void mpfi_matrix_sub(MPFIMatrix *new, MPFIMatrix *x, MPFIMatrix *y){
|
116
|
+
void mpfi_matrix_sub (MPFIMatrix *new, MPFIMatrix *x, MPFIMatrix *y) {
|
117
117
|
int i, j, index;
|
118
|
-
for(j = 0; j < x->column; j++){
|
118
|
+
for (j = 0; j < x->column; j++) {
|
119
119
|
index = j * x->row;
|
120
|
-
for(i = 0; i < x->row; i++){
|
120
|
+
for (i = 0; i < x->row; i++) {
|
121
121
|
mpfi_sub(new->data + i + index, x->data + i + index, y->data + i + index);
|
122
122
|
}
|
123
123
|
}
|
124
124
|
}
|
125
125
|
|
126
|
-
void mpfi_matrix_sub_fr(MPFIMatrix *new, MPFIMatrix *x, MPFRMatrix *y){
|
126
|
+
void mpfi_matrix_sub_fr (MPFIMatrix *new, MPFIMatrix *x, MPFRMatrix *y) {
|
127
127
|
int i, j, index;
|
128
|
-
for(j = 0; j < x->column; j++){
|
128
|
+
for (j = 0; j < x->column; j++) {
|
129
129
|
index = j * x->row;
|
130
|
-
for(i = 0; i < x->row; i++){
|
130
|
+
for (i = 0; i < x->row; i++) {
|
131
131
|
mpfi_sub_fr(new->data + i + index, x->data + i + index, y->data + i + index);
|
132
132
|
}
|
133
133
|
}
|
134
134
|
}
|
135
135
|
|
136
136
|
/* x and new must be different pointer from each other. */
|
137
|
-
void mpfi_matrix_mul(MPFIMatrix *new, MPFIMatrix *x, MPFIMatrix *y){
|
137
|
+
void mpfi_matrix_mul (MPFIMatrix *new, MPFIMatrix *x, MPFIMatrix *y) {
|
138
138
|
int i, j, k, index, index_y;
|
139
139
|
MPFI *tmp;
|
140
140
|
r_mpfi_temp_alloc_init(tmp);
|
141
|
-
for(i = 0; i < new->size; i++){
|
141
|
+
for (i = 0; i < new->size; i++) {
|
142
142
|
mpfi_set_si(new->data + i, 0);
|
143
143
|
}
|
144
|
-
for(j = 0; j < y->column; j++){
|
145
|
-
for(i = 0; i < x->row; i++){
|
144
|
+
for (j = 0; j < y->column; j++) {
|
145
|
+
for (i = 0; i < x->row; i++) {
|
146
146
|
index = i + j * new->row;
|
147
147
|
index_y = j * y->row;
|
148
|
-
for(k = 0; k < x->column; k++){
|
148
|
+
for (k = 0; k < x->column; k++) {
|
149
149
|
mpfi_mul(tmp, x->data + i + k * x->row, y->data + k + index_y);
|
150
150
|
mpfi_add(new->data + index, new->data + index, tmp);
|
151
151
|
}
|
@@ -155,18 +155,18 @@ void mpfi_matrix_mul(MPFIMatrix *new, MPFIMatrix *x, MPFIMatrix *y){
|
|
155
155
|
}
|
156
156
|
|
157
157
|
/* x and new must be different pointer from each other. */
|
158
|
-
void mpfi_matrix_mul_fr(MPFIMatrix *new, MPFIMatrix *x, MPFRMatrix *y){
|
158
|
+
void mpfi_matrix_mul_fr (MPFIMatrix *new, MPFIMatrix *x, MPFRMatrix *y) {
|
159
159
|
int i, j, k, index, index_y;
|
160
160
|
MPFI *tmp;
|
161
161
|
r_mpfi_temp_alloc_init(tmp);
|
162
|
-
for(i = 0; i < new->size; i++){
|
162
|
+
for (i = 0; i < new->size; i++) {
|
163
163
|
mpfi_set_si(new->data + i, 0);
|
164
164
|
}
|
165
|
-
for(j = 0; j < y->column; j++){
|
166
|
-
for(i = 0; i < x->row; i++){
|
165
|
+
for (j = 0; j < y->column; j++) {
|
166
|
+
for (i = 0; i < x->row; i++) {
|
167
167
|
index = i + j * new->row;
|
168
168
|
index_y = j * y->row;
|
169
|
-
for(k = 0; k < x->column; k++){
|
169
|
+
for (k = 0; k < x->column; k++) {
|
170
170
|
mpfi_mul_fr(tmp, x->data + i + k * x->row, y->data + k + index_y);
|
171
171
|
mpfi_add(new->data + index, new->data + index, tmp);
|
172
172
|
}
|
@@ -175,22 +175,22 @@ void mpfi_matrix_mul_fr(MPFIMatrix *new, MPFIMatrix *x, MPFRMatrix *y){
|
|
175
175
|
r_mpfi_temp_free(tmp);
|
176
176
|
}
|
177
177
|
|
178
|
-
void mpfi_matrix_mul_scalar(MPFIMatrix *new, MPFIMatrix *x, MPFI *scalar){
|
178
|
+
void mpfi_matrix_mul_scalar (MPFIMatrix *new, MPFIMatrix *x, MPFI *scalar) {
|
179
179
|
int i;
|
180
|
-
for(i = 0; i < x->size; i++){
|
180
|
+
for (i = 0; i < x->size; i++) {
|
181
181
|
mpfi_mul(new->data + i, x->data + i, scalar);
|
182
182
|
}
|
183
183
|
}
|
184
184
|
|
185
|
-
void mpfi_matrix_div_scalar(MPFIMatrix *new, MPFIMatrix *x, MPFI *scalar){
|
185
|
+
void mpfi_matrix_div_scalar (MPFIMatrix *new, MPFIMatrix *x, MPFI *scalar) {
|
186
186
|
int i;
|
187
|
-
for(i = 0; i < x->size; i++){
|
187
|
+
for (i = 0; i < x->size; i++) {
|
188
188
|
mpfi_div(new->data + i, x->data + i, scalar);
|
189
189
|
}
|
190
190
|
}
|
191
191
|
|
192
192
|
/* Return 0 if *x includes *y. Otherwise return 1. */
|
193
|
-
int mpfi_matrix_include_p(MPFIMatrix *x, MPFIMatrix *y){
|
193
|
+
int mpfi_matrix_include_p (MPFIMatrix *x, MPFIMatrix *y) {
|
194
194
|
int i, ret = 0;
|
195
195
|
if (x->column == y->column && x->row == y->row) {
|
196
196
|
for (i = 0; i < x->size; i++) {
|
@@ -199,14 +199,14 @@ int mpfi_matrix_include_p(MPFIMatrix *x, MPFIMatrix *y){
|
|
199
199
|
break;
|
200
200
|
}
|
201
201
|
}
|
202
|
-
}else{
|
202
|
+
} else {
|
203
203
|
ret = 1;
|
204
204
|
}
|
205
205
|
return ret;
|
206
206
|
}
|
207
207
|
|
208
208
|
/* Return 0 if *x includes *y. Otherwise return 1. */
|
209
|
-
int mpfi_matrix_include_fr_p(MPFIMatrix *x, MPFRMatrix *y){
|
209
|
+
int mpfi_matrix_include_fr_p (MPFIMatrix *x, MPFRMatrix *y) {
|
210
210
|
int i, ret = 0;
|
211
211
|
if (x->column == y->column && x->row == y->row) {
|
212
212
|
for (i = 0; i < x->size; i++) {
|
@@ -215,14 +215,14 @@ int mpfi_matrix_include_fr_p(MPFIMatrix *x, MPFRMatrix *y){
|
|
215
215
|
break;
|
216
216
|
}
|
217
217
|
}
|
218
|
-
}else{
|
218
|
+
} else {
|
219
219
|
ret = 1;
|
220
220
|
}
|
221
221
|
return ret;
|
222
222
|
}
|
223
223
|
|
224
224
|
/* Return 0 if *x includes *y. Otherwise return 1. */
|
225
|
-
int mpfi_matrix_strictly_include_p(MPFIMatrix *x, MPFIMatrix *y){
|
225
|
+
int mpfi_matrix_strictly_include_p (MPFIMatrix *x, MPFIMatrix *y) {
|
226
226
|
int i, ret = 0;
|
227
227
|
if (x->column == y->column && x->row == y->row) {
|
228
228
|
for (i = 0; i < x->size; i++) {
|
@@ -231,14 +231,14 @@ int mpfi_matrix_strictly_include_p(MPFIMatrix *x, MPFIMatrix *y){
|
|
231
231
|
break;
|
232
232
|
}
|
233
233
|
}
|
234
|
-
}else{
|
234
|
+
} else {
|
235
235
|
ret = 1;
|
236
236
|
}
|
237
237
|
return ret;
|
238
238
|
}
|
239
239
|
|
240
240
|
/* Return 0 if *x is bonded. Otherwise return 1. */
|
241
|
-
int mpfi_matrix_bounded_p(MPFIMatrix *x){
|
241
|
+
int mpfi_matrix_bounded_p (MPFIMatrix *x) {
|
242
242
|
int ret = 0, i;
|
243
243
|
for (i = 0; i < x->size; i++) {
|
244
244
|
if (mpfi_bounded_p(x->data + i) == 0) {
|
@@ -249,78 +249,78 @@ int mpfi_matrix_bounded_p(MPFIMatrix *x){
|
|
249
249
|
return ret;
|
250
250
|
}
|
251
251
|
|
252
|
-
void mpfi_matrix_mid(MPFRMatrix *ret, MPFIMatrix *x){
|
252
|
+
void mpfi_matrix_mid (MPFRMatrix *ret, MPFIMatrix *x) {
|
253
253
|
int i;
|
254
|
-
for(i = 0; i < x->size; i++){
|
254
|
+
for (i = 0; i < x->size; i++) {
|
255
255
|
mpfi_mid(ret->data + i, x->data + i);
|
256
256
|
}
|
257
257
|
}
|
258
258
|
|
259
|
-
void mpfi_matrix_mid_interval(MPFIMatrix *ret, MPFIMatrix *x){
|
259
|
+
void mpfi_matrix_mid_interval (MPFIMatrix *ret, MPFIMatrix *x) {
|
260
260
|
int i;
|
261
|
-
for(i = 0; i < x->size; i++){
|
261
|
+
for (i = 0; i < x->size; i++) {
|
262
262
|
mpfi_mid_interval(ret->data + i, x->data + i);
|
263
263
|
}
|
264
264
|
}
|
265
265
|
|
266
|
-
void mpfi_matrix_from_mpfr_matrix(MPFIMatrix *ret, MPFRMatrix *x){
|
266
|
+
void mpfi_matrix_from_mpfr_matrix (MPFIMatrix *ret, MPFRMatrix *x) {
|
267
267
|
int i;
|
268
|
-
for(i = 0; i < x->size; i++){
|
268
|
+
for (i = 0; i < x->size; i++) {
|
269
269
|
mpfi_set_fr(ret->data + i, x->data + i);
|
270
270
|
}
|
271
271
|
}
|
272
272
|
|
273
273
|
/* This function returns 0 if the intersection of two boxes exists. */
|
274
274
|
/* Otherwise, it returns nonzero. */
|
275
|
-
int mpfi_matrix_intersect(MPFIMatrix *z, MPFIMatrix *x, MPFIMatrix *y){
|
275
|
+
int mpfi_matrix_intersect (MPFIMatrix *z, MPFIMatrix *x, MPFIMatrix *y) {
|
276
276
|
int ret = 0;
|
277
277
|
int i;
|
278
278
|
if (x->column == y->column && x->row == y->row) {
|
279
|
-
for(i = 0; i < x->size; i++){
|
279
|
+
for (i = 0; i < x->size; i++) {
|
280
280
|
mpfi_intersect(z->data + i, x->data + i, y->data + i);
|
281
|
-
if(ret == 0 && mpfi_is_empty(z->data + i)){
|
281
|
+
if (ret == 0 && mpfi_is_empty(z->data + i)) {
|
282
282
|
ret = 1;
|
283
283
|
}
|
284
284
|
}
|
285
285
|
return ret;
|
286
|
-
}else{
|
286
|
+
} else {
|
287
287
|
return -1;
|
288
288
|
}
|
289
289
|
}
|
290
290
|
|
291
291
|
/* Return -1 if size of matrixies is not same. */
|
292
292
|
/* Otherwise, return 0 and set convex hull to MPFIMatrix *z. */
|
293
|
-
int mpfi_matrix_union(MPFIMatrix *z, MPFIMatrix *x, MPFIMatrix *y){
|
293
|
+
int mpfi_matrix_union (MPFIMatrix *z, MPFIMatrix *x, MPFIMatrix *y) {
|
294
294
|
int ret = 0;
|
295
295
|
int i;
|
296
296
|
if (x->column == y->column && x->row == y->row) {
|
297
|
-
for(i = 0; i < x->size; i++){
|
297
|
+
for (i = 0; i < x->size; i++) {
|
298
298
|
mpfi_union(z->data + i, x->data + i, y->data + i);
|
299
299
|
}
|
300
300
|
return ret;
|
301
|
-
}else{
|
301
|
+
} else {
|
302
302
|
return -1;
|
303
303
|
}
|
304
304
|
}
|
305
305
|
|
306
|
-
void mpfi_matrix_inner_product(MPFI *pr, MPFIMatrix *x, MPFIMatrix *y){
|
306
|
+
void mpfi_matrix_inner_product (MPFI *pr, MPFIMatrix *x, MPFIMatrix *y) {
|
307
307
|
MPFI *tmp;
|
308
308
|
int i;
|
309
309
|
r_mpfi_temp_alloc_init(tmp);
|
310
310
|
mpfi_set_si(pr, 0);
|
311
|
-
for(i = 0; i < x->size; i++){
|
311
|
+
for (i = 0; i < x->size; i++) {
|
312
312
|
mpfi_mul(tmp, x->data + i, y->data + i);
|
313
313
|
mpfi_add(pr, pr, tmp);
|
314
314
|
}
|
315
315
|
r_mpfi_temp_free(tmp);
|
316
316
|
}
|
317
317
|
|
318
|
-
void mpfi_matrix_vector_distance(MPFI *distance, MPFIMatrix *x, MPFIMatrix *y){
|
318
|
+
void mpfi_matrix_vector_distance (MPFI *distance, MPFIMatrix *x, MPFIMatrix *y) {
|
319
319
|
MPFI *tmp;
|
320
320
|
int i;
|
321
321
|
r_mpfi_temp_alloc_init(tmp);
|
322
322
|
mpfi_set_si(distance, 0);
|
323
|
-
for(i = 0; i < x->size; i++){
|
323
|
+
for (i = 0; i < x->size; i++) {
|
324
324
|
mpfi_sub(tmp, x->data + i, y->data + i);
|
325
325
|
mpfi_mul(tmp, tmp, tmp);
|
326
326
|
mpfi_add(distance, distance, tmp);
|
@@ -329,7 +329,7 @@ void mpfi_matrix_vector_distance(MPFI *distance, MPFIMatrix *x, MPFIMatrix *y){
|
|
329
329
|
r_mpfi_temp_free(tmp);
|
330
330
|
}
|
331
331
|
|
332
|
-
void mpfi_matrix_vector_distance_center_pts(MPFR *distance, MPFIMatrix *x, MPFIMatrix *y){
|
332
|
+
void mpfi_matrix_vector_distance_center_pts (MPFR *distance, MPFIMatrix *x, MPFIMatrix *y) {
|
333
333
|
MPFRMatrix *tmp_x, *tmp_y;
|
334
334
|
r_mpfr_matrix_temp_alloc_init(tmp_x, x->row, x->column);
|
335
335
|
r_mpfr_matrix_temp_alloc_init(tmp_y, y->row, y->column);
|
@@ -342,12 +342,12 @@ void mpfi_matrix_vector_distance_center_pts(MPFR *distance, MPFIMatrix *x, MPFIM
|
|
342
342
|
r_mpfr_matrix_temp_free(tmp_y);
|
343
343
|
}
|
344
344
|
|
345
|
-
void mpfi_matrix_vector_norm(MPFI *norm, MPFIMatrix *x){
|
345
|
+
void mpfi_matrix_vector_norm (MPFI *norm, MPFIMatrix *x) {
|
346
346
|
MPFI *tmp;
|
347
347
|
int i;
|
348
348
|
r_mpfi_temp_alloc_init(tmp);
|
349
349
|
mpfi_set_si(norm, 0);
|
350
|
-
for(i = 0; i < x->size; i++){
|
350
|
+
for (i = 0; i < x->size; i++) {
|
351
351
|
mpfi_mul(tmp, x->data + i, x->data + i);
|
352
352
|
mpfi_add(norm, norm, tmp);
|
353
353
|
}
|
@@ -355,20 +355,20 @@ void mpfi_matrix_vector_norm(MPFI *norm, MPFIMatrix *x){
|
|
355
355
|
r_mpfi_temp_free(tmp);
|
356
356
|
}
|
357
357
|
|
358
|
-
void mpfi_matrix_max_norm(MPFI *norm, MPFIMatrix *x){
|
358
|
+
void mpfi_matrix_max_norm (MPFI *norm, MPFIMatrix *x) {
|
359
359
|
MPFI *tmp, *abs;
|
360
360
|
int i;
|
361
361
|
r_mpfi_temp_alloc_init(tmp);
|
362
362
|
r_mpfi_temp_alloc_init(abs);
|
363
363
|
mpfi_set_si(norm, 0);
|
364
|
-
for(i = 0; i < x->size; i++){
|
364
|
+
for (i = 0; i < x->size; i++) {
|
365
365
|
mpfi_abs(abs, x->data + i);
|
366
366
|
mpfi_intersect(tmp, abs, norm);
|
367
|
-
if(mpfi_is_empty(tmp) > 0){
|
368
|
-
if(mpfr_cmp(r_mpfi_right_ptr(abs), r_mpfi_left_ptr(norm)) > 0){
|
367
|
+
if (mpfi_is_empty(tmp) > 0) {
|
368
|
+
if (mpfr_cmp(r_mpfi_right_ptr(abs), r_mpfi_left_ptr(norm)) > 0) {
|
369
369
|
mpfi_set(norm, abs);
|
370
370
|
}
|
371
|
-
}else{
|
371
|
+
} else {
|
372
372
|
mpfi_union(norm, norm, abs);
|
373
373
|
}
|
374
374
|
}
|
@@ -376,7 +376,7 @@ void mpfi_matrix_max_norm(MPFI *norm, MPFIMatrix *x){
|
|
376
376
|
r_mpfi_temp_free(abs);
|
377
377
|
}
|
378
378
|
|
379
|
-
void mpfi_matrix_max_diam_abs(MPFR *diam, MPFIMatrix *x){
|
379
|
+
void mpfi_matrix_max_diam_abs (MPFR *diam, MPFIMatrix *x) {
|
380
380
|
int i;
|
381
381
|
MPFR *tmp;
|
382
382
|
r_mpfr_temp_alloc_init(tmp);
|
@@ -384,7 +384,7 @@ void mpfi_matrix_max_diam_abs(MPFR *diam, MPFIMatrix *x){
|
|
384
384
|
mpfr_set_si(diam, 0, GMP_RNDN);
|
385
385
|
for (i = 0; i < x->size; i++) {
|
386
386
|
mpfi_diam_abs(tmp, x->data + i);
|
387
|
-
if(mpfr_cmp(tmp, diam) > 0){
|
387
|
+
if (mpfr_cmp(tmp, diam) > 0) {
|
388
388
|
mpfr_set(diam, tmp, GMP_RNDN);
|
389
389
|
}
|
390
390
|
}
|
@@ -394,32 +394,32 @@ void mpfi_matrix_max_diam_abs(MPFR *diam, MPFIMatrix *x){
|
|
394
394
|
|
395
395
|
/* ------------------- vector --------------------- */
|
396
396
|
|
397
|
-
void mpfi_col_vector_init(MPFIMatrix *mat, int row){
|
397
|
+
void mpfi_col_vector_init (MPFIMatrix *mat, int row) {
|
398
398
|
int i;
|
399
399
|
mat->row = row;
|
400
400
|
mat->column = 1;
|
401
401
|
mat->size = row;
|
402
402
|
/* mat->data = (MPFI *)malloc(sizeof(MPF) * mat->size); */
|
403
403
|
mat->data = ALLOC_N(MPFI, mat->size);
|
404
|
-
for(i = 0; i < mat->size; i++){
|
404
|
+
for (i = 0; i < mat->size; i++) {
|
405
405
|
mpfi_init(mat->data + i);
|
406
406
|
}
|
407
407
|
}
|
408
408
|
|
409
|
-
void mpfi_row_vector_init(MPFIMatrix *mat, int column){
|
409
|
+
void mpfi_row_vector_init (MPFIMatrix *mat, int column) {
|
410
410
|
int i;
|
411
411
|
mat->row = 1;
|
412
412
|
mat->column = column;
|
413
413
|
mat->size = column;
|
414
414
|
/* mat->data = (MPFI *)malloc(sizeof(MPF) * mat->size); */
|
415
415
|
mat->data = ALLOC_N(MPFI, mat->size);
|
416
|
-
for(i = 0; i < mat->size; i++){
|
416
|
+
for (i = 0; i < mat->size; i++) {
|
417
417
|
mpfi_init(mat->data + i);
|
418
418
|
}
|
419
419
|
}
|
420
420
|
|
421
421
|
/* If length of MPFIMatrix *x is zero, return 1. Otherwise return 0. */
|
422
|
-
int mpfi_vector_normalize(MPFIMatrix *new, MPFIMatrix *x){
|
422
|
+
int mpfi_vector_normalize (MPFIMatrix *new, MPFIMatrix *x) {
|
423
423
|
MPFRMatrix *fr_mat;
|
424
424
|
MPFR *norm;
|
425
425
|
int i, j, index, ret = 0;
|
@@ -427,14 +427,14 @@ int mpfi_vector_normalize(MPFIMatrix *new, MPFIMatrix *x){
|
|
427
427
|
mpfi_matrix_mid(fr_mat, x);
|
428
428
|
r_mpfr_temp_alloc_init(norm);
|
429
429
|
mpfr_matrix_vector_norm(norm, fr_mat);
|
430
|
-
if(mpfr_cmp_ui(norm, 0) > 0){
|
431
|
-
for(j = 0; j < x->column; j++){
|
430
|
+
if (mpfr_cmp_ui(norm, 0) > 0) {
|
431
|
+
for (j = 0; j < x->column; j++) {
|
432
432
|
index = j * x->row;
|
433
|
-
for(i = 0; i < x->row; i++){
|
433
|
+
for (i = 0; i < x->row; i++) {
|
434
434
|
mpfi_div_fr(new->data + i + index, x->data + i + index, norm);
|
435
435
|
}
|
436
436
|
}
|
437
|
-
}else{
|
437
|
+
} else {
|
438
438
|
ret = 1;
|
439
439
|
}
|
440
440
|
r_mpfr_matrix_temp_free(fr_mat);
|
@@ -442,7 +442,7 @@ int mpfi_vector_normalize(MPFIMatrix *new, MPFIMatrix *x){
|
|
442
442
|
return ret;
|
443
443
|
}
|
444
444
|
|
445
|
-
void mpfi_vector_midpoint(MPFIMatrix *new, MPFIMatrix *x, MPFIMatrix *y){
|
445
|
+
void mpfi_vector_midpoint (MPFIMatrix *new, MPFIMatrix *x, MPFIMatrix *y) {
|
446
446
|
int i;
|
447
447
|
for (i = 0; i < new->size; i++) {
|
448
448
|
mpfi_add(mpfi_matrix_get_ptr(new, i), mpfi_matrix_get_ptr(x, i), mpfi_matrix_get_ptr(y, i));
|
@@ -451,7 +451,7 @@ void mpfi_vector_midpoint(MPFIMatrix *new, MPFIMatrix *x, MPFIMatrix *y){
|
|
451
451
|
}
|
452
452
|
|
453
453
|
/* If length of MPFIMatrix *x is zero, return 1. Otherwise return 0. */
|
454
|
-
int mpfi_vector_set_length(MPFIMatrix *new, MPFIMatrix *x, MPFR *length){
|
454
|
+
int mpfi_vector_set_length (MPFIMatrix *new, MPFIMatrix *x, MPFR *length) {
|
455
455
|
MPFI *norm_i;
|
456
456
|
MPFR *factor_r;
|
457
457
|
int i, j, index, ret = 0;
|
@@ -459,16 +459,16 @@ int mpfi_vector_set_length(MPFIMatrix *new, MPFIMatrix *x, MPFR *length){
|
|
459
459
|
r_mpfr_temp_alloc_init(factor_r);
|
460
460
|
mpfi_matrix_vector_norm(norm_i, x);
|
461
461
|
mpfi_mid(factor_r, norm_i);
|
462
|
-
if(mpfr_cmp_ui(factor_r, 0) > 0){
|
462
|
+
if (mpfr_cmp_ui(factor_r, 0) > 0) {
|
463
463
|
mpfr_ui_div(factor_r, 1, factor_r, GMP_RNDN);
|
464
464
|
mpfr_mul(factor_r, factor_r, length, GMP_RNDN);
|
465
|
-
for(j = 0; j < x->column; j++){
|
465
|
+
for (j = 0; j < x->column; j++) {
|
466
466
|
index = j * x->row;
|
467
|
-
for(i = 0; i < x->row; i++){
|
467
|
+
for (i = 0; i < x->row; i++) {
|
468
468
|
mpfi_mul_fr(new->data + i + index, x->data + i + index, factor_r);
|
469
469
|
}
|
470
470
|
}
|
471
|
-
}else{
|
471
|
+
} else {
|
472
472
|
ret = 1;
|
473
473
|
}
|
474
474
|
r_mpfi_temp_free(norm_i);
|
@@ -480,7 +480,7 @@ int mpfi_vector_set_length(MPFIMatrix *new, MPFIMatrix *x, MPFR *length){
|
|
480
480
|
|
481
481
|
/* Return 0 if we execute even permutation for matrix, 1 if odd permutation or */
|
482
482
|
/* -1 if matrix is singular. */
|
483
|
-
int mpfi_square_matrix_lu_decomp (MPFIMatrix *ret, int *indx, MPFIMatrix *x){
|
483
|
+
int mpfi_square_matrix_lu_decomp (MPFIMatrix *ret, int *indx, MPFIMatrix *x) {
|
484
484
|
int i, j, k, imax, ret_val = 0;
|
485
485
|
MPFI *big, *sum, *dum, *tmp1, *tmp2;
|
486
486
|
MPFIMatrix *vv, *tmp_ret;
|
@@ -500,11 +500,11 @@ int mpfi_square_matrix_lu_decomp (MPFIMatrix *ret, int *indx, MPFIMatrix *x){
|
|
500
500
|
mpfi_abs(tmp1, mpfi_matrix_get_element(x, i, j));
|
501
501
|
|
502
502
|
mpfi_intersect(tmp2, tmp1, big);
|
503
|
-
if(mpfi_is_empty(tmp2) > 0){
|
504
|
-
if(mpfr_cmp(r_mpfi_right_ptr(tmp1), r_mpfi_left_ptr(big)) > 0){
|
503
|
+
if (mpfi_is_empty(tmp2) > 0) {
|
504
|
+
if (mpfr_cmp(r_mpfi_right_ptr(tmp1), r_mpfi_left_ptr(big)) > 0) {
|
505
505
|
mpfi_set(big, tmp1);
|
506
506
|
}
|
507
|
-
}else{
|
507
|
+
} else {
|
508
508
|
mpfi_union(big, tmp1, big);
|
509
509
|
}
|
510
510
|
}
|
@@ -538,12 +538,12 @@ int mpfi_square_matrix_lu_decomp (MPFIMatrix *ret, int *indx, MPFIMatrix *x){
|
|
538
538
|
mpfi_mul(dum, vv->data + i, dum);
|
539
539
|
|
540
540
|
mpfi_intersect(tmp2, dum, big);
|
541
|
-
if(mpfi_is_empty(tmp2) > 0){
|
542
|
-
if(mpfr_cmp(r_mpfi_right_ptr(dum), r_mpfi_left_ptr(big)) > 0){
|
541
|
+
if (mpfi_is_empty(tmp2) > 0) {
|
542
|
+
if (mpfr_cmp(r_mpfi_right_ptr(dum), r_mpfi_left_ptr(big)) > 0) {
|
543
543
|
mpfi_set(big, dum);
|
544
544
|
imax = i;
|
545
545
|
}
|
546
|
-
}else{
|
546
|
+
} else {
|
547
547
|
mpfi_union(big, dum, big);
|
548
548
|
imax = i;
|
549
549
|
}
|
@@ -582,7 +582,7 @@ int mpfi_square_matrix_lu_decomp (MPFIMatrix *ret, int *indx, MPFIMatrix *x){
|
|
582
582
|
return ret_val;
|
583
583
|
}
|
584
584
|
|
585
|
-
static void mpfi_2d_square_matrix_determinant(MPFI *det, MPFIMatrix *x){
|
585
|
+
static void mpfi_2d_square_matrix_determinant (MPFI *det, MPFIMatrix *x) {
|
586
586
|
MPFI *tmp;
|
587
587
|
r_mpfi_temp_alloc_init(tmp);
|
588
588
|
mpfi_mul(det, x->data, x->data + 3);
|
@@ -591,7 +591,7 @@ static void mpfi_2d_square_matrix_determinant(MPFI *det, MPFIMatrix *x){
|
|
591
591
|
r_mpfi_temp_free(tmp);
|
592
592
|
}
|
593
593
|
|
594
|
-
static void mpfi_3d_square_matrix_determinant(MPFI *det, MPFIMatrix *x){
|
594
|
+
static void mpfi_3d_square_matrix_determinant (MPFI *det, MPFIMatrix *x) {
|
595
595
|
MPFI *tmp;
|
596
596
|
r_mpfi_temp_alloc_init(tmp);
|
597
597
|
|
@@ -622,17 +622,17 @@ static void mpfi_3d_square_matrix_determinant(MPFI *det, MPFIMatrix *x){
|
|
622
622
|
r_mpfi_temp_free(tmp);
|
623
623
|
}
|
624
624
|
|
625
|
-
void mpfi_square_matrix_determinant(MPFI *det, MPFIMatrix *x){
|
626
|
-
if (x->column == 2 && x->row == 2){
|
625
|
+
void mpfi_square_matrix_determinant (MPFI *det, MPFIMatrix *x) {
|
626
|
+
if (x->column == 2 && x->row == 2) {
|
627
627
|
mpfi_2d_square_matrix_determinant(det, x);
|
628
|
-
}else if(x->column == 3 && x->row == 3){
|
628
|
+
} else if (x->column == 3 && x->row == 3) {
|
629
629
|
mpfi_3d_square_matrix_determinant(det, x);
|
630
|
-
}else{
|
630
|
+
} else {
|
631
631
|
MPFIMatrix *ptr_lu;
|
632
632
|
int *indx, i;
|
633
633
|
r_mpfi_matrix_temp_alloc_init(ptr_lu, x->row, x->column);
|
634
634
|
indx = (int *) malloc(sizeof(int) * x->row);
|
635
|
-
if((i = mpfi_square_matrix_lu_decomp (ptr_lu, indx, x)) >= 0){
|
635
|
+
if ((i = mpfi_square_matrix_lu_decomp (ptr_lu, indx, x)) >= 0) {
|
636
636
|
if (i == 0) {
|
637
637
|
mpfi_set_si(det, 1);
|
638
638
|
} else if (i == 1) {
|
@@ -641,7 +641,7 @@ void mpfi_square_matrix_determinant(MPFI *det, MPFIMatrix *x){
|
|
641
641
|
for (i = 0; i < x->row; i++) {
|
642
642
|
mpfi_mul(det, det, mpfi_matrix_get_element(ptr_lu, i, i));
|
643
643
|
}
|
644
|
-
}else{
|
644
|
+
} else {
|
645
645
|
mpfi_set_ui(det, 0);
|
646
646
|
}
|
647
647
|
r_mpfi_matrix_temp_free(ptr_lu);
|
@@ -649,7 +649,7 @@ void mpfi_square_matrix_determinant(MPFI *det, MPFIMatrix *x){
|
|
649
649
|
}
|
650
650
|
}
|
651
651
|
|
652
|
-
void mpfi_square_matrix_qr_decomp(MPFIMatrix *q, MPFIMatrix *r, MPFIMatrix *x){
|
652
|
+
void mpfi_square_matrix_qr_decomp (MPFIMatrix *q, MPFIMatrix *r, MPFIMatrix *x) {
|
653
653
|
MPFIMatrix *q_mat, *r_mat;
|
654
654
|
int size, i, j, k, ind1, ind2, ind3;
|
655
655
|
MPFIMatrix *ary;
|
@@ -696,14 +696,14 @@ void mpfi_square_matrix_qr_decomp(MPFIMatrix *q, MPFIMatrix *r, MPFIMatrix *x){
|
|
696
696
|
r_mpfi_temp_free(tmp);
|
697
697
|
}
|
698
698
|
|
699
|
-
void mpfi_square_matrix_identity(MPFIMatrix *id){
|
699
|
+
void mpfi_square_matrix_identity (MPFIMatrix *id) {
|
700
700
|
int i, j, index;
|
701
701
|
for (j = 0; j < id->column; j++) {
|
702
702
|
index = j * id->row;
|
703
703
|
for (i = 0; i < id->row; i++) {
|
704
|
-
if(i == j){
|
704
|
+
if (i == j) {
|
705
705
|
mpfi_set_si(id->data + i + index, 1);
|
706
|
-
}else{
|
706
|
+
} else {
|
707
707
|
mpfi_set_si(id->data + i + index, 0);
|
708
708
|
}
|
709
709
|
}
|