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
@@ -43,55 +43,54 @@ typedef struct __MPFIMatrix{
|
|
43
43
|
/* (for example, mpfi_matrix_transpose), */
|
44
44
|
/* you must use differnt pointer for returned value from that of an argument. */
|
45
45
|
|
46
|
-
void mpfi_matrix_clear(MPFIMatrix *mat);
|
47
|
-
void mpfi_matrix_init(MPFIMatrix *mat, int row, int column);
|
48
|
-
void mpfi_matrix_set_zeros(MPFIMatrix *mat);
|
49
|
-
void mpfi_matrix_set_element(MPFIMatrix *mat, int row, int col, MPFI *a);
|
50
|
-
void mpfi_matrix_set(MPFIMatrix *new, MPFIMatrix *x);
|
51
|
-
void mpfi_matrix_swap(MPFIMatrix *x, MPFIMatrix *y);
|
52
|
-
|
53
|
-
void mpfi_matrix_row(MPFIMatrix *new, MPFIMatrix *x, int row);
|
54
|
-
void mpfi_matrix_column(MPFIMatrix *new, MPFIMatrix *x, int column);
|
55
|
-
void mpfi_matrix_transpose(MPFIMatrix *new, MPFIMatrix *x);
|
56
|
-
void mpfi_matrix_neg(MPFIMatrix *new, MPFIMatrix *x);
|
57
|
-
|
58
|
-
int mpfi_matrix_equal_p(MPFIMatrix *x, MPFIMatrix *y);
|
59
|
-
void mpfi_matrix_add(MPFIMatrix *new, MPFIMatrix *x, MPFIMatrix *y);
|
60
|
-
void mpfi_matrix_add_fr(MPFIMatrix *new, MPFIMatrix *x, MPFRMatrix *y);
|
61
|
-
void mpfi_matrix_sub(MPFIMatrix *new, MPFIMatrix *x, MPFIMatrix *y);
|
62
|
-
void mpfi_matrix_sub_fr(MPFIMatrix *new, MPFIMatrix *x, MPFRMatrix *y);
|
63
|
-
void mpfi_matrix_mul(MPFIMatrix *new, MPFIMatrix *x, MPFIMatrix *y);
|
64
|
-
void mpfi_matrix_mul_fr(MPFIMatrix *new, MPFIMatrix *x, MPFRMatrix *y);
|
65
|
-
void mpfi_matrix_mul_scalar(MPFIMatrix *new, MPFIMatrix *x, MPFI *scalar);
|
66
|
-
void mpfi_matrix_div_scalar(MPFIMatrix *new, MPFIMatrix *x, MPFI *scalar);
|
67
|
-
|
68
|
-
int mpfi_matrix_include_p(MPFIMatrix *x, MPFIMatrix *y);
|
69
|
-
int mpfi_matrix_include_fr_p(MPFIMatrix *x, MPFRMatrix *y);
|
70
|
-
int mpfi_matrix_strictly_include_p(MPFIMatrix *x, MPFIMatrix *y);
|
71
|
-
int mpfi_matrix_bounded_p(MPFIMatrix *x);
|
72
|
-
void mpfi_matrix_mid(MPFRMatrix *ret, MPFIMatrix *x);
|
73
|
-
void mpfi_matrix_mid_interval(MPFIMatrix *ret, MPFIMatrix *x);
|
74
|
-
void mpfi_matrix_from_mpfr_matrix(MPFIMatrix *ret, MPFRMatrix *x);
|
75
|
-
int mpfi_matrix_intersect(MPFIMatrix *ret, MPFIMatrix *x, MPFIMatrix *y);
|
76
|
-
int mpfi_matrix_union(MPFIMatrix *z, MPFIMatrix *x, MPFIMatrix *y);
|
77
|
-
|
78
|
-
void mpfi_matrix_inner_product(MPFI *pr, MPFIMatrix *x, MPFIMatrix *y);
|
79
|
-
void mpfi_matrix_vector_distance(MPFI *distance, MPFIMatrix *x, MPFIMatrix *y);
|
80
|
-
void mpfi_matrix_vector_distance_center_pts(MPFR *distance, MPFIMatrix *x, MPFIMatrix *y);
|
81
|
-
void mpfi_matrix_vector_norm(MPFI *norm, MPFIMatrix *x);
|
82
|
-
void mpfi_matrix_max_norm(MPFI *norm, MPFIMatrix *x);
|
83
|
-
void mpfi_matrix_max_diam_abs(MPFR *diam, MPFIMatrix *x);
|
46
|
+
void mpfi_matrix_clear (MPFIMatrix *mat);
|
47
|
+
void mpfi_matrix_init (MPFIMatrix *mat, int row, int column);
|
48
|
+
void mpfi_matrix_set_zeros (MPFIMatrix *mat);
|
49
|
+
void mpfi_matrix_set_element (MPFIMatrix *mat, int row, int col, MPFI *a);
|
50
|
+
void mpfi_matrix_set (MPFIMatrix *new, MPFIMatrix *x);
|
51
|
+
void mpfi_matrix_swap (MPFIMatrix *x, MPFIMatrix *y);
|
52
|
+
|
53
|
+
void mpfi_matrix_row (MPFIMatrix *new, MPFIMatrix *x, int row);
|
54
|
+
void mpfi_matrix_column (MPFIMatrix *new, MPFIMatrix *x, int column);
|
55
|
+
void mpfi_matrix_transpose (MPFIMatrix *new, MPFIMatrix *x);
|
56
|
+
void mpfi_matrix_neg (MPFIMatrix *new, MPFIMatrix *x);
|
57
|
+
|
58
|
+
int mpfi_matrix_equal_p (MPFIMatrix *x, MPFIMatrix *y);
|
59
|
+
void mpfi_matrix_add (MPFIMatrix *new, MPFIMatrix *x, MPFIMatrix *y);
|
60
|
+
void mpfi_matrix_add_fr (MPFIMatrix *new, MPFIMatrix *x, MPFRMatrix *y);
|
61
|
+
void mpfi_matrix_sub (MPFIMatrix *new, MPFIMatrix *x, MPFIMatrix *y);
|
62
|
+
void mpfi_matrix_sub_fr (MPFIMatrix *new, MPFIMatrix *x, MPFRMatrix *y);
|
63
|
+
void mpfi_matrix_mul (MPFIMatrix *new, MPFIMatrix *x, MPFIMatrix *y);
|
64
|
+
void mpfi_matrix_mul_fr (MPFIMatrix *new, MPFIMatrix *x, MPFRMatrix *y);
|
65
|
+
void mpfi_matrix_mul_scalar (MPFIMatrix *new, MPFIMatrix *x, MPFI *scalar);
|
66
|
+
void mpfi_matrix_div_scalar (MPFIMatrix *new, MPFIMatrix *x, MPFI *scalar);
|
67
|
+
|
68
|
+
int mpfi_matrix_include_p (MPFIMatrix *x, MPFIMatrix *y);
|
69
|
+
int mpfi_matrix_include_fr_p (MPFIMatrix *x, MPFRMatrix *y);
|
70
|
+
int mpfi_matrix_strictly_include_p (MPFIMatrix *x, MPFIMatrix *y);
|
71
|
+
int mpfi_matrix_bounded_p (MPFIMatrix *x);
|
72
|
+
void mpfi_matrix_mid (MPFRMatrix *ret, MPFIMatrix *x);
|
73
|
+
void mpfi_matrix_mid_interval (MPFIMatrix *ret, MPFIMatrix *x);
|
74
|
+
void mpfi_matrix_from_mpfr_matrix (MPFIMatrix *ret, MPFRMatrix *x);
|
75
|
+
int mpfi_matrix_intersect (MPFIMatrix *ret, MPFIMatrix *x, MPFIMatrix *y);
|
76
|
+
int mpfi_matrix_union (MPFIMatrix *z, MPFIMatrix *x, MPFIMatrix *y);
|
77
|
+
|
78
|
+
void mpfi_matrix_inner_product (MPFI *pr, MPFIMatrix *x, MPFIMatrix *y);
|
79
|
+
void mpfi_matrix_vector_distance (MPFI *distance, MPFIMatrix *x, MPFIMatrix *y);
|
80
|
+
void mpfi_matrix_vector_distance_center_pts (MPFR *distance, MPFIMatrix *x, MPFIMatrix *y);
|
81
|
+
void mpfi_matrix_vector_norm (MPFI *norm, MPFIMatrix *x);
|
82
|
+
void mpfi_matrix_max_norm (MPFI *norm, MPFIMatrix *x);
|
83
|
+
void mpfi_matrix_max_diam_abs (MPFR *diam, MPFIMatrix *x);
|
84
84
|
|
85
85
|
/* ----------------- vector ---------------- */
|
86
|
-
void mpfi_col_vector_init(MPFIMatrix *mat, int row);
|
87
|
-
void mpfi_row_vector_init(MPFIMatrix *mat, int column);
|
88
|
-
int mpfi_vector_normalize(MPFIMatrix *new, MPFIMatrix *x);
|
89
|
-
void mpfi_vector_midpoint(MPFIMatrix *new, MPFIMatrix *x, MPFIMatrix *y);
|
90
|
-
int mpfi_vector_set_length(MPFIMatrix *new, MPFIMatrix *x, MPFR *l);
|
86
|
+
void mpfi_col_vector_init (MPFIMatrix *mat, int row);
|
87
|
+
void mpfi_row_vector_init (MPFIMatrix *mat, int column);
|
88
|
+
int mpfi_vector_normalize (MPFIMatrix *new, MPFIMatrix *x);
|
89
|
+
void mpfi_vector_midpoint (MPFIMatrix *new, MPFIMatrix *x, MPFIMatrix *y);
|
90
|
+
int mpfi_vector_set_length (MPFIMatrix *new, MPFIMatrix *x, MPFR *l);
|
91
91
|
|
92
92
|
/* ----------------- square matrix ----------------- */
|
93
93
|
int mpfi_square_matrix_lu_decomp (MPFIMatrix *ret, int *indx, MPFIMatrix *x);
|
94
|
-
void mpfi_square_matrix_determinant(MPFI *det, MPFIMatrix *x);
|
95
|
-
void mpfi_square_matrix_qr_decomp(MPFIMatrix *q, MPFIMatrix *r, MPFIMatrix *x);
|
96
|
-
void mpfi_square_matrix_identity(MPFIMatrix *id);
|
97
|
-
|
94
|
+
void mpfi_square_matrix_determinant (MPFI *det, MPFIMatrix *x);
|
95
|
+
void mpfi_square_matrix_qr_decomp (MPFIMatrix *q, MPFIMatrix *r, MPFIMatrix *x);
|
96
|
+
void mpfi_square_matrix_identity (MPFIMatrix *id);
|
@@ -3,29 +3,29 @@
|
|
3
3
|
static ID eqq;
|
4
4
|
static VALUE __mpfr_matrix_class__, __mpfi_matrix_class__;
|
5
5
|
|
6
|
-
void r_mpfi_matrix_free(void *ptr){
|
6
|
+
void r_mpfi_matrix_free (void *ptr) {
|
7
7
|
mpfi_matrix_clear(ptr);
|
8
8
|
free(ptr);
|
9
9
|
}
|
10
10
|
|
11
|
-
void r_mpfi_matrix_suitable_matrix_init (VALUE *other, MPFIMatrix **ptr_other, int row, int column){
|
12
|
-
if(column == 1){
|
11
|
+
void r_mpfi_matrix_suitable_matrix_init (VALUE *other, MPFIMatrix **ptr_other, int row, int column) {
|
12
|
+
if (column == 1) {
|
13
13
|
r_mpfi_make_col_vector_struct(*other, *ptr_other);
|
14
14
|
mpfi_col_vector_init(*ptr_other, row);
|
15
|
-
}else if (row == 1){
|
15
|
+
} else if (row == 1) {
|
16
16
|
r_mpfi_make_row_vector_struct(*other, *ptr_other);
|
17
17
|
mpfi_row_vector_init(*ptr_other, column);
|
18
|
-
}else{
|
19
|
-
if (row == column){
|
18
|
+
} else {
|
19
|
+
if (row == column) {
|
20
20
|
r_mpfi_make_square_matrix_struct(*other, *ptr_other);
|
21
|
-
}else{
|
21
|
+
} else {
|
22
22
|
r_mpfi_make_matrix_struct(*other, *ptr_other);
|
23
23
|
}
|
24
24
|
mpfi_matrix_init(*ptr_other, row, column);
|
25
25
|
}
|
26
26
|
}
|
27
27
|
|
28
|
-
/* VALUE r_mpfi_matrix_copied_robj(VALUE old){ */
|
28
|
+
/* VALUE r_mpfi_matrix_copied_robj (VALUE old) { */
|
29
29
|
/* MPFIMatrix *ptr_old, *ptr_ret; */
|
30
30
|
/* r_mpfi_get_matrix_struct(ptr_old, old); */
|
31
31
|
/* VALUE ret; */
|
@@ -34,7 +34,7 @@ void r_mpfi_matrix_suitable_matrix_init (VALUE *other, MPFIMatrix **ptr_other, i
|
|
34
34
|
/* return ret; */
|
35
35
|
/* } */
|
36
36
|
|
37
|
-
VALUE r_mpfi_matrix_robj(MPFIMatrix *x){
|
37
|
+
VALUE r_mpfi_matrix_robj (MPFIMatrix *x) {
|
38
38
|
VALUE ret;
|
39
39
|
MPFIMatrix *ptr_ret;
|
40
40
|
r_mpfi_matrix_suitable_matrix_init (&ret, &ptr_ret, x->row, x->column);
|
@@ -43,20 +43,20 @@ VALUE r_mpfi_matrix_robj(MPFIMatrix *x){
|
|
43
43
|
}
|
44
44
|
|
45
45
|
/* Allocation function for MPFI::Matrix. */
|
46
|
-
static VALUE r_mpfi_matrix_alloc (VALUE self){
|
46
|
+
static VALUE r_mpfi_matrix_alloc (VALUE self) {
|
47
47
|
MPFIMatrix *ptr;
|
48
48
|
r_mpfi_make_matrix_struct(self, ptr);
|
49
49
|
return self;
|
50
50
|
}
|
51
51
|
|
52
|
-
/* static void r_mpfi_matrix_init_set_from_rmatrix(MPFIMatrix *x, VALUE src){ */
|
52
|
+
/* static void r_mpfi_matrix_init_set_from_rmatrix (MPFIMatrix *x, VALUE src) { */
|
53
53
|
/* MPFIMatrix *ptr_src; */
|
54
54
|
/* r_mpfi_get_matrix_struct(ptr_src, src); */
|
55
55
|
/* mpfi_matrix_init(x, ptr_src->row, ptr_src->column); */
|
56
56
|
/* mpfi_matrix_set(x, ptr_src); */
|
57
57
|
/* } */
|
58
58
|
|
59
|
-
static void r_mpfi_matrix_set_initial_value(MPFIMatrix *ptr, int argc, VALUE *argv)
|
59
|
+
static void r_mpfi_matrix_set_initial_value (MPFIMatrix *ptr, int argc, VALUE *argv)
|
60
60
|
{
|
61
61
|
int row, column, i, j;
|
62
62
|
VALUE row_ary;
|
@@ -71,7 +71,8 @@ static void r_mpfi_matrix_set_initial_value(MPFIMatrix *ptr, int argc, VALUE *ar
|
|
71
71
|
rb_raise(rb_eArgError, "MPFI::Matrix.new needs Array which has arrays of same sizes.");
|
72
72
|
}
|
73
73
|
for (j = 0; j < column; j++) {
|
74
|
-
|
74
|
+
volatile VALUE el = rb_ary_entry(row_ary, j);
|
75
|
+
r_mpfi_set_robj(mpfi_matrix_get_element(ptr, i, j), el);
|
75
76
|
}
|
76
77
|
}
|
77
78
|
break;
|
@@ -86,17 +87,17 @@ static void r_mpfi_matrix_set_initial_value(MPFIMatrix *ptr, int argc, VALUE *ar
|
|
86
87
|
}
|
87
88
|
|
88
89
|
/* Return new MPFI::Matrix instance. The same arguments as MPFI::Matrix.new is acceptable. */
|
89
|
-
static VALUE r_mpfi_matrix_global_new(int argc, VALUE *argv, VALUE self)
|
90
|
+
static VALUE r_mpfi_matrix_global_new (int argc, VALUE *argv, VALUE self)
|
90
91
|
{
|
91
92
|
MPFIMatrix *ptr;
|
92
93
|
VALUE val;
|
93
|
-
|
94
|
+
r_mpfi_make_matrix_struct(val, ptr);
|
94
95
|
r_mpfi_matrix_set_initial_value(ptr, argc, argv);
|
95
96
|
return val;
|
96
97
|
}
|
97
98
|
|
98
99
|
/* Initialization function for MPFI::Matrix. */
|
99
|
-
static VALUE r_mpfi_matrix_initialize (int argc, VALUE *argv, VALUE self){
|
100
|
+
static VALUE r_mpfi_matrix_initialize (int argc, VALUE *argv, VALUE self) {
|
100
101
|
MPFIMatrix *ptr;
|
101
102
|
r_mpfi_get_matrix_struct(ptr, self);
|
102
103
|
r_mpfi_matrix_set_initial_value(ptr, argc, argv);
|
@@ -104,21 +105,21 @@ static VALUE r_mpfi_matrix_initialize (int argc, VALUE *argv, VALUE self){
|
|
104
105
|
}
|
105
106
|
|
106
107
|
/* Allocation function for MPFI::SquareMatrix. */
|
107
|
-
static VALUE r_mpfi_square_matrix_alloc (VALUE self){
|
108
|
+
static VALUE r_mpfi_square_matrix_alloc (VALUE self) {
|
108
109
|
MPFIMatrix *ptr;
|
109
110
|
r_mpfi_make_square_matrix_struct(self, ptr);
|
110
111
|
return self;
|
111
112
|
}
|
112
113
|
|
113
|
-
static void r_mpfi_square_matrix_set_initial_value(MPFIMatrix *ptr, VALUE arg)
|
114
|
+
static void r_mpfi_square_matrix_set_initial_value (MPFIMatrix *ptr, VALUE arg)
|
114
115
|
{
|
115
116
|
int row, column, i, j;
|
116
117
|
VALUE row_ary;
|
117
|
-
switch(TYPE(arg)){
|
118
|
+
switch (TYPE(arg)) {
|
118
119
|
case T_ARRAY:
|
119
120
|
row = RARRAY_LEN(arg);
|
120
121
|
column = RARRAY_LEN(rb_ary_entry(arg, 0));
|
121
|
-
if(row == column){
|
122
|
+
if (row == column) {
|
122
123
|
mpfi_matrix_init(ptr, row, column);
|
123
124
|
for (i = 0; i < row; i++) {
|
124
125
|
row_ary = rb_ary_entry(arg, i);
|
@@ -129,7 +130,7 @@ static void r_mpfi_square_matrix_set_initial_value(MPFIMatrix *ptr, VALUE arg)
|
|
129
130
|
r_mpfi_set_robj(mpfi_matrix_get_element(ptr, i, j), rb_ary_entry(row_ary, j));
|
130
131
|
}
|
131
132
|
}
|
132
|
-
}else{
|
133
|
+
} else {
|
133
134
|
rb_raise(rb_eArgError, "MPFI::SquareMatrix.new needs two dimensinal Array which has the same sizes of row and column.");
|
134
135
|
}
|
135
136
|
break;
|
@@ -145,7 +146,7 @@ static void r_mpfi_square_matrix_set_initial_value(MPFIMatrix *ptr, VALUE arg)
|
|
145
146
|
}
|
146
147
|
|
147
148
|
/* Return new MPFI::SquareMatrix instance. The same arguments as MPFI::SquareMatrix.new is acceptable. */
|
148
|
-
static VALUE r_mpfi_square_matrix_global_new(int argc, VALUE arg)
|
149
|
+
static VALUE r_mpfi_square_matrix_global_new (int argc, VALUE arg)
|
149
150
|
{
|
150
151
|
MPFIMatrix *ptr;
|
151
152
|
VALUE val;
|
@@ -155,7 +156,7 @@ static VALUE r_mpfi_square_matrix_global_new(int argc, VALUE arg)
|
|
155
156
|
}
|
156
157
|
|
157
158
|
/* Initialization function for MPFI::SquareMatrix. */
|
158
|
-
static VALUE r_mpfi_square_matrix_initialize (VALUE self, VALUE arg){
|
159
|
+
static VALUE r_mpfi_square_matrix_initialize (VALUE self, VALUE arg) {
|
159
160
|
MPFIMatrix *ptr;
|
160
161
|
r_mpfi_get_matrix_struct(ptr, self);
|
161
162
|
r_mpfi_square_matrix_set_initial_value(ptr, arg);
|
@@ -163,7 +164,7 @@ static VALUE r_mpfi_square_matrix_initialize (VALUE self, VALUE arg){
|
|
163
164
|
}
|
164
165
|
|
165
166
|
/* initialize_copy */
|
166
|
-
static VALUE r_mpfi_matrix_initialize_copy (VALUE self, VALUE other){
|
167
|
+
static VALUE r_mpfi_matrix_initialize_copy (VALUE self, VALUE other) {
|
167
168
|
MPFIMatrix *ptr_self, *ptr_other;
|
168
169
|
r_mpfi_get_matrix_struct(ptr_self, self);
|
169
170
|
r_mpfi_get_matrix_struct(ptr_other, other);
|
@@ -173,21 +174,22 @@ static VALUE r_mpfi_matrix_initialize_copy (VALUE self, VALUE other){
|
|
173
174
|
}
|
174
175
|
|
175
176
|
/* Allocation function for MPFI::ColumnVector. */
|
176
|
-
static VALUE r_mpfi_col_vector_alloc (VALUE self){
|
177
|
+
static VALUE r_mpfi_col_vector_alloc (VALUE self) {
|
177
178
|
MPFIMatrix *ptr;
|
178
179
|
r_mpfi_make_col_vector_struct(self, ptr);
|
179
180
|
return self;
|
180
181
|
}
|
181
182
|
|
182
|
-
static void r_mpfi_col_vector_set_initial_value(MPFIMatrix *ptr, VALUE arg)
|
183
|
+
static void r_mpfi_col_vector_set_initial_value (MPFIMatrix *ptr, VALUE arg)
|
183
184
|
{
|
184
185
|
int row, i;
|
185
|
-
switch(TYPE(arg)){
|
186
|
+
switch (TYPE(arg)) {
|
186
187
|
case T_ARRAY:
|
187
188
|
row = RARRAY_LEN(arg);
|
188
189
|
mpfi_col_vector_init(ptr, row);
|
189
190
|
for (i = 0; i < row; i++) {
|
190
|
-
|
191
|
+
volatile VALUE el = rb_ary_entry(arg, i);
|
192
|
+
r_mpfi_set_robj(mpfi_matrix_get_ptr(ptr, i), el);
|
191
193
|
}
|
192
194
|
break;
|
193
195
|
case T_FIXNUM:
|
@@ -204,7 +206,7 @@ static void r_mpfi_col_vector_set_initial_value(MPFIMatrix *ptr, VALUE arg)
|
|
204
206
|
}
|
205
207
|
|
206
208
|
/* Return new MPFI::ColumnVector instance. The same arguments as MPFI::ColumnVector.new is acceptable. */
|
207
|
-
static VALUE r_mpfi_col_vector_global_new(int argc, VALUE arg)
|
209
|
+
static VALUE r_mpfi_col_vector_global_new (int argc, VALUE arg)
|
208
210
|
{
|
209
211
|
MPFIMatrix *ptr;
|
210
212
|
VALUE val;
|
@@ -214,7 +216,7 @@ static VALUE r_mpfi_col_vector_global_new(int argc, VALUE arg)
|
|
214
216
|
}
|
215
217
|
|
216
218
|
/* Initialization function for MPFI::ColumnVector. */
|
217
|
-
static VALUE r_mpfi_col_vector_initialize (VALUE self, VALUE arg){
|
219
|
+
static VALUE r_mpfi_col_vector_initialize (VALUE self, VALUE arg) {
|
218
220
|
MPFIMatrix *ptr;
|
219
221
|
r_mpfi_get_matrix_struct(ptr, self);
|
220
222
|
r_mpfi_col_vector_set_initial_value(ptr, arg);
|
@@ -222,21 +224,22 @@ static VALUE r_mpfi_col_vector_initialize (VALUE self, VALUE arg){
|
|
222
224
|
}
|
223
225
|
|
224
226
|
/* Allocation function for MPFI::RowVector. */
|
225
|
-
static VALUE r_mpfi_row_vector_alloc (VALUE self){
|
227
|
+
static VALUE r_mpfi_row_vector_alloc (VALUE self) {
|
226
228
|
MPFIMatrix *ptr;
|
227
229
|
r_mpfi_make_row_vector_struct(self, ptr);
|
228
230
|
return self;
|
229
231
|
}
|
230
232
|
|
231
|
-
static void r_mpfi_row_vector_set_initial_value(MPFIMatrix *ptr, VALUE arg)
|
233
|
+
static void r_mpfi_row_vector_set_initial_value (MPFIMatrix *ptr, VALUE arg)
|
232
234
|
{
|
233
235
|
int column, i;
|
234
|
-
switch(TYPE(arg)){
|
236
|
+
switch (TYPE(arg)) {
|
235
237
|
case T_ARRAY:
|
236
238
|
column = RARRAY_LEN(arg);
|
237
239
|
mpfi_row_vector_init(ptr, column);
|
238
240
|
for (i = 0; i < column; i++) {
|
239
|
-
|
241
|
+
volatile VALUE el = rb_ary_entry(arg, i);
|
242
|
+
r_mpfi_set_robj(mpfi_matrix_get_ptr(ptr, i), el);
|
240
243
|
}
|
241
244
|
break;
|
242
245
|
case T_FIXNUM:
|
@@ -253,7 +256,7 @@ static void r_mpfi_row_vector_set_initial_value(MPFIMatrix *ptr, VALUE arg)
|
|
253
256
|
}
|
254
257
|
|
255
258
|
/* Return new MPFI::RowVector instance. The same arguments as MPFI::RowVector.new is acceptable. */
|
256
|
-
static VALUE r_mpfi_row_vector_global_new(int argc, VALUE arg)
|
259
|
+
static VALUE r_mpfi_row_vector_global_new (int argc, VALUE arg)
|
257
260
|
{
|
258
261
|
MPFIMatrix *ptr;
|
259
262
|
VALUE val;
|
@@ -263,14 +266,14 @@ static VALUE r_mpfi_row_vector_global_new(int argc, VALUE arg)
|
|
263
266
|
}
|
264
267
|
|
265
268
|
/* Initialization function for MPFI::RowVector. */
|
266
|
-
static VALUE r_mpfi_row_vector_initialize (VALUE self, VALUE arg){
|
269
|
+
static VALUE r_mpfi_row_vector_initialize (VALUE self, VALUE arg) {
|
267
270
|
MPFIMatrix *ptr;
|
268
271
|
r_mpfi_get_matrix_struct(ptr, self);
|
269
272
|
r_mpfi_row_vector_set_initial_value(ptr, arg);
|
270
273
|
return Qtrue;
|
271
274
|
}
|
272
275
|
|
273
|
-
static VALUE r_mpfi_matrix_marshal_dump(VALUE self)
|
276
|
+
static VALUE r_mpfi_matrix_marshal_dump (VALUE self)
|
274
277
|
{
|
275
278
|
MPFIMatrix *ptr;
|
276
279
|
int i;
|
@@ -290,7 +293,7 @@ static VALUE r_mpfi_matrix_marshal_dump(VALUE self)
|
|
290
293
|
return ret_ary;
|
291
294
|
}
|
292
295
|
|
293
|
-
static VALUE r_mpfi_matrix_marshal_load(VALUE self, VALUE dump_ary)
|
296
|
+
static VALUE r_mpfi_matrix_marshal_load (VALUE self, VALUE dump_ary)
|
294
297
|
{
|
295
298
|
MPFIMatrix *ptr;
|
296
299
|
int i;
|
@@ -303,7 +306,7 @@ static VALUE r_mpfi_matrix_marshal_load(VALUE self, VALUE dump_ary)
|
|
303
306
|
ptr->size = ptr->row * ptr->column;
|
304
307
|
ptr->data = ALLOC_N(MPFI, ptr->size);
|
305
308
|
|
306
|
-
for(i = 0; i < ptr->size; i++){
|
309
|
+
for (i = 0; i < ptr->size; i++) {
|
307
310
|
dump_element = rb_ary_entry(dump_ary, i + 2);
|
308
311
|
Check_Type(dump_element, T_STRING);
|
309
312
|
dump = RSTRING_PTR(dump_element);
|
@@ -313,28 +316,28 @@ static VALUE r_mpfi_matrix_marshal_load(VALUE self, VALUE dump_ary)
|
|
313
316
|
}
|
314
317
|
|
315
318
|
/* Return size of data array which equals to column * row. */
|
316
|
-
static VALUE r_mpfi_matrix_size (VALUE self){
|
319
|
+
static VALUE r_mpfi_matrix_size (VALUE self) {
|
317
320
|
MPFIMatrix *ptr_self;
|
318
321
|
r_mpfi_get_matrix_struct(ptr_self, self);
|
319
322
|
return INT2FIX(ptr_self->size);
|
320
323
|
}
|
321
324
|
|
322
325
|
/* Return column size of matrix. */
|
323
|
-
static VALUE r_mpfi_matrix_column_size (VALUE self){
|
326
|
+
static VALUE r_mpfi_matrix_column_size (VALUE self) {
|
324
327
|
MPFIMatrix *ptr_self;
|
325
328
|
r_mpfi_get_matrix_struct(ptr_self, self);
|
326
329
|
return INT2FIX(ptr_self->column);
|
327
330
|
}
|
328
331
|
|
329
332
|
/* Return row size of matrix. */
|
330
|
-
static VALUE r_mpfi_matrix_row_size (VALUE self){
|
333
|
+
static VALUE r_mpfi_matrix_row_size (VALUE self) {
|
331
334
|
MPFIMatrix *ptr_self;
|
332
335
|
r_mpfi_get_matrix_struct(ptr_self, self);
|
333
336
|
return INT2FIX(ptr_self->row);
|
334
337
|
}
|
335
338
|
|
336
339
|
/* Return element at _arg_.*/
|
337
|
-
static VALUE r_mpfi_matrix_at (VALUE self, VALUE arg){
|
340
|
+
static VALUE r_mpfi_matrix_at (VALUE self, VALUE arg) {
|
338
341
|
MPFIMatrix *ptr_self;
|
339
342
|
int i;
|
340
343
|
r_mpfi_get_matrix_struct(ptr_self, self);
|
@@ -345,13 +348,13 @@ static VALUE r_mpfi_matrix_at (VALUE self, VALUE arg){
|
|
345
348
|
r_mpfi_make_struct_init(ret, ptr_ret);
|
346
349
|
mpfi_set(ptr_ret, ptr_self->data + i);
|
347
350
|
return ret;
|
348
|
-
}else{
|
351
|
+
} else {
|
349
352
|
return Qnil;
|
350
353
|
}
|
351
354
|
}
|
352
355
|
|
353
356
|
/* Return element with _row_ and _column_.*/
|
354
|
-
static VALUE r_mpfi_matrix_element (VALUE self, VALUE row, VALUE column){
|
357
|
+
static VALUE r_mpfi_matrix_element (VALUE self, VALUE row, VALUE column) {
|
355
358
|
MPFIMatrix *ptr_self;
|
356
359
|
int i, j;
|
357
360
|
r_mpfi_get_matrix_struct(ptr_self, self);
|
@@ -363,13 +366,13 @@ static VALUE r_mpfi_matrix_element (VALUE self, VALUE row, VALUE column){
|
|
363
366
|
r_mpfi_make_struct_init(ret, ptr_ret);
|
364
367
|
mpfi_set(ptr_ret, ptr_self->data + i + j * ptr_self->row);
|
365
368
|
return ret;
|
366
|
-
}else{
|
369
|
+
} else {
|
367
370
|
return Qnil;
|
368
371
|
}
|
369
372
|
}
|
370
373
|
|
371
374
|
/* Set _robj_ to element of which row is _row_ and column is _column_. */
|
372
|
-
static VALUE r_mpfi_matrix_set_element (VALUE self, VALUE row, VALUE column, VALUE robj){
|
375
|
+
static VALUE r_mpfi_matrix_set_element (VALUE self, VALUE row, VALUE column, VALUE robj) {
|
373
376
|
MPFIMatrix *ptr_self;
|
374
377
|
int i, j;
|
375
378
|
r_mpfi_get_matrix_struct(ptr_self, self);
|
@@ -382,40 +385,42 @@ static VALUE r_mpfi_matrix_set_element (VALUE self, VALUE row, VALUE column, VAL
|
|
382
385
|
}
|
383
386
|
|
384
387
|
/* Evaluate block with each element of matrix. */
|
385
|
-
static VALUE r_mpfi_matrix_each_element (VALUE self){
|
388
|
+
static VALUE r_mpfi_matrix_each_element (VALUE self) {
|
386
389
|
MPFIMatrix *ptr_self;
|
387
390
|
VALUE ret;
|
388
391
|
int i, j;
|
392
|
+
RETURN_ENUMERATOR(self, 0, NULL);
|
389
393
|
r_mpfi_get_matrix_struct(ptr_self, self);
|
390
394
|
ret = Qnil;
|
391
395
|
for (i = 0; i < ptr_self->row; i++) {
|
392
396
|
for (j = 0; j < ptr_self->column; j++) {
|
393
|
-
volatile VALUE
|
394
|
-
ret = rb_yield(
|
397
|
+
volatile VALUE el = r_mpfi_make_new_fi_obj(ptr_self->data + i + j * ptr_self->row);
|
398
|
+
ret = rb_yield(el);
|
395
399
|
}
|
396
400
|
}
|
397
401
|
return ret;
|
398
402
|
}
|
399
403
|
|
400
404
|
/* Evaluate block with each element and its index. */
|
401
|
-
static VALUE r_mpfi_matrix_each_element_with_index (VALUE self){
|
405
|
+
static VALUE r_mpfi_matrix_each_element_with_index (VALUE self) {
|
402
406
|
MPFIMatrix *ptr_self;
|
403
407
|
VALUE ret, tmp_i;
|
404
408
|
int i, j;
|
409
|
+
RETURN_ENUMERATOR(self, 0, NULL);
|
405
410
|
r_mpfi_get_matrix_struct(ptr_self, self);
|
406
411
|
ret = Qnil;
|
407
412
|
for (i = 0; i < ptr_self->row; i++) {
|
408
413
|
tmp_i = INT2NUM(i);
|
409
414
|
for (j = 0; j < ptr_self->column; j++) {
|
410
|
-
volatile VALUE
|
411
|
-
ret = rb_yield(rb_ary_new3(3,
|
415
|
+
volatile VALUE el = r_mpfi_make_new_fi_obj(ptr_self->data + i + j * ptr_self->row);
|
416
|
+
ret = rb_yield(rb_ary_new3(3, el, tmp_i, INT2NUM(j)));
|
412
417
|
}
|
413
418
|
}
|
414
419
|
return ret;
|
415
420
|
}
|
416
421
|
|
417
422
|
/* Return one dimensinal array which has strings converted elements to. */
|
418
|
-
static VALUE r_mpfi_matrix_str_ary_for_inspect(VALUE self){
|
423
|
+
static VALUE r_mpfi_matrix_str_ary_for_inspect (VALUE self) {
|
419
424
|
MPFIMatrix *ptr_self;
|
420
425
|
char *tmp_str;
|
421
426
|
VALUE ret_ary;
|
@@ -423,8 +428,8 @@ static VALUE r_mpfi_matrix_str_ary_for_inspect(VALUE self){
|
|
423
428
|
r_mpfi_get_matrix_struct(ptr_self, self);
|
424
429
|
ret_ary = rb_ary_new2(ptr_self->size);
|
425
430
|
for (i = 0; i < ptr_self->size; i++) {
|
426
|
-
if(!mpfr_asprintf(&tmp_str, "%.Re %.Re",
|
427
|
-
|
431
|
+
if (!mpfr_asprintf(&tmp_str, "%.Re %.Re",
|
432
|
+
r_mpfi_left_ptr((ptr_self->data + i)), r_mpfi_right_ptr(ptr_self->data + i))) {
|
428
433
|
rb_raise(rb_eFatal, "Can not allocate a string by mpfr_asprintf.");
|
429
434
|
}
|
430
435
|
rb_ary_store(ret_ary, i, rb_str_new2(tmp_str));
|
@@ -434,20 +439,20 @@ static VALUE r_mpfi_matrix_str_ary_for_inspect(VALUE self){
|
|
434
439
|
}
|
435
440
|
|
436
441
|
/* Return two dimensinal array which has strings converted elements to. */
|
437
|
-
static VALUE r_mpfi_matrix_str_ary_for_inspect2(VALUE self){
|
442
|
+
static VALUE r_mpfi_matrix_str_ary_for_inspect2 (VALUE self) {
|
438
443
|
MPFIMatrix *ptr_self;
|
439
444
|
char *tmp_str;
|
440
445
|
int i, j;
|
441
446
|
VALUE *ary, ret_ary;
|
442
447
|
r_mpfi_get_matrix_struct(ptr_self, self);
|
443
448
|
ary = ALLOC_N(VALUE, ptr_self->row);
|
444
|
-
for(i = 0; i < ptr_self->row; i++){
|
449
|
+
for (i = 0; i < ptr_self->row; i++) {
|
445
450
|
ary[i] = rb_ary_new();
|
446
451
|
}
|
447
452
|
for (i = 0; i < ptr_self->size; i += ptr_self->row) {
|
448
453
|
for (j = 0; j < ptr_self->row; j++) {
|
449
|
-
if(!mpfr_asprintf(&tmp_str, "%.Re %.Re",
|
450
|
-
|
454
|
+
if (!mpfr_asprintf(&tmp_str, "%.Re %.Re",
|
455
|
+
r_mpfi_left_ptr((ptr_self->data + i + j)), r_mpfi_right_ptr(ptr_self->data + i + j))) {
|
451
456
|
rb_raise(rb_eFatal, "Can not allocate a string by mpfr_asprintf.");
|
452
457
|
}
|
453
458
|
rb_ary_push(ary[j], rb_str_new2(tmp_str));
|
@@ -459,14 +464,14 @@ static VALUE r_mpfi_matrix_str_ary_for_inspect2(VALUE self){
|
|
459
464
|
return ret_ary;
|
460
465
|
}
|
461
466
|
|
462
|
-
static VALUE r_mpfi_matrix_to_str_ary(VALUE self){
|
467
|
+
static VALUE r_mpfi_matrix_to_str_ary (VALUE self) {
|
463
468
|
MPFIMatrix *ptr_self;
|
464
469
|
char *tmp_str1, *tmp_str2;
|
465
470
|
int i, j;
|
466
471
|
VALUE *ary, ret_ary;
|
467
472
|
r_mpfi_get_matrix_struct(ptr_self, self);
|
468
473
|
ary = ALLOC_N(VALUE, ptr_self->row);
|
469
|
-
for(i = 0; i < ptr_self->row; i++){
|
474
|
+
for (i = 0; i < ptr_self->row; i++) {
|
470
475
|
ary[i] = rb_ary_new();
|
471
476
|
}
|
472
477
|
for (i = 0; i < ptr_self->size; i += ptr_self->row) {
|
@@ -487,7 +492,7 @@ static VALUE r_mpfi_matrix_to_str_ary(VALUE self){
|
|
487
492
|
return ret_ary;
|
488
493
|
}
|
489
494
|
|
490
|
-
static VALUE r_mpfi_matrix_to_strf_ary(VALUE self, VALUE format_str){
|
495
|
+
static VALUE r_mpfi_matrix_to_strf_ary (VALUE self, VALUE format_str) {
|
491
496
|
MPFIMatrix *ptr_self;
|
492
497
|
char *tmp_str1, *tmp_str2, *format;
|
493
498
|
int i, j;
|
@@ -495,15 +500,15 @@ static VALUE r_mpfi_matrix_to_strf_ary(VALUE self, VALUE format_str){
|
|
495
500
|
r_mpfi_get_matrix_struct(ptr_self, self);
|
496
501
|
format = StringValuePtr(format_str);
|
497
502
|
ary = ALLOC_N(VALUE, ptr_self->row);
|
498
|
-
for(i = 0; i < ptr_self->row; i++){
|
503
|
+
for (i = 0; i < ptr_self->row; i++) {
|
499
504
|
ary[i] = rb_ary_new();
|
500
505
|
}
|
501
506
|
for (i = 0; i < ptr_self->size; i += ptr_self->row) {
|
502
507
|
for (j = 0; j < ptr_self->row; j++) {
|
503
|
-
if(!mpfr_asprintf(&tmp_str1, format, r_mpfi_left_ptr((ptr_self->data + i + j)))) {
|
508
|
+
if (!mpfr_asprintf(&tmp_str1, format, r_mpfi_left_ptr((ptr_self->data + i + j)))) {
|
504
509
|
rb_raise(rb_eFatal, "Can not allocate a string by mpfr_asprintf.");
|
505
510
|
}
|
506
|
-
if(!mpfr_asprintf(&tmp_str2, format, r_mpfi_right_ptr(ptr_self->data + i + j))) {
|
511
|
+
if (!mpfr_asprintf(&tmp_str2, format, r_mpfi_right_ptr(ptr_self->data + i + j))) {
|
507
512
|
rb_raise(rb_eFatal, "Can not allocate a string by mpfr_asprintf.");
|
508
513
|
}
|
509
514
|
rb_ary_push(ary[j], rb_ary_new3(2, rb_str_new2(tmp_str1), rb_str_new2(tmp_str2)));
|
@@ -516,7 +521,7 @@ static VALUE r_mpfi_matrix_to_strf_ary(VALUE self, VALUE format_str){
|
|
516
521
|
return ret_ary;
|
517
522
|
}
|
518
523
|
|
519
|
-
static VALUE r_mpfi_matrix_to_array(VALUE self){
|
524
|
+
static VALUE r_mpfi_matrix_to_array (VALUE self) {
|
520
525
|
MPFIMatrix *ptr_self;
|
521
526
|
int i;
|
522
527
|
VALUE ret_ary;
|
@@ -528,13 +533,13 @@ static VALUE r_mpfi_matrix_to_array(VALUE self){
|
|
528
533
|
return ret_ary;
|
529
534
|
}
|
530
535
|
|
531
|
-
static VALUE r_mpfi_matrix_to_array2(VALUE self){
|
536
|
+
static VALUE r_mpfi_matrix_to_array2 (VALUE self) {
|
532
537
|
MPFIMatrix *ptr_self;
|
533
538
|
int i, j;
|
534
539
|
VALUE *ary, ret_ary;
|
535
540
|
r_mpfi_get_matrix_struct(ptr_self, self);
|
536
541
|
ary = ALLOC_N(VALUE, ptr_self->row);
|
537
|
-
for(i = 0; i < ptr_self->row; i++){
|
542
|
+
for (i = 0; i < ptr_self->row; i++) {
|
538
543
|
ary[i] = rb_ary_new();
|
539
544
|
}
|
540
545
|
for (i = 0; i < ptr_self->size; i += ptr_self->row) {
|
@@ -553,11 +558,11 @@ static VALUE r_mpfi_matrix_row (VALUE self, VALUE arg) {
|
|
553
558
|
VALUE ret;
|
554
559
|
r_mpfi_get_matrix_struct(ptr_self, self);
|
555
560
|
num = NUM2INT(arg);
|
556
|
-
if(num < ptr_self->row){
|
561
|
+
if (num < ptr_self->row) {
|
557
562
|
r_mpfi_matrix_suitable_matrix_init (&ret, &ptr_ret, 1, ptr_self->column);
|
558
563
|
mpfi_matrix_row(ptr_ret, ptr_self, num);
|
559
564
|
return ret;
|
560
|
-
}else{
|
565
|
+
} else {
|
561
566
|
return Qnil;
|
562
567
|
}
|
563
568
|
}
|
@@ -568,17 +573,17 @@ static VALUE r_mpfi_matrix_column (VALUE self, VALUE arg) {
|
|
568
573
|
VALUE ret;
|
569
574
|
r_mpfi_get_matrix_struct(ptr_self, self);
|
570
575
|
num = NUM2INT(arg);
|
571
|
-
if(num < ptr_self->column){
|
576
|
+
if (num < ptr_self->column) {
|
572
577
|
r_mpfi_matrix_suitable_matrix_init (&ret, &ptr_ret, ptr_self->row, 1);
|
573
578
|
mpfi_matrix_column(ptr_ret, ptr_self, num);
|
574
579
|
return ret;
|
575
|
-
}else{
|
580
|
+
} else {
|
576
581
|
return Qnil;
|
577
582
|
}
|
578
583
|
}
|
579
584
|
|
580
585
|
/* Return transposed matrix which is new object. */
|
581
|
-
static VALUE r_mpfi_matrix_transpose (VALUE self){
|
586
|
+
static VALUE r_mpfi_matrix_transpose (VALUE self) {
|
582
587
|
MPFIMatrix *ptr_self, *ptr_ret;
|
583
588
|
VALUE ret;
|
584
589
|
r_mpfi_get_matrix_struct(ptr_self, self);
|
@@ -588,7 +593,7 @@ static VALUE r_mpfi_matrix_transpose (VALUE self){
|
|
588
593
|
}
|
589
594
|
|
590
595
|
/* Transpose self. This method is destroying method. */
|
591
|
-
static VALUE r_mpfi_matrix_transpose2 (VALUE self){
|
596
|
+
static VALUE r_mpfi_matrix_transpose2 (VALUE self) {
|
592
597
|
MPFIMatrix *ptr_self, tmp;
|
593
598
|
int i;
|
594
599
|
r_mpfi_get_matrix_struct(ptr_self, self);
|
@@ -605,7 +610,7 @@ static VALUE r_mpfi_matrix_transpose2 (VALUE self){
|
|
605
610
|
}
|
606
611
|
|
607
612
|
/* Return transposed matrix which is new object. */
|
608
|
-
static VALUE r_mpfi_matrix_neg (VALUE self){
|
613
|
+
static VALUE r_mpfi_matrix_neg (VALUE self) {
|
609
614
|
MPFIMatrix *ptr_self, *ptr_ret;
|
610
615
|
VALUE ret;
|
611
616
|
r_mpfi_get_matrix_struct(ptr_self, self);
|
@@ -616,7 +621,7 @@ static VALUE r_mpfi_matrix_neg (VALUE self){
|
|
616
621
|
|
617
622
|
|
618
623
|
/* Return true if all elements of _self_ equal to corresponding elements of _other_. */
|
619
|
-
static VALUE r_mpfi_matrix_equal_p (VALUE self, VALUE other){
|
624
|
+
static VALUE r_mpfi_matrix_equal_p (VALUE self, VALUE other) {
|
620
625
|
MPFIMatrix *ptr_self, *ptr_other;
|
621
626
|
r_mpfi_get_matrix_struct(ptr_self, self);
|
622
627
|
r_mpfi_get_matrix_struct(ptr_other, other);
|
@@ -627,7 +632,7 @@ static VALUE r_mpfi_matrix_equal_p (VALUE self, VALUE other){
|
|
627
632
|
}
|
628
633
|
|
629
634
|
/* Return _self_ + _other_. */
|
630
|
-
static VALUE r_mpfi_matrix_add (VALUE self, VALUE other){
|
635
|
+
static VALUE r_mpfi_matrix_add (VALUE self, VALUE other) {
|
631
636
|
MPFIMatrix *ptr_self, *ptr_other, *ptr_ret;
|
632
637
|
VALUE ret;
|
633
638
|
r_mpfi_get_matrix_struct(ptr_self, self);
|
@@ -635,45 +640,45 @@ static VALUE r_mpfi_matrix_add (VALUE self, VALUE other){
|
|
635
640
|
if (ptr_self->column == ptr_other->column && ptr_self->row == ptr_other->row) {
|
636
641
|
r_mpfi_matrix_suitable_matrix_init (&ret, &ptr_ret, ptr_self->row, ptr_self->column);
|
637
642
|
mpfi_matrix_add(ptr_ret, ptr_self, ptr_other);
|
638
|
-
}else{
|
643
|
+
} else {
|
639
644
|
rb_raise(rb_eArgError, "Matrixes must have same size.");
|
640
645
|
}
|
641
646
|
return ret;
|
642
647
|
}
|
643
648
|
|
644
649
|
/* Return _self_ + _other_ which is MPFI::Matrix. */
|
645
|
-
static VALUE r_mpfi_matrix_add2 (VALUE self, VALUE other){
|
650
|
+
static VALUE r_mpfi_matrix_add2 (VALUE self, VALUE other) {
|
646
651
|
MPFIMatrix *ptr_self, *ptr_ret;
|
647
652
|
VALUE ret;
|
648
653
|
r_mpfi_get_matrix_struct(ptr_self, self);
|
649
654
|
r_mpfi_make_matrix_struct(ret, ptr_ret);
|
650
655
|
|
651
|
-
if(RTEST(rb_funcall(__mpfi_matrix_class__, eqq, 1, other))){
|
656
|
+
if (RTEST(rb_funcall(__mpfi_matrix_class__, eqq, 1, other))) {
|
652
657
|
MPFIMatrix *ptr_other;
|
653
658
|
r_mpfi_get_matrix_struct(ptr_other, other);
|
654
659
|
if (ptr_self->column == ptr_other->column && ptr_self->row == ptr_other->row) {
|
655
660
|
r_mpfi_matrix_suitable_matrix_init (&ret, &ptr_ret, ptr_self->row, ptr_self->column);
|
656
661
|
mpfi_matrix_add(ptr_ret, ptr_self, ptr_other);
|
657
|
-
}else{
|
662
|
+
} else {
|
658
663
|
rb_raise(rb_eArgError, "Matrixes must have same size.");
|
659
664
|
}
|
660
|
-
}else if(RTEST(rb_funcall(__mpfr_matrix_class__, eqq, 1, other))){
|
665
|
+
} else if (RTEST(rb_funcall(__mpfr_matrix_class__, eqq, 1, other))) {
|
661
666
|
MPFRMatrix *ptr_other;
|
662
667
|
r_mpfr_get_matrix_struct(ptr_other, other);
|
663
668
|
if (ptr_self->column == ptr_other->column && ptr_self->row == ptr_other->row) {
|
664
669
|
r_mpfi_matrix_suitable_matrix_init (&ret, &ptr_ret, ptr_self->row, ptr_self->column);
|
665
670
|
mpfi_matrix_add_fr(ptr_ret, ptr_self, ptr_other);
|
666
|
-
}else{
|
671
|
+
} else {
|
667
672
|
rb_raise(rb_eArgError, "Matrixes must have same size.");
|
668
|
-
}
|
669
|
-
}else{
|
673
|
+
}
|
674
|
+
} else {
|
670
675
|
rb_raise(rb_eArgError, "Argument matrix must be an instance of MPFI::Matrix or MPFR::Matrix.");
|
671
676
|
}
|
672
677
|
return ret;
|
673
678
|
}
|
674
679
|
|
675
680
|
/* Return _self_ - _other_. */
|
676
|
-
static VALUE r_mpfi_matrix_sub (VALUE self, VALUE other){
|
681
|
+
static VALUE r_mpfi_matrix_sub (VALUE self, VALUE other) {
|
677
682
|
MPFIMatrix *ptr_self, *ptr_other, *ptr_ret;
|
678
683
|
VALUE ret;
|
679
684
|
r_mpfi_get_matrix_struct(ptr_self, self);
|
@@ -682,120 +687,120 @@ static VALUE r_mpfi_matrix_sub (VALUE self, VALUE other){
|
|
682
687
|
if (ptr_self->column == ptr_other->column && ptr_self->row == ptr_other->row) {
|
683
688
|
r_mpfi_matrix_suitable_matrix_init (&ret, &ptr_ret, ptr_self->row, ptr_self->column);
|
684
689
|
mpfi_matrix_sub(ptr_ret, ptr_self, ptr_other);
|
685
|
-
}else{
|
690
|
+
} else {
|
686
691
|
rb_raise(rb_eArgError, "Matrixes must have same size.");
|
687
692
|
}
|
688
693
|
return ret;
|
689
694
|
}
|
690
695
|
|
691
696
|
/* Return _self_ - _other_ which is MPFI::Matrix. */
|
692
|
-
static VALUE r_mpfi_matrix_sub2 (VALUE self, VALUE other){
|
697
|
+
static VALUE r_mpfi_matrix_sub2 (VALUE self, VALUE other) {
|
693
698
|
MPFIMatrix *ptr_self, *ptr_ret;
|
694
699
|
VALUE ret;
|
695
700
|
r_mpfi_get_matrix_struct(ptr_self, self);
|
696
701
|
r_mpfi_make_matrix_struct(ret, ptr_ret);
|
697
702
|
|
698
|
-
if(RTEST(rb_funcall(__mpfi_matrix_class__, eqq, 1, other))){
|
703
|
+
if (RTEST(rb_funcall(__mpfi_matrix_class__, eqq, 1, other))) {
|
699
704
|
MPFIMatrix *ptr_other;
|
700
705
|
r_mpfi_get_matrix_struct(ptr_other, other);
|
701
706
|
if (ptr_self->column == ptr_other->column && ptr_self->row == ptr_other->row) {
|
702
707
|
r_mpfi_matrix_suitable_matrix_init (&ret, &ptr_ret, ptr_self->row, ptr_self->column);
|
703
708
|
mpfi_matrix_sub(ptr_ret, ptr_self, ptr_other);
|
704
|
-
}else{
|
709
|
+
} else {
|
705
710
|
rb_raise(rb_eArgError, "Matrixes must have same size.");
|
706
711
|
}
|
707
|
-
}else if(RTEST(rb_funcall(__mpfr_matrix_class__, eqq, 1, other))){
|
712
|
+
} else if (RTEST(rb_funcall(__mpfr_matrix_class__, eqq, 1, other))) {
|
708
713
|
MPFRMatrix *ptr_other;
|
709
714
|
r_mpfr_get_matrix_struct(ptr_other, other);
|
710
715
|
if (ptr_self->column == ptr_other->column && ptr_self->row == ptr_other->row) {
|
711
716
|
r_mpfi_matrix_suitable_matrix_init (&ret, &ptr_ret, ptr_self->row, ptr_self->column);
|
712
717
|
mpfi_matrix_sub_fr(ptr_ret, ptr_self, ptr_other);
|
713
|
-
}else{
|
718
|
+
} else {
|
714
719
|
rb_raise(rb_eArgError, "Matrixes must have same size.");
|
715
|
-
}
|
716
|
-
}else{
|
720
|
+
}
|
721
|
+
} else {
|
717
722
|
rb_raise(rb_eArgError, "Argument matrix must be an instance of MPFI::Matrix or MPFR::Matrix.");
|
718
723
|
}
|
719
724
|
return ret;
|
720
725
|
}
|
721
726
|
|
722
|
-
static VALUE r_mpfi_matrix_vector_inner_product (VALUE self, VALUE arg){
|
727
|
+
static VALUE r_mpfi_matrix_vector_inner_product (VALUE self, VALUE arg) {
|
723
728
|
MPFIMatrix *ptr_self, *ptr_arg;
|
724
729
|
VALUE ret;
|
725
730
|
MPFI *ptr_ret;
|
726
731
|
r_mpfi_get_matrix_struct(ptr_self, self);
|
727
732
|
r_mpfi_get_matrix_struct(ptr_arg, arg);
|
728
733
|
r_mpfi_make_struct_init(ret, ptr_ret);
|
729
|
-
if(ptr_self->size == ptr_arg->size){
|
734
|
+
if (ptr_self->size == ptr_arg->size) {
|
730
735
|
mpfi_matrix_inner_product(ptr_ret, ptr_self, ptr_arg);
|
731
|
-
}else{
|
736
|
+
} else {
|
732
737
|
rb_raise(rb_eArgError, "Vectors must have same size.");
|
733
738
|
}
|
734
739
|
return ret;
|
735
740
|
}
|
736
741
|
|
737
742
|
/* Return _self_ * _other_. */
|
738
|
-
static VALUE r_mpfi_matrix_mul_matrix (VALUE self, VALUE other){
|
743
|
+
static VALUE r_mpfi_matrix_mul_matrix (VALUE self, VALUE other) {
|
739
744
|
MPFIMatrix *ptr_self, *ptr_other, *ptr_ret;
|
740
745
|
VALUE ret;
|
741
746
|
r_mpfi_get_matrix_struct(ptr_self, self);
|
742
747
|
r_mpfi_get_matrix_struct(ptr_other, other);
|
743
748
|
r_mpfi_make_matrix_struct(ret, ptr_ret);
|
744
749
|
if (ptr_self->column == ptr_other->row) {
|
745
|
-
if((ptr_other->column == 1) && (ptr_self->row == 1)){
|
750
|
+
if ((ptr_other->column == 1) && (ptr_self->row == 1)) {
|
746
751
|
ret = r_mpfi_matrix_vector_inner_product(self, other);
|
747
|
-
}else{
|
752
|
+
} else {
|
748
753
|
r_mpfi_matrix_suitable_matrix_init (&ret, &ptr_ret, ptr_self->row, ptr_other->column);
|
749
754
|
mpfi_matrix_mul(ptr_ret, ptr_self, ptr_other);
|
750
755
|
}
|
751
|
-
}else{
|
756
|
+
} else {
|
752
757
|
rb_raise(rb_eArgError, "Row size of first matrixes must be same as colmun size of second matrixes.");
|
753
758
|
}
|
754
759
|
return ret;
|
755
760
|
}
|
756
761
|
|
757
762
|
/* Return _self_ * _other_ which is MPFI::Matrix. */
|
758
|
-
static VALUE r_mpfi_matrix_mul_matrix2 (VALUE self, VALUE other){
|
763
|
+
static VALUE r_mpfi_matrix_mul_matrix2 (VALUE self, VALUE other) {
|
759
764
|
MPFIMatrix *ptr_self, *ptr_ret;
|
760
765
|
VALUE ret;
|
761
766
|
r_mpfi_get_matrix_struct(ptr_self, self);
|
762
767
|
r_mpfi_make_matrix_struct(ret, ptr_ret);
|
763
768
|
|
764
|
-
if(RTEST(rb_funcall(__mpfi_matrix_class__, eqq, 1, other))){
|
769
|
+
if (RTEST(rb_funcall(__mpfi_matrix_class__, eqq, 1, other))) {
|
765
770
|
MPFIMatrix *ptr_other;
|
766
771
|
r_mpfi_get_matrix_struct(ptr_other, other);
|
767
772
|
if (ptr_self->column == ptr_other->row) {
|
768
773
|
r_mpfi_matrix_suitable_matrix_init (&ret, &ptr_ret, ptr_self->row, ptr_other->column);
|
769
774
|
mpfi_matrix_mul(ptr_ret, ptr_self, ptr_other);
|
770
|
-
}else{
|
775
|
+
} else {
|
771
776
|
rb_raise(rb_eArgError, "Row size of first matrixes must be same as colmun size of second matrixes.");
|
772
777
|
}
|
773
|
-
}else if(RTEST(rb_funcall(__mpfr_matrix_class__, eqq, 1, other))){
|
778
|
+
} else if (RTEST(rb_funcall(__mpfr_matrix_class__, eqq, 1, other))) {
|
774
779
|
MPFRMatrix *ptr_other;
|
775
780
|
r_mpfr_get_matrix_struct(ptr_other, other);
|
776
781
|
if (ptr_self->column == ptr_other->row) {
|
777
782
|
r_mpfi_matrix_suitable_matrix_init (&ret, &ptr_ret, ptr_self->row, ptr_other->column);
|
778
783
|
mpfi_matrix_mul_fr(ptr_ret, ptr_self, ptr_other);
|
779
|
-
}else{
|
784
|
+
} else {
|
780
785
|
rb_raise(rb_eArgError, "Row size of first matrixes must be same as colmun size of second matrixes.");
|
781
|
-
}
|
782
|
-
}else{
|
786
|
+
}
|
787
|
+
} else {
|
783
788
|
rb_raise(rb_eArgError, "Argument matrix must be an instance of MPFI::Matrix or MPFR::Matrix.");
|
784
789
|
}
|
785
790
|
return ret;
|
786
791
|
}
|
787
792
|
|
788
793
|
/* Return _scalar_ * _self_, where _scalar_ is scalar and _self_ is matrix. */
|
789
|
-
static VALUE r_mpfi_matrix_mul_scalar (VALUE self, VALUE scalar){
|
794
|
+
static VALUE r_mpfi_matrix_mul_scalar (VALUE self, VALUE scalar) {
|
790
795
|
MPFIMatrix *ptr_self, *ptr_ret;
|
791
796
|
MPFI *ptr_scalar;
|
792
797
|
VALUE ret;
|
793
798
|
r_mpfi_get_matrix_struct(ptr_self, self);
|
794
799
|
r_mpfi_matrix_suitable_matrix_init (&ret, &ptr_ret, ptr_self->row, ptr_self->column);
|
795
|
-
if(RTEST(rb_funcall(r_mpfi_class, eqq, 1, scalar))){
|
800
|
+
if (RTEST(rb_funcall(r_mpfi_class, eqq, 1, scalar))) {
|
796
801
|
r_mpfi_get_struct(ptr_scalar, scalar);
|
797
802
|
mpfi_matrix_mul_scalar(ptr_ret, ptr_self, ptr_scalar);
|
798
|
-
}else{
|
803
|
+
} else {
|
799
804
|
r_mpfi_temp_alloc_init(ptr_scalar);
|
800
805
|
r_mpfi_set_robj(ptr_scalar, scalar);
|
801
806
|
mpfi_matrix_mul_scalar(ptr_ret, ptr_self, ptr_scalar);
|
@@ -804,16 +809,16 @@ static VALUE r_mpfi_matrix_mul_scalar (VALUE self, VALUE scalar){
|
|
804
809
|
return ret;
|
805
810
|
}
|
806
811
|
|
807
|
-
static VALUE r_mpfi_matrix_div_scalar (VALUE self, VALUE scalar){
|
812
|
+
static VALUE r_mpfi_matrix_div_scalar (VALUE self, VALUE scalar) {
|
808
813
|
MPFIMatrix *ptr_self, *ptr_ret;
|
809
814
|
MPFI *ptr_scalar;
|
810
815
|
VALUE ret;
|
811
816
|
r_mpfi_get_matrix_struct(ptr_self, self);
|
812
817
|
r_mpfi_matrix_suitable_matrix_init (&ret, &ptr_ret, ptr_self->row, ptr_self->column);
|
813
|
-
if(RTEST(rb_funcall(r_mpfi_class, eqq, 1, scalar))){
|
818
|
+
if (RTEST(rb_funcall(r_mpfi_class, eqq, 1, scalar))) {
|
814
819
|
r_mpfi_get_struct(ptr_scalar, scalar);
|
815
820
|
mpfi_matrix_div_scalar(ptr_ret, ptr_self, ptr_scalar);
|
816
|
-
}else{
|
821
|
+
} else {
|
817
822
|
r_mpfi_temp_alloc_init(ptr_scalar);
|
818
823
|
r_mpfi_set_robj(ptr_scalar, scalar);
|
819
824
|
mpfi_matrix_div_scalar(ptr_ret, ptr_self, ptr_scalar);
|
@@ -823,41 +828,41 @@ static VALUE r_mpfi_matrix_div_scalar (VALUE self, VALUE scalar){
|
|
823
828
|
}
|
824
829
|
|
825
830
|
|
826
|
-
static VALUE r_mpfi_matrix_include_p (VALUE self, VALUE other){
|
831
|
+
static VALUE r_mpfi_matrix_include_p (VALUE self, VALUE other) {
|
827
832
|
MPFIMatrix *ptr_self;
|
828
833
|
VALUE ret;
|
829
834
|
r_mpfi_get_matrix_struct(ptr_self, self);
|
830
835
|
ret = Qnil;
|
831
|
-
if(RTEST(rb_funcall(r_mpfi_matrix, eqq, 1, other))){
|
836
|
+
if (RTEST(rb_funcall(r_mpfi_matrix, eqq, 1, other))) {
|
832
837
|
MPFIMatrix *ptr_other;
|
833
838
|
r_mpfi_get_matrix_struct(ptr_other, other);
|
834
|
-
if(mpfi_matrix_include_p(ptr_self, ptr_other) == 0){
|
839
|
+
if (mpfi_matrix_include_p(ptr_self, ptr_other) == 0) {
|
835
840
|
ret = Qtrue;
|
836
841
|
}
|
837
|
-
}else if(RTEST(rb_funcall(r_mpfr_matrix, eqq, 1, other))){
|
842
|
+
} else if (RTEST(rb_funcall(r_mpfr_matrix, eqq, 1, other))) {
|
838
843
|
MPFRMatrix *ptr_other;
|
839
844
|
r_mpfr_get_matrix_struct(ptr_other, other);
|
840
|
-
if(mpfi_matrix_include_fr_p(ptr_self, ptr_other) == 0){
|
845
|
+
if (mpfi_matrix_include_fr_p(ptr_self, ptr_other) == 0) {
|
841
846
|
ret = Qtrue;
|
842
847
|
}
|
843
|
-
}else{
|
848
|
+
} else {
|
844
849
|
rb_raise(rb_eArgError, "Argument must be MPFI::Matrix or MPFR::Matrix instance.");
|
845
850
|
}
|
846
851
|
return ret;
|
847
852
|
}
|
848
853
|
|
849
|
-
static VALUE r_mpfi_matrix_strictly_include_p (VALUE self, VALUE other){
|
854
|
+
static VALUE r_mpfi_matrix_strictly_include_p (VALUE self, VALUE other) {
|
850
855
|
MPFIMatrix *ptr_self;
|
851
856
|
VALUE ret;
|
852
857
|
r_mpfi_get_matrix_struct(ptr_self, self);
|
853
858
|
ret = Qnil;
|
854
|
-
if(RTEST(rb_funcall(r_mpfi_matrix, eqq, 1, other))){
|
859
|
+
if (RTEST(rb_funcall(r_mpfi_matrix, eqq, 1, other))) {
|
855
860
|
MPFIMatrix *ptr_other;
|
856
861
|
r_mpfi_get_matrix_struct(ptr_other, other);
|
857
|
-
if(mpfi_matrix_strictly_include_p(ptr_self, ptr_other) == 0){
|
862
|
+
if (mpfi_matrix_strictly_include_p(ptr_self, ptr_other) == 0) {
|
858
863
|
ret = Qtrue;
|
859
864
|
}
|
860
|
-
}else{
|
865
|
+
} else {
|
861
866
|
rb_raise(rb_eArgError, "Argument must be MPFI::Matrix instance.");
|
862
867
|
}
|
863
868
|
return ret;
|
@@ -866,14 +871,14 @@ static VALUE r_mpfi_matrix_strictly_include_p (VALUE self, VALUE other){
|
|
866
871
|
static VALUE r_mpfi_matrix_bounded_p (VALUE self) {
|
867
872
|
MPFIMatrix *ptr_self;
|
868
873
|
r_mpfi_get_matrix_struct(ptr_self, self);
|
869
|
-
if(mpfi_matrix_bounded_p(ptr_self) == 0){
|
874
|
+
if (mpfi_matrix_bounded_p(ptr_self) == 0) {
|
870
875
|
return Qtrue;
|
871
|
-
}else{
|
876
|
+
} else {
|
872
877
|
return Qnil;
|
873
878
|
}
|
874
879
|
}
|
875
880
|
|
876
|
-
static VALUE r_mpfi_matrix_mid (VALUE self){
|
881
|
+
static VALUE r_mpfi_matrix_mid (VALUE self) {
|
877
882
|
MPFIMatrix *ptr_self;
|
878
883
|
VALUE val_ret;
|
879
884
|
MPFRMatrix *ptr_ret;
|
@@ -883,7 +888,7 @@ static VALUE r_mpfi_matrix_mid (VALUE self){
|
|
883
888
|
return val_ret;
|
884
889
|
}
|
885
890
|
|
886
|
-
static VALUE r_mpfi_matrix_mid_interval (VALUE self){
|
891
|
+
static VALUE r_mpfi_matrix_mid_interval (VALUE self) {
|
887
892
|
MPFIMatrix *ptr_self, *ptr_ret;
|
888
893
|
VALUE val_ret;
|
889
894
|
r_mpfi_get_matrix_struct(ptr_self, self);
|
@@ -892,34 +897,34 @@ static VALUE r_mpfi_matrix_mid_interval (VALUE self){
|
|
892
897
|
return val_ret;
|
893
898
|
}
|
894
899
|
|
895
|
-
static VALUE r_mpfi_matrix_intersect (VALUE self, VALUE other){
|
900
|
+
static VALUE r_mpfi_matrix_intersect (VALUE self, VALUE other) {
|
896
901
|
MPFIMatrix *ptr_self, *ptr_other, *ptr_ret;
|
897
902
|
VALUE val_ret;
|
898
903
|
r_mpfi_get_matrix_struct(ptr_self, self);
|
899
904
|
r_mpfi_get_matrix_struct(ptr_other, other);
|
900
905
|
r_mpfi_matrix_suitable_matrix_init(&val_ret, &ptr_ret, ptr_self->row, ptr_self->column);
|
901
|
-
if(mpfi_matrix_intersect(ptr_ret, ptr_self, ptr_other) == 0){
|
906
|
+
if (mpfi_matrix_intersect(ptr_ret, ptr_self, ptr_other) == 0) {
|
902
907
|
return val_ret;
|
903
|
-
}else{
|
908
|
+
} else {
|
904
909
|
return Qnil;
|
905
910
|
}
|
906
911
|
}
|
907
912
|
|
908
|
-
static VALUE r_mpfi_matrix_union (VALUE self, VALUE other){
|
913
|
+
static VALUE r_mpfi_matrix_union (VALUE self, VALUE other) {
|
909
914
|
MPFIMatrix *ptr_self, *ptr_other, *ptr_ret;
|
910
915
|
VALUE val_ret;
|
911
916
|
r_mpfi_get_matrix_struct(ptr_self, self);
|
912
917
|
r_mpfi_get_matrix_struct(ptr_other, other);
|
913
918
|
r_mpfi_matrix_suitable_matrix_init(&val_ret, &ptr_ret, ptr_self->row, ptr_self->column);
|
914
|
-
if(mpfi_matrix_union(ptr_ret, ptr_self, ptr_other) == 0){
|
919
|
+
if (mpfi_matrix_union(ptr_ret, ptr_self, ptr_other) == 0) {
|
915
920
|
return val_ret;
|
916
|
-
}else{
|
921
|
+
} else {
|
917
922
|
return Qnil;
|
918
923
|
}
|
919
924
|
}
|
920
925
|
|
921
926
|
|
922
|
-
static VALUE r_mpfi_matrix_max_diam_abs (VALUE self){
|
927
|
+
static VALUE r_mpfi_matrix_max_diam_abs (VALUE self) {
|
923
928
|
MPFIMatrix *ptr_self;
|
924
929
|
MPFR *ptr_ret;
|
925
930
|
VALUE ret_val;
|
@@ -930,14 +935,14 @@ static VALUE r_mpfi_matrix_max_diam_abs (VALUE self){
|
|
930
935
|
}
|
931
936
|
|
932
937
|
/* Return row size of matrix. */
|
933
|
-
static VALUE r_mpfi_square_matrix_dim (VALUE self){
|
938
|
+
static VALUE r_mpfi_square_matrix_dim (VALUE self) {
|
934
939
|
MPFIMatrix *ptr_self;
|
935
940
|
r_mpfi_get_matrix_struct(ptr_self, self);
|
936
941
|
return INT2FIX(ptr_self->row);
|
937
942
|
}
|
938
943
|
|
939
944
|
/* Return [matrix_l, matrix_r, indx]. */
|
940
|
-
static VALUE r_mpfi_square_matrix_lu_decomp (VALUE self){
|
945
|
+
static VALUE r_mpfi_square_matrix_lu_decomp (VALUE self) {
|
941
946
|
MPFIMatrix *ptr_self, *ptr_ret_l, *ptr_ret_u;
|
942
947
|
VALUE ret_l, ret_u, ret, ret_indx_ary;
|
943
948
|
int i, j, *indx;
|
@@ -945,23 +950,23 @@ static VALUE r_mpfi_square_matrix_lu_decomp (VALUE self){
|
|
945
950
|
r_mpfi_matrix_suitable_matrix_init (&ret_l, &ptr_ret_l, ptr_self->row, ptr_self->column);
|
946
951
|
r_mpfi_matrix_suitable_matrix_init (&ret_u, &ptr_ret_u, ptr_self->row, ptr_self->column);
|
947
952
|
indx = ALLOC_N(int, ptr_self->row);
|
948
|
-
if(mpfi_square_matrix_lu_decomp (ptr_ret_u, indx, ptr_self) >= 0){
|
953
|
+
if (mpfi_square_matrix_lu_decomp (ptr_ret_u, indx, ptr_self) >= 0) {
|
949
954
|
ret_indx_ary = rb_ary_new2(ptr_self->row);
|
950
|
-
for(i = 1; i < ptr_ret_u->row; i++){
|
951
|
-
for(j = 0; j < i; j++){
|
955
|
+
for (i = 1; i < ptr_ret_u->row; i++) {
|
956
|
+
for (j = 0; j < i; j++) {
|
952
957
|
mpfi_set(mpfi_matrix_get_element(ptr_ret_l, i, j), mpfi_matrix_get_element(ptr_ret_u, i, j));
|
953
958
|
mpfi_set_si(mpfi_matrix_get_element(ptr_ret_u, i, j), 0);
|
954
959
|
}
|
955
960
|
}
|
956
|
-
for(i = 0; i < ptr_ret_u->row; i++){
|
961
|
+
for (i = 0; i < ptr_ret_u->row; i++) {
|
957
962
|
mpfi_set_si(mpfi_matrix_get_element(ptr_ret_l, i, i), 1);
|
958
963
|
}
|
959
|
-
for(i = 0; i < ptr_ret_u->row; i++){
|
960
|
-
for(j = i + 1; j < ptr_ret_u->column; j++){
|
964
|
+
for (i = 0; i < ptr_ret_u->row; i++) {
|
965
|
+
for (j = i + 1; j < ptr_ret_u->column; j++) {
|
961
966
|
mpfi_set_si(mpfi_matrix_get_element(ptr_ret_l, i, j), 0);
|
962
967
|
}
|
963
968
|
}
|
964
|
-
for(i = 0; i < ptr_ret_u->row; i++){
|
969
|
+
for (i = 0; i < ptr_ret_u->row; i++) {
|
965
970
|
rb_ary_store(ret_indx_ary, i, INT2NUM(indx[i]));
|
966
971
|
}
|
967
972
|
ret = rb_ary_new3(3, ret_l, ret_u, ret_indx_ary);
|
@@ -972,7 +977,7 @@ static VALUE r_mpfi_square_matrix_lu_decomp (VALUE self){
|
|
972
977
|
return ret;
|
973
978
|
}
|
974
979
|
|
975
|
-
static VALUE r_mpfi_square_matrix_determinant (VALUE self){
|
980
|
+
static VALUE r_mpfi_square_matrix_determinant (VALUE self) {
|
976
981
|
MPFIMatrix *ptr_self;
|
977
982
|
MPFI *ptr_ret;
|
978
983
|
VALUE ret;
|
@@ -982,7 +987,7 @@ static VALUE r_mpfi_square_matrix_determinant (VALUE self){
|
|
982
987
|
return ret;
|
983
988
|
}
|
984
989
|
|
985
|
-
static VALUE r_mpfi_square_matrix_qr_decomp (VALUE self){
|
990
|
+
static VALUE r_mpfi_square_matrix_qr_decomp (VALUE self) {
|
986
991
|
MPFIMatrix *ptr_self, *ptr_q, *ptr_r;
|
987
992
|
VALUE q, r;
|
988
993
|
r_mpfi_get_matrix_struct(ptr_self, self);
|
@@ -992,7 +997,7 @@ static VALUE r_mpfi_square_matrix_qr_decomp (VALUE self){
|
|
992
997
|
return rb_ary_new3(2, q, r);
|
993
998
|
}
|
994
999
|
|
995
|
-
static VALUE r_mpfi_square_matrix_identity (VALUE self, VALUE size){
|
1000
|
+
static VALUE r_mpfi_square_matrix_identity (VALUE self, VALUE size) {
|
996
1001
|
VALUE ret;
|
997
1002
|
MPFIMatrix *ptr_ret;
|
998
1003
|
int s = NUM2INT(size);
|
@@ -1003,14 +1008,14 @@ static VALUE r_mpfi_square_matrix_identity (VALUE self, VALUE size){
|
|
1003
1008
|
|
1004
1009
|
|
1005
1010
|
/* Return size of data array which equals to column * row. */
|
1006
|
-
static VALUE r_mpfi_vector_dim (VALUE self){
|
1011
|
+
static VALUE r_mpfi_vector_dim (VALUE self) {
|
1007
1012
|
MPFIMatrix *ptr_self;
|
1008
1013
|
r_mpfi_get_matrix_struct(ptr_self, self);
|
1009
1014
|
return INT2FIX(ptr_self->size);
|
1010
1015
|
}
|
1011
1016
|
|
1012
1017
|
/* Take matrix for vector and return length of the vector. */
|
1013
|
-
static VALUE r_mpfi_vector_abs (VALUE self){
|
1018
|
+
static VALUE r_mpfi_vector_abs (VALUE self) {
|
1014
1019
|
MPFIMatrix *ptr_self;
|
1015
1020
|
VALUE ret;
|
1016
1021
|
MPFI *ptr_ret;
|
@@ -1021,7 +1026,7 @@ static VALUE r_mpfi_vector_abs (VALUE self){
|
|
1021
1026
|
}
|
1022
1027
|
|
1023
1028
|
/* Return element at _arg_.*/
|
1024
|
-
static VALUE r_mpfi_vector_element (VALUE self, VALUE arg){
|
1029
|
+
static VALUE r_mpfi_vector_element (VALUE self, VALUE arg) {
|
1025
1030
|
MPFIMatrix *ptr_self;
|
1026
1031
|
int i;
|
1027
1032
|
r_mpfi_get_matrix_struct(ptr_self, self);
|
@@ -1032,13 +1037,13 @@ static VALUE r_mpfi_vector_element (VALUE self, VALUE arg){
|
|
1032
1037
|
r_mpfi_make_struct_init(ret, ptr_ret);
|
1033
1038
|
mpfi_set(ptr_ret, ptr_self->data + i);
|
1034
1039
|
return ret;
|
1035
|
-
}else{
|
1040
|
+
} else {
|
1036
1041
|
return Qnil;
|
1037
1042
|
}
|
1038
1043
|
}
|
1039
1044
|
|
1040
1045
|
/* Set _robj_ to _arg_ th element. */
|
1041
|
-
static VALUE r_mpfi_vector_set_element (VALUE self, VALUE arg, VALUE robj){
|
1046
|
+
static VALUE r_mpfi_vector_set_element (VALUE self, VALUE arg, VALUE robj) {
|
1042
1047
|
MPFIMatrix *ptr_self;
|
1043
1048
|
int i;
|
1044
1049
|
r_mpfi_get_matrix_struct(ptr_self, self);
|
@@ -1050,83 +1055,81 @@ static VALUE r_mpfi_vector_set_element (VALUE self, VALUE arg, VALUE robj){
|
|
1050
1055
|
}
|
1051
1056
|
|
1052
1057
|
/* Evaluate block with each element of vector. */
|
1053
|
-
static VALUE r_mpfi_vector_each_element (VALUE self){
|
1058
|
+
static VALUE r_mpfi_vector_each_element (VALUE self) {
|
1054
1059
|
MPFIMatrix *ptr_self;
|
1055
|
-
VALUE ret
|
1056
|
-
MPFI *tmp_ptr;
|
1060
|
+
VALUE ret;
|
1057
1061
|
int i;
|
1062
|
+
RETURN_ENUMERATOR(self, 0, NULL);
|
1058
1063
|
ret = Qnil;
|
1059
1064
|
r_mpfi_get_matrix_struct(ptr_self, self);
|
1060
|
-
r_mpfi_make_struct_init(tmp, tmp_ptr);
|
1061
1065
|
for (i = 0; i < ptr_self->size; i++) {
|
1062
|
-
|
1063
|
-
ret = rb_yield(
|
1066
|
+
volatile VALUE el = r_mpfi_make_new_fi_obj(ptr_self->data + i);
|
1067
|
+
ret = rb_yield(el);
|
1064
1068
|
}
|
1065
1069
|
return ret;
|
1066
1070
|
}
|
1067
1071
|
|
1068
1072
|
/* Evaluate block with each element and its index. */
|
1069
|
-
static VALUE r_mpfi_vector_each_element_with_index (VALUE self){
|
1073
|
+
static VALUE r_mpfi_vector_each_element_with_index (VALUE self) {
|
1070
1074
|
MPFIMatrix *ptr_self;
|
1071
|
-
VALUE ret
|
1072
|
-
MPFI *tmp_ptr;
|
1075
|
+
VALUE ret;
|
1073
1076
|
int i;
|
1077
|
+
RETURN_ENUMERATOR(self, 0, NULL);
|
1074
1078
|
r_mpfi_get_matrix_struct(ptr_self, self);
|
1075
|
-
r_mpfi_make_struct_init(tmp, tmp_ptr);
|
1076
1079
|
ret = Qnil;
|
1077
1080
|
for (i = 0; i < ptr_self->size; i++) {
|
1078
|
-
|
1079
|
-
ret = rb_yield(rb_ary_new3(2,
|
1081
|
+
volatile VALUE el = r_mpfi_make_new_fi_obj(ptr_self->data + i);
|
1082
|
+
ret = rb_yield(rb_ary_new3(2, el, INT2NUM(i)));
|
1080
1083
|
}
|
1081
1084
|
return ret;
|
1082
1085
|
}
|
1083
1086
|
|
1084
|
-
static VALUE r_mpfi_vector_inner_product (VALUE self, VALUE arg){
|
1087
|
+
static VALUE r_mpfi_vector_inner_product (VALUE self, VALUE arg) {
|
1085
1088
|
MPFIMatrix *ptr_self, *ptr_arg;
|
1086
1089
|
VALUE ret;
|
1087
1090
|
MPFI *ptr_ret;
|
1088
1091
|
r_mpfi_get_matrix_struct(ptr_self, self);
|
1089
1092
|
r_mpfi_get_matrix_struct(ptr_arg, arg);
|
1090
1093
|
r_mpfi_make_struct_init(ret, ptr_ret);
|
1091
|
-
if(ptr_self->size == ptr_arg->size){
|
1094
|
+
if (ptr_self->size == ptr_arg->size) {
|
1092
1095
|
mpfi_matrix_inner_product(ptr_ret, ptr_self, ptr_arg);
|
1093
|
-
}else{
|
1096
|
+
} else {
|
1094
1097
|
rb_raise(rb_eArgError, "Vectors must have same size.");
|
1095
1098
|
}
|
1096
1099
|
return ret;
|
1097
1100
|
}
|
1098
1101
|
|
1099
|
-
static VALUE r_mpfi_vector_distance_from (VALUE self, VALUE arg){
|
1102
|
+
static VALUE r_mpfi_vector_distance_from (VALUE self, VALUE arg) {
|
1100
1103
|
MPFIMatrix *ptr_self, *ptr_arg;
|
1101
1104
|
VALUE ret;
|
1102
1105
|
MPFI *ptr_ret;
|
1103
1106
|
r_mpfi_get_matrix_struct(ptr_self, self);
|
1104
1107
|
r_mpfi_get_matrix_struct(ptr_arg, arg);
|
1105
1108
|
r_mpfi_make_struct_init(ret, ptr_ret);
|
1106
|
-
if(ptr_self->size == ptr_arg->size){
|
1109
|
+
if (ptr_self->size == ptr_arg->size) {
|
1107
1110
|
mpfi_matrix_vector_distance(ptr_ret, ptr_self, ptr_arg);
|
1108
|
-
}else{
|
1111
|
+
} else {
|
1109
1112
|
rb_raise(rb_eArgError, "Vectors must have same size.");
|
1110
1113
|
}
|
1111
1114
|
return ret;
|
1112
1115
|
}
|
1113
1116
|
|
1114
|
-
static VALUE r_mpfi_vector_distance_center_pts (VALUE self, VALUE arg){
|
1117
|
+
static VALUE r_mpfi_vector_distance_center_pts (VALUE self, VALUE arg) {
|
1115
1118
|
MPFIMatrix *ptr_self, *ptr_arg;
|
1116
1119
|
VALUE ret;
|
1117
1120
|
MPFR *ptr_ret;
|
1118
1121
|
r_mpfi_get_matrix_struct(ptr_self, self);
|
1119
1122
|
r_mpfi_get_matrix_struct(ptr_arg, arg);
|
1120
1123
|
r_mpfr_make_struct_init(ret, ptr_ret);
|
1121
|
-
if(ptr_self->size == ptr_arg->size){
|
1124
|
+
if (ptr_self->size == ptr_arg->size) {
|
1122
1125
|
mpfi_matrix_vector_distance_center_pts(ptr_ret, ptr_self, ptr_arg);
|
1123
|
-
}else{
|
1126
|
+
} else {
|
1124
1127
|
rb_raise(rb_eArgError, "Vectors must have same size.");
|
1125
1128
|
}
|
1126
1129
|
return ret;
|
1127
1130
|
}
|
1128
1131
|
|
1129
|
-
static VALUE r_mpfi_vector_midpoint (VALUE self, VALUE arg){
|
1132
|
+
static VALUE r_mpfi_vector_midpoint (VALUE self, VALUE arg) {
|
1130
1133
|
MPFIMatrix *ptr_self, *ptr_arg, *ptr_ret;
|
1131
1134
|
VALUE ret;
|
1132
1135
|
r_mpfi_get_matrix_struct(ptr_self, self);
|
@@ -1136,50 +1139,50 @@ static VALUE r_mpfi_vector_midpoint (VALUE self, VALUE arg){
|
|
1136
1139
|
return ret;
|
1137
1140
|
}
|
1138
1141
|
|
1139
|
-
static VALUE r_mpfi_vector_normalize (VALUE self){
|
1142
|
+
static VALUE r_mpfi_vector_normalize (VALUE self) {
|
1140
1143
|
MPFIMatrix *ptr_self, *ptr_ret;
|
1141
1144
|
VALUE ret;
|
1142
1145
|
r_mpfi_get_matrix_struct(ptr_self, self);
|
1143
1146
|
r_mpfi_matrix_suitable_matrix_init (&ret, &ptr_ret, ptr_self->row, ptr_self->column);
|
1144
|
-
if(mpfi_vector_normalize(ptr_ret, ptr_self) == 0){
|
1147
|
+
if (mpfi_vector_normalize(ptr_ret, ptr_self) == 0) {
|
1145
1148
|
return ret;
|
1146
|
-
}else{
|
1149
|
+
} else {
|
1147
1150
|
return Qnil;
|
1148
1151
|
}
|
1149
1152
|
}
|
1150
1153
|
|
1151
1154
|
/* Return normalized vector of _self_. This method is destroy method. */
|
1152
|
-
static VALUE r_mpfi_vector_normalize2 (VALUE self){
|
1155
|
+
static VALUE r_mpfi_vector_normalize2 (VALUE self) {
|
1153
1156
|
MPFIMatrix *ptr_self, tmp;
|
1154
1157
|
VALUE ret;
|
1155
1158
|
r_mpfi_get_matrix_struct(ptr_self, self);
|
1156
1159
|
ret = self;
|
1157
1160
|
mpfi_matrix_init(&tmp, ptr_self->column, ptr_self->row);
|
1158
|
-
if(mpfi_vector_normalize(&tmp, ptr_self) == 0){
|
1161
|
+
if (mpfi_vector_normalize(&tmp, ptr_self) == 0) {
|
1159
1162
|
mpfi_matrix_set(ptr_self, &tmp);
|
1160
|
-
}else{
|
1163
|
+
} else {
|
1161
1164
|
ret = Qnil;
|
1162
1165
|
}
|
1163
1166
|
mpfi_matrix_clear(&tmp);
|
1164
1167
|
return ret;
|
1165
1168
|
}
|
1166
1169
|
|
1167
|
-
static VALUE r_mpfi_vector_set_length (VALUE self, VALUE arg){
|
1170
|
+
static VALUE r_mpfi_vector_set_length (VALUE self, VALUE arg) {
|
1168
1171
|
MPFIMatrix *ptr_self, *ptr_ret;
|
1169
1172
|
VALUE ret, returned_value;
|
1170
1173
|
MPFR *ptr_l;
|
1171
1174
|
returned_value = Qnil;
|
1172
1175
|
r_mpfi_get_matrix_struct(ptr_self, self);
|
1173
1176
|
r_mpfi_matrix_suitable_matrix_init (&ret, &ptr_ret, ptr_self->row, ptr_self->column);
|
1174
|
-
if(RTEST(rb_funcall(r_mpfr_class, eqq, 1, arg))){
|
1177
|
+
if (RTEST(rb_funcall(r_mpfr_class, eqq, 1, arg))) {
|
1175
1178
|
r_mpfr_get_struct(ptr_l, arg);
|
1176
|
-
if(mpfi_vector_set_length(ptr_ret, ptr_self, ptr_l) == 0){
|
1179
|
+
if (mpfi_vector_set_length(ptr_ret, ptr_self, ptr_l) == 0) {
|
1177
1180
|
returned_value = ret;
|
1178
1181
|
}
|
1179
|
-
}else{
|
1182
|
+
} else {
|
1180
1183
|
r_mpfr_temp_alloc_init(ptr_l);
|
1181
1184
|
r_mpfr_set_robj(ptr_l, arg, GMP_RNDN);
|
1182
|
-
if(mpfi_vector_set_length(ptr_ret, ptr_self, ptr_l) == 0){
|
1185
|
+
if (mpfi_vector_set_length(ptr_ret, ptr_self, ptr_l) == 0) {
|
1183
1186
|
returned_value = ret;
|
1184
1187
|
}
|
1185
1188
|
r_mpfr_temp_free(ptr_l);
|
@@ -1187,23 +1190,23 @@ static VALUE r_mpfi_vector_set_length (VALUE self, VALUE arg){
|
|
1187
1190
|
return returned_value;
|
1188
1191
|
}
|
1189
1192
|
|
1190
|
-
static VALUE r_mpfi_vector_set_length2 (VALUE self, VALUE arg){
|
1193
|
+
static VALUE r_mpfi_vector_set_length2 (VALUE self, VALUE arg) {
|
1191
1194
|
MPFIMatrix *ptr_self, *ptr_ret;
|
1192
1195
|
VALUE ret, returned_value;
|
1193
1196
|
MPFR *ptr_l;
|
1194
1197
|
returned_value = Qnil;
|
1195
1198
|
r_mpfi_get_matrix_struct(ptr_self, self);
|
1196
1199
|
r_mpfi_matrix_suitable_matrix_init (&ret, &ptr_ret, ptr_self->row, ptr_self->column);
|
1197
|
-
if(RTEST(rb_funcall(r_mpfi_class, eqq, 1, arg))){
|
1200
|
+
if (RTEST(rb_funcall(r_mpfi_class, eqq, 1, arg))) {
|
1198
1201
|
r_mpfr_get_struct(ptr_l, arg);
|
1199
|
-
if(mpfi_vector_set_length(ptr_ret, ptr_self, ptr_l) == 0){
|
1202
|
+
if (mpfi_vector_set_length(ptr_ret, ptr_self, ptr_l) == 0) {
|
1200
1203
|
mpfi_matrix_set(ptr_self, ptr_ret);
|
1201
1204
|
returned_value = self;
|
1202
1205
|
}
|
1203
|
-
}else{
|
1206
|
+
} else {
|
1204
1207
|
r_mpfr_temp_alloc_init(ptr_l);
|
1205
1208
|
r_mpfr_set_robj(ptr_l, arg, GMP_RNDN);
|
1206
|
-
if(mpfi_vector_set_length(ptr_ret, ptr_self, ptr_l) == 0){
|
1209
|
+
if (mpfi_vector_set_length(ptr_ret, ptr_self, ptr_l) == 0) {
|
1207
1210
|
mpfi_matrix_set(ptr_self, ptr_ret);
|
1208
1211
|
returned_value = self;
|
1209
1212
|
}
|
@@ -1213,7 +1216,7 @@ static VALUE r_mpfi_vector_set_length2 (VALUE self, VALUE arg){
|
|
1213
1216
|
}
|
1214
1217
|
|
1215
1218
|
|
1216
|
-
static VALUE r_mpfr_matrix_to_fi_matrix(VALUE self){
|
1219
|
+
static VALUE r_mpfr_matrix_to_fi_matrix (VALUE self) {
|
1217
1220
|
MPFRMatrix *ptr;
|
1218
1221
|
VALUE ret;
|
1219
1222
|
MPFIMatrix *ptr_ret;
|
@@ -1223,7 +1226,7 @@ static VALUE r_mpfr_matrix_to_fi_matrix(VALUE self){
|
|
1223
1226
|
return ret;
|
1224
1227
|
}
|
1225
1228
|
|
1226
|
-
void Init_matrix(){
|
1229
|
+
void Init_matrix() {
|
1227
1230
|
/* Initialization of MPFI::Matrix, MPFI::SquareMatrix, MPFI::ColumnVector and MPFI::RowVector */
|
1228
1231
|
VALUE tmp_r_mpfi_class = rb_define_class("MPFI", rb_cNumeric);
|
1229
1232
|
r_mpfi_matrix = rb_define_class_under(tmp_r_mpfi_class, "Matrix", rb_cObject);
|
@@ -1231,7 +1234,7 @@ void Init_matrix(){
|
|
1231
1234
|
r_mpfi_col_vector = rb_define_class_under(tmp_r_mpfi_class, "ColumnVector", r_mpfi_matrix);
|
1232
1235
|
r_mpfi_row_vector = rb_define_class_under(tmp_r_mpfi_class, "RowVector", r_mpfi_matrix);
|
1233
1236
|
|
1234
|
-
rb_define_singleton_method(
|
1237
|
+
rb_define_singleton_method(tmp_r_mpfi_class, "Matrix", r_mpfi_matrix_global_new, -1);
|
1235
1238
|
rb_define_alloc_func(r_mpfi_matrix, r_mpfi_matrix_alloc);
|
1236
1239
|
rb_define_private_method(r_mpfi_matrix, "initialize", r_mpfi_matrix_initialize, -1);
|
1237
1240
|
rb_define_private_method(r_mpfi_matrix, "initialize_copy", r_mpfi_matrix_initialize_copy, 1);
|
@@ -1312,7 +1315,7 @@ void Init_matrix(){
|
|
1312
1315
|
rb_define_method(r_mpfi_square_matrix, "qr_decomp", r_mpfi_square_matrix_qr_decomp, 0);
|
1313
1316
|
|
1314
1317
|
rb_define_singleton_method(r_mpfi_square_matrix, "identity", r_mpfi_square_matrix_identity, 1);
|
1315
|
-
|
1318
|
+
|
1316
1319
|
/* Initialization of MPFI::Vector module */
|
1317
1320
|
r_mpfi_vector_module = rb_define_module_under(tmp_r_mpfi_class, "Vector");
|
1318
1321
|
|