ruby-mpfi 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -20,5 +20,16 @@ dir_config("mpfr")
20
20
  dir_config("mpfi")
21
21
  dir_config("gmp")
22
22
  if have_header('mpfr.h') && have_library('mpfr') && have_header('gmp.h') && have_library('gmp')
23
+ ruby_mpfr_header_dir = nil
24
+ begin
25
+ require "rubygems"
26
+ spec = Gem::Specification.find_by_name("ruby-mpfr")
27
+ ruby_mpfr_header_dir = File.join(spec.full_gem_path, 'ext/mpfr')
28
+ rescue LoadError
29
+ end
30
+ unless find_header("ruby_mpfr.h", ruby_mpfr_header_dir)
31
+ header_not_found("ruby_mpfr.h")
32
+ end
33
+ find_header("ruby_mpfi.h", File.join(File.dirname(__FILE__), "../../mpfi"))
23
34
  create_makefile("mpfi/complex")
24
35
  end
@@ -66,9 +66,9 @@ static VALUE r_mpfi_complex_initialize_copy (VALUE self, VALUE other){
66
66
  /* Return real part. */
67
67
  static VALUE r_mpfi_complex_real (VALUE self){
68
68
  MPFIComplex *ptr_self;
69
- r_mpfi_get_complex_struct(ptr_self, self);
70
69
  VALUE ret;
71
70
  MPFI *ptr_ret;
71
+ r_mpfi_get_complex_struct(ptr_self, self);
72
72
  r_mpfi_make_struct_init(ret, ptr_ret);
73
73
  mpfi_set(ptr_ret, ptr_self->re);
74
74
  return ret;
@@ -77,9 +77,9 @@ static VALUE r_mpfi_complex_real (VALUE self){
77
77
  /* Return imaginary part. */
78
78
  static VALUE r_mpfi_complex_imaginary (VALUE self){
79
79
  MPFIComplex *ptr_self;
80
- r_mpfi_get_complex_struct(ptr_self, self);
81
80
  VALUE ret;
82
81
  MPFI *ptr_ret;
82
+ r_mpfi_get_complex_struct(ptr_self, self);
83
83
  r_mpfi_make_struct_init(ret, ptr_ret);
84
84
  mpfi_set(ptr_ret, ptr_self->im);
85
85
  return ret;
@@ -88,9 +88,9 @@ static VALUE r_mpfi_complex_imaginary (VALUE self){
88
88
  /* If _p1_ is 0, return real part. If _p1_ is 1, return imaginary part. */
89
89
  static VALUE r_mpfi_complex_element (VALUE self, VALUE arg){
90
90
  MPFIComplex *ptr_self;
91
- r_mpfi_get_complex_struct(ptr_self, self);
92
91
  VALUE ret;
93
92
  MPFI *ptr_ret;
93
+ r_mpfi_get_complex_struct(ptr_self, self);
94
94
  r_mpfi_make_struct_init(ret, ptr_ret);
95
95
  switch(NUM2INT(arg)){
96
96
  case 0:
@@ -109,8 +109,8 @@ static VALUE r_mpfi_complex_element (VALUE self, VALUE arg){
109
109
  /* Return conjugate complex number. */
110
110
  static VALUE r_mpfi_complex_conjugate (VALUE self){
111
111
  MPFIComplex *ptr_self, *ptr_ret;
112
- r_mpfi_get_complex_struct(ptr_self, self);
113
112
  VALUE ret;
113
+ r_mpfi_get_complex_struct(ptr_self, self);
114
114
  r_mpfi_make_complex_struct_init(ret, ptr_ret);
115
115
  mpfi_complex_conjugate(ptr_ret, ptr_self);
116
116
  return ret;
@@ -130,15 +130,16 @@ static VALUE r_mpfi_complex_conjugate (VALUE self){
130
130
  /* String for inspect. */
131
131
  static VALUE r_mpfi_complex_inspect(VALUE self){
132
132
  MPFIComplex *ptr_s;
133
- r_mpfi_get_complex_struct(ptr_s, self);
134
133
  char *ret_str;
134
+ VALUE ret_val;
135
+ r_mpfi_get_complex_struct(ptr_s, self);
135
136
  if (!mpfr_asprintf(&ret_str, "#<MPFI:%lx,['%.Re %.Re', '%.Re %.Re'], [%d, %d]>",
136
137
  NUM2LONG(rb_funcall(self, object_id, 0)), r_mpfi_left_ptr(ptr_s->re),
137
138
  r_mpfi_right_ptr(ptr_s->re), r_mpfi_left_ptr(ptr_s->im), r_mpfi_right_ptr(ptr_s->im),
138
139
  mpfi_get_prec(ptr_s->re), mpfi_get_prec(ptr_s->im))) {
139
140
  rb_raise(rb_eFatal, "Can not allocate a string by mpfr_asprintf.");
140
141
  }
141
- VALUE ret_val = rb_str_new2(ret_str);
142
+ ret_val = rb_str_new2(ret_str);
142
143
  mpfr_free_str(ret_str);
143
144
  return ret_val;
144
145
  }
@@ -146,9 +147,10 @@ static VALUE r_mpfi_complex_inspect(VALUE self){
146
147
  /* Return array including strings which the elements is converted to by _p1_. */
147
148
  static VALUE r_mpfi_complex_str_ary(VALUE self, VALUE format_str){
148
149
  MPFIComplex *ptr_self;
149
- r_mpfi_get_complex_struct(ptr_self, self);
150
- char *format = StringValuePtr(format_str), *tmp_str;
150
+ char *format, *tmp_str;
151
151
  VALUE ret_val[2];
152
+ r_mpfi_get_complex_struct(ptr_self, self);
153
+ format = StringValuePtr(format_str);
152
154
  gmp_asprintf(&tmp_str, format, ptr_self->re);
153
155
  ret_val[0] = rb_str_new2(tmp_str);
154
156
  free(tmp_str);
@@ -161,9 +163,9 @@ static VALUE r_mpfi_complex_str_ary(VALUE self, VALUE format_str){
161
163
  /* Return _self_ + _p1_.*/
162
164
  static VALUE r_mpfi_complex_add (VALUE self, VALUE other){
163
165
  MPFIComplex *ptr_self, *ptr_other, *ptr_ret;
166
+ VALUE ret;
164
167
  r_mpfi_get_complex_struct(ptr_self, self);
165
168
  r_mpfi_get_complex_struct(ptr_other, other);
166
- VALUE ret;
167
169
  r_mpfi_make_complex_struct_init(ret, ptr_ret);
168
170
  mpfi_complex_add(ptr_ret, ptr_self, ptr_other);
169
171
  return ret;
@@ -172,9 +174,9 @@ static VALUE r_mpfi_complex_add (VALUE self, VALUE other){
172
174
  /* Return _self_ - _p1_.*/
173
175
  static VALUE r_mpfi_complex_sub (VALUE self, VALUE other){
174
176
  MPFIComplex *ptr_self, *ptr_other, *ptr_ret;
177
+ VALUE ret;
175
178
  r_mpfi_get_complex_struct(ptr_self, self);
176
179
  r_mpfi_get_complex_struct(ptr_other, other);
177
- VALUE ret;
178
180
  r_mpfi_make_complex_struct_init(ret, ptr_ret);
179
181
  mpfi_complex_sub(ptr_ret, ptr_self, ptr_other);
180
182
  return ret;
@@ -183,9 +185,9 @@ static VALUE r_mpfi_complex_sub (VALUE self, VALUE other){
183
185
  /* Return _self_ * _p1_.*/
184
186
  static VALUE r_mpfi_complex_mul (VALUE self, VALUE other){
185
187
  MPFIComplex *ptr_self, *ptr_other, *ptr_ret;
188
+ VALUE ret;
186
189
  r_mpfi_get_complex_struct(ptr_self, self);
187
190
  r_mpfi_get_complex_struct(ptr_other, other);
188
- VALUE ret;
189
191
  r_mpfi_make_complex_struct_init(ret, ptr_ret);
190
192
  mpfi_complex_mul(ptr_ret, ptr_self, ptr_other);
191
193
  return ret;
@@ -194,9 +196,9 @@ static VALUE r_mpfi_complex_mul (VALUE self, VALUE other){
194
196
  /* Return _self_ / _p1_.*/
195
197
  static VALUE r_mpfi_complex_div (VALUE self, VALUE other){
196
198
  MPFIComplex *ptr_self, *ptr_other, *ptr_ret;
199
+ VALUE ret;
197
200
  r_mpfi_get_complex_struct(ptr_self, self);
198
201
  r_mpfi_get_complex_struct(ptr_other, other);
199
- VALUE ret;
200
202
  r_mpfi_make_complex_struct_init(ret, ptr_ret);
201
203
  mpfi_complex_div(ptr_ret, ptr_self, ptr_other);
202
204
  return ret;
@@ -19,5 +19,19 @@ dir_config('mpfi')
19
19
  dir_config('gmp')
20
20
 
21
21
  if have_header('mpfr.h') && have_library('mpfr') && have_header('mpfi.h') && have_library('mpfi') && have_header('gmp.h') && have_library('gmp')
22
+ ruby_mpfr_dir = nil
23
+ begin
24
+ require "rubygems"
25
+ spec = Gem::Specification.find_by_name("ruby-mpfr")
26
+ ruby_mpfr_dir = File.join(spec.full_gem_path, 'ext')
27
+ rescue LoadError
28
+ end
29
+ unless find_header("ruby_mpfr.h", File.join(ruby_mpfr_dir, 'mpfr'))
30
+ header_not_found("ruby_mpfr.h")
31
+ end
32
+ unless find_header("ruby_mpfr_matrix.h", File.join(ruby_mpfr_dir, 'mpfr_matrix/mpfr'))
33
+ header_not_found("ruby_mpfr_matrix.h")
34
+ end
35
+ find_header("ruby_mpfi.h", File.join(File.dirname(__FILE__), "../../mpfi"))
22
36
  create_makefile("mpfi/matrix")
23
37
  end
@@ -1,12 +1,12 @@
1
1
  #include "ruby_mpfi_matrix.h"
2
2
 
3
3
  void mpfi_matrix_init(MPFIMatrix *mat, int row, int column){
4
+ int i;
4
5
  mat->row = row;
5
6
  mat->column = column;
6
7
  mat->size = row * column;
7
8
  /* mat->data = (MPFI *)malloc(sizeof(MPFI) * mat->size); */
8
9
  mat->data = ALLOC_N(MPFI, mat->size);
9
- int i;
10
10
  for(i = 0; i < mat->size; i++){
11
11
  mpfi_init(mat->data + i);
12
12
  }
@@ -305,8 +305,8 @@ int mpfi_matrix_union(MPFIMatrix *z, MPFIMatrix *x, MPFIMatrix *y){
305
305
 
306
306
  void mpfi_matrix_inner_product(MPFI *pr, MPFIMatrix *x, MPFIMatrix *y){
307
307
  MPFI *tmp;
308
- r_mpfi_temp_alloc_init(tmp);
309
308
  int i;
309
+ r_mpfi_temp_alloc_init(tmp);
310
310
  mpfi_set_si(pr, 0);
311
311
  for(i = 0; i < x->size; i++){
312
312
  mpfi_mul(tmp, x->data + i, y->data + i);
@@ -317,8 +317,8 @@ void mpfi_matrix_inner_product(MPFI *pr, MPFIMatrix *x, MPFIMatrix *y){
317
317
 
318
318
  void mpfi_matrix_vector_distance(MPFI *distance, MPFIMatrix *x, MPFIMatrix *y){
319
319
  MPFI *tmp;
320
- r_mpfi_temp_alloc_init(tmp);
321
320
  int i;
321
+ r_mpfi_temp_alloc_init(tmp);
322
322
  mpfi_set_si(distance, 0);
323
323
  for(i = 0; i < x->size; i++){
324
324
  mpfi_sub(tmp, x->data + i, y->data + i);
@@ -344,8 +344,8 @@ void mpfi_matrix_vector_distance_center_pts(MPFR *distance, MPFIMatrix *x, MPFIM
344
344
 
345
345
  void mpfi_matrix_vector_norm(MPFI *norm, MPFIMatrix *x){
346
346
  MPFI *tmp;
347
- r_mpfi_temp_alloc_init(tmp);
348
347
  int i;
348
+ r_mpfi_temp_alloc_init(tmp);
349
349
  mpfi_set_si(norm, 0);
350
350
  for(i = 0; i < x->size; i++){
351
351
  mpfi_mul(tmp, x->data + i, x->data + i);
@@ -357,9 +357,9 @@ void mpfi_matrix_vector_norm(MPFI *norm, MPFIMatrix *x){
357
357
 
358
358
  void mpfi_matrix_max_norm(MPFI *norm, MPFIMatrix *x){
359
359
  MPFI *tmp, *abs;
360
+ int i;
360
361
  r_mpfi_temp_alloc_init(tmp);
361
362
  r_mpfi_temp_alloc_init(abs);
362
- int i;
363
363
  mpfi_set_si(norm, 0);
364
364
  for(i = 0; i < x->size; i++){
365
365
  mpfi_abs(abs, x->data + i);
@@ -395,24 +395,24 @@ void mpfi_matrix_max_diam_abs(MPFR *diam, MPFIMatrix *x){
395
395
  /* ------------------- vector --------------------- */
396
396
 
397
397
  void mpfi_col_vector_init(MPFIMatrix *mat, int row){
398
+ int i;
398
399
  mat->row = row;
399
400
  mat->column = 1;
400
401
  mat->size = row;
401
402
  /* mat->data = (MPFI *)malloc(sizeof(MPF) * mat->size); */
402
403
  mat->data = ALLOC_N(MPFI, mat->size);
403
- int i;
404
404
  for(i = 0; i < mat->size; i++){
405
405
  mpfi_init(mat->data + i);
406
406
  }
407
407
  }
408
408
 
409
409
  void mpfi_row_vector_init(MPFIMatrix *mat, int column){
410
+ int i;
410
411
  mat->row = 1;
411
412
  mat->column = column;
412
413
  mat->size = column;
413
414
  /* mat->data = (MPFI *)malloc(sizeof(MPF) * mat->size); */
414
415
  mat->data = ALLOC_N(MPFI, mat->size);
415
- int i;
416
416
  for(i = 0; i < mat->size; i++){
417
417
  mpfi_init(mat->data + i);
418
418
  }
@@ -421,12 +421,12 @@ void mpfi_row_vector_init(MPFIMatrix *mat, int column){
421
421
  /* If length of MPFIMatrix *x is zero, return 1. Otherwise return 0. */
422
422
  int mpfi_vector_normalize(MPFIMatrix *new, MPFIMatrix *x){
423
423
  MPFRMatrix *fr_mat;
424
+ MPFR *norm;
425
+ int i, j, index, ret = 0;
424
426
  r_mpfr_matrix_temp_alloc_init(fr_mat, x->row, x->column);
425
427
  mpfi_matrix_mid(fr_mat, x);
426
- MPFR *norm;
427
428
  r_mpfr_temp_alloc_init(norm);
428
429
  mpfr_matrix_vector_norm(norm, fr_mat);
429
- int i, j, index, ret = 0;
430
430
  if(mpfr_cmp_ui(norm, 0) > 0){
431
431
  for(j = 0; j < x->column; j++){
432
432
  index = j * x->row;
@@ -454,11 +454,11 @@ void mpfi_vector_midpoint(MPFIMatrix *new, MPFIMatrix *x, MPFIMatrix *y){
454
454
  int mpfi_vector_set_length(MPFIMatrix *new, MPFIMatrix *x, MPFR *length){
455
455
  MPFI *norm_i;
456
456
  MPFR *factor_r;
457
+ int i, j, index, ret = 0;
457
458
  r_mpfi_temp_alloc_init(norm_i);
458
459
  r_mpfr_temp_alloc_init(factor_r);
459
460
  mpfi_matrix_vector_norm(norm_i, x);
460
461
  mpfi_mid(factor_r, norm_i);
461
- int i, j, index, ret = 0;
462
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);
@@ -629,8 +629,9 @@ void mpfi_square_matrix_determinant(MPFI *det, MPFIMatrix *x){
629
629
  mpfi_3d_square_matrix_determinant(det, x);
630
630
  }else{
631
631
  MPFIMatrix *ptr_lu;
632
+ int *indx, i;
632
633
  r_mpfi_matrix_temp_alloc_init(ptr_lu, x->row, x->column);
633
- int indx[x->row], i;
634
+ indx = (int *) malloc(sizeof(int) * x->row);
634
635
  if((i = mpfi_square_matrix_lu_decomp (ptr_lu, indx, x)) >= 0){
635
636
  if (i == 0) {
636
637
  mpfi_set_si(det, 1);
@@ -644,22 +645,22 @@ void mpfi_square_matrix_determinant(MPFI *det, MPFIMatrix *x){
644
645
  mpfi_set_ui(det, 0);
645
646
  }
646
647
  r_mpfi_matrix_temp_free(ptr_lu);
648
+ free(indx);
647
649
  }
648
-
649
650
  }
650
651
 
651
652
  void mpfi_square_matrix_qr_decomp(MPFIMatrix *q, MPFIMatrix *r, MPFIMatrix *x){
652
653
  MPFIMatrix *q_mat, *r_mat;
654
+ int size, i, j, k, ind1, ind2, ind3;
655
+ MPFIMatrix *ary;
656
+ MPFI *tmp;
653
657
  r_mpfi_matrix_temp_alloc_init(q_mat, q->row, q->column);
654
658
  r_mpfi_matrix_temp_alloc_init(r_mat, r->row, r->column);
655
659
 
656
- int size = x->row;
657
- MPFIMatrix *ary;
660
+ size = x->row;
658
661
  r_mpfi_matrix_temp_alloc_init(ary, size, size);
659
662
  mpfi_matrix_set(ary, x);
660
- MPFI *tmp;
661
663
  r_mpfi_temp_alloc_init(tmp);
662
- int i, j, k, ind1, ind2, ind3;
663
664
  for (i = 0; i < size; i++) {
664
665
  ind1 = i * size;
665
666
  ind2 = i + ind1;
@@ -707,5 +708,4 @@ void mpfi_square_matrix_identity(MPFIMatrix *id){
707
708
  }
708
709
  }
709
710
  }
710
-
711
711
  }
@@ -273,10 +273,10 @@ static VALUE r_mpfi_row_vector_initialize (VALUE self, VALUE arg){
273
273
  static VALUE r_mpfi_matrix_marshal_dump(VALUE self)
274
274
  {
275
275
  MPFIMatrix *ptr;
276
- r_mpfi_get_matrix_struct(ptr, self);
277
276
  int i;
278
277
  char *tmp_str;
279
278
  VALUE ret_ary;
279
+ r_mpfi_get_matrix_struct(ptr, self);
280
280
  ret_ary = rb_ary_new();
281
281
  rb_ary_push(ret_ary, INT2FIX(ptr->row));
282
282
  rb_ary_push(ret_ary, INT2FIX(ptr->column));
@@ -293,15 +293,15 @@ static VALUE r_mpfi_matrix_marshal_dump(VALUE self)
293
293
  static VALUE r_mpfi_matrix_marshal_load(VALUE self, VALUE dump_ary)
294
294
  {
295
295
  MPFIMatrix *ptr;
296
+ int i;
297
+ char *dump;
298
+ VALUE dump_element;
296
299
  r_mpfi_get_matrix_struct(ptr, self);
297
300
 
298
301
  ptr->row = NUM2INT(rb_ary_entry(dump_ary, 0));
299
302
  ptr->column = NUM2INT(rb_ary_entry(dump_ary, 1));
300
303
  ptr->size = ptr->row * ptr->column;
301
304
  ptr->data = ALLOC_N(MPFI, ptr->size);
302
- int i;
303
- char *dump;
304
- VALUE dump_element;
305
305
 
306
306
  for(i = 0; i < ptr->size; i++){
307
307
  dump_element = rb_ary_entry(dump_ary, i + 2);
@@ -336,8 +336,9 @@ static VALUE r_mpfi_matrix_row_size (VALUE self){
336
336
  /* Return element at _arg_.*/
337
337
  static VALUE r_mpfi_matrix_at (VALUE self, VALUE arg){
338
338
  MPFIMatrix *ptr_self;
339
+ int i;
339
340
  r_mpfi_get_matrix_struct(ptr_self, self);
340
- int i = NUM2INT(arg);
341
+ i = NUM2INT(arg);
341
342
  if (i < ptr_self->size) {
342
343
  VALUE ret;
343
344
  MPFI *ptr_ret;
@@ -352,8 +353,10 @@ static VALUE r_mpfi_matrix_at (VALUE self, VALUE arg){
352
353
  /* Return element with _row_ and _column_.*/
353
354
  static VALUE r_mpfi_matrix_element (VALUE self, VALUE row, VALUE column){
354
355
  MPFIMatrix *ptr_self;
356
+ int i, j;
355
357
  r_mpfi_get_matrix_struct(ptr_self, self);
356
- int i = NUM2INT(row), j = NUM2INT(column);
358
+ i = NUM2INT(row);
359
+ j = NUM2INT(column);
357
360
  if (i < ptr_self->row && j < ptr_self->column) {
358
361
  VALUE ret;
359
362
  MPFI*ptr_ret;
@@ -368,8 +371,10 @@ static VALUE r_mpfi_matrix_element (VALUE self, VALUE row, VALUE column){
368
371
  /* Set _robj_ to element of which row is _row_ and column is _column_. */
369
372
  static VALUE r_mpfi_matrix_set_element (VALUE self, VALUE row, VALUE column, VALUE robj){
370
373
  MPFIMatrix *ptr_self;
374
+ int i, j;
371
375
  r_mpfi_get_matrix_struct(ptr_self, self);
372
- int i = NUM2INT(row), j = NUM2INT(column);
376
+ i = NUM2INT(row);
377
+ j = NUM2INT(column);
373
378
  if (i < ptr_self->row && j < ptr_self->column) {
374
379
  r_mpfi_set_robj(ptr_self->data + i + j * ptr_self->row, robj);
375
380
  }
@@ -379,9 +384,10 @@ static VALUE r_mpfi_matrix_set_element (VALUE self, VALUE row, VALUE column, VAL
379
384
  /* Evaluate block with each element of matrix. */
380
385
  static VALUE r_mpfi_matrix_each_element (VALUE self){
381
386
  MPFIMatrix *ptr_self;
382
- r_mpfi_get_matrix_struct(ptr_self, self);
383
- VALUE ret = Qnil;
387
+ VALUE ret;
384
388
  int i, j;
389
+ r_mpfi_get_matrix_struct(ptr_self, self);
390
+ ret = Qnil;
385
391
  for (i = 0; i < ptr_self->row; i++) {
386
392
  for (j = 0; j < ptr_self->column; j++) {
387
393
  volatile VALUE arg = r_mpfi_make_new_fi_obj(ptr_self->data + i + j * ptr_self->row);
@@ -394,9 +400,10 @@ static VALUE r_mpfi_matrix_each_element (VALUE self){
394
400
  /* Evaluate block with each element and its index. */
395
401
  static VALUE r_mpfi_matrix_each_element_with_index (VALUE self){
396
402
  MPFIMatrix *ptr_self;
397
- r_mpfi_get_matrix_struct(ptr_self, self);
398
- VALUE ret = Qnil, tmp_i;
403
+ VALUE ret, tmp_i;
399
404
  int i, j;
405
+ r_mpfi_get_matrix_struct(ptr_self, self);
406
+ ret = Qnil;
400
407
  for (i = 0; i < ptr_self->row; i++) {
401
408
  tmp_i = INT2NUM(i);
402
409
  for (j = 0; j < ptr_self->column; j++) {
@@ -410,8 +417,8 @@ static VALUE r_mpfi_matrix_each_element_with_index (VALUE self){
410
417
  /* Return one dimensinal array which has strings converted elements to. */
411
418
  static VALUE r_mpfi_matrix_str_ary_for_inspect(VALUE self){
412
419
  MPFIMatrix *ptr_self;
413
- r_mpfi_get_matrix_struct(ptr_self, self);
414
420
  char *tmp_str;
421
+ r_mpfi_get_matrix_struct(ptr_self, self);
415
422
  VALUE ret_val[ptr_self->size];
416
423
  int i;
417
424
  for (i = 0; i < ptr_self->size; i++) {
@@ -428,10 +435,10 @@ static VALUE r_mpfi_matrix_str_ary_for_inspect(VALUE self){
428
435
  /* Return two dimensinal array which has strings converted elements to. */
429
436
  static VALUE r_mpfi_matrix_str_ary_for_inspect2(VALUE self){
430
437
  MPFIMatrix *ptr_self;
431
- r_mpfi_get_matrix_struct(ptr_self, self);
432
438
  char *tmp_str;
433
- VALUE ary[ptr_self->row];
434
439
  int i, j;
440
+ r_mpfi_get_matrix_struct(ptr_self, self);
441
+ VALUE ary[ptr_self->row];
435
442
  for(i = 0; i < ptr_self->row; i++){
436
443
  ary[i] = rb_ary_new();
437
444
  }
@@ -450,10 +457,10 @@ static VALUE r_mpfi_matrix_str_ary_for_inspect2(VALUE self){
450
457
 
451
458
  static VALUE r_mpfi_matrix_to_str_ary(VALUE self){
452
459
  MPFIMatrix *ptr_self;
453
- r_mpfi_get_matrix_struct(ptr_self, self);
454
460
  char *tmp_str1, *tmp_str2;
455
- VALUE ary[ptr_self->row];
456
461
  int i, j;
462
+ r_mpfi_get_matrix_struct(ptr_self, self);
463
+ VALUE ary[ptr_self->row];
457
464
  for(i = 0; i < ptr_self->row; i++){
458
465
  ary[i] = rb_ary_new();
459
466
  }
@@ -475,11 +482,11 @@ static VALUE r_mpfi_matrix_to_str_ary(VALUE self){
475
482
 
476
483
  static VALUE r_mpfi_matrix_to_strf_ary(VALUE self, VALUE format_str){
477
484
  MPFIMatrix *ptr_self;
485
+ char *tmp_str1, *tmp_str2, *format;
486
+ int i, j;
478
487
  r_mpfi_get_matrix_struct(ptr_self, self);
479
- char *tmp_str1, *tmp_str2;
480
- char *format = StringValuePtr(format_str);
488
+ format = StringValuePtr(format_str);
481
489
  VALUE ary[ptr_self->row];
482
- int i, j;
483
490
  for(i = 0; i < ptr_self->row; i++){
484
491
  ary[i] = rb_ary_new();
485
492
  }
@@ -501,9 +508,9 @@ static VALUE r_mpfi_matrix_to_strf_ary(VALUE self, VALUE format_str){
501
508
 
502
509
  static VALUE r_mpfi_matrix_to_array(VALUE self){
503
510
  MPFIMatrix *ptr_self;
511
+ int i;
504
512
  r_mpfi_get_matrix_struct(ptr_self, self);
505
513
  VALUE ret_val[ptr_self->size];
506
- int i;
507
514
  for (i = 0; i < ptr_self->size; i++) {
508
515
  ret_val[i] = r_mpfi_make_new_fi_obj(ptr_self->data + i);
509
516
  }
@@ -512,9 +519,9 @@ static VALUE r_mpfi_matrix_to_array(VALUE self){
512
519
 
513
520
  static VALUE r_mpfi_matrix_to_array2(VALUE self){
514
521
  MPFIMatrix *ptr_self;
522
+ int i, j;
515
523
  r_mpfi_get_matrix_struct(ptr_self, self);
516
524
  VALUE ary[ptr_self->row];
517
- int i, j;
518
525
  for(i = 0; i < ptr_self->row; i++){
519
526
  ary[i] = rb_ary_new();
520
527
  }
@@ -528,9 +535,10 @@ static VALUE r_mpfi_matrix_to_array2(VALUE self){
528
535
 
529
536
  static VALUE r_mpfi_matrix_row (VALUE self, VALUE arg) {
530
537
  MPFIMatrix *ptr_self, *ptr_ret;
531
- r_mpfi_get_matrix_struct(ptr_self, self);
532
- int num = NUM2INT(arg);
538
+ int num;
533
539
  VALUE ret;
540
+ r_mpfi_get_matrix_struct(ptr_self, self);
541
+ num = NUM2INT(arg);
534
542
  if(num < ptr_self->row){
535
543
  r_mpfi_matrix_suitable_matrix_init (&ret, &ptr_ret, 1, ptr_self->column);
536
544
  mpfi_matrix_row(ptr_ret, ptr_self, num);
@@ -542,9 +550,10 @@ static VALUE r_mpfi_matrix_row (VALUE self, VALUE arg) {
542
550
 
543
551
  static VALUE r_mpfi_matrix_column (VALUE self, VALUE arg) {
544
552
  MPFIMatrix *ptr_self, *ptr_ret;
545
- r_mpfi_get_matrix_struct(ptr_self, self);
546
- int num = NUM2INT(arg);
553
+ int num;
547
554
  VALUE ret;
555
+ r_mpfi_get_matrix_struct(ptr_self, self);
556
+ num = NUM2INT(arg);
548
557
  if(num < ptr_self->column){
549
558
  r_mpfi_matrix_suitable_matrix_init (&ret, &ptr_ret, ptr_self->row, 1);
550
559
  mpfi_matrix_column(ptr_ret, ptr_self, num);
@@ -557,8 +566,8 @@ static VALUE r_mpfi_matrix_column (VALUE self, VALUE arg) {
557
566
  /* Return transposed matrix which is new object. */
558
567
  static VALUE r_mpfi_matrix_transpose (VALUE self){
559
568
  MPFIMatrix *ptr_self, *ptr_ret;
560
- r_mpfi_get_matrix_struct(ptr_self, self);
561
569
  VALUE ret;
570
+ r_mpfi_get_matrix_struct(ptr_self, self);
562
571
  r_mpfi_matrix_suitable_matrix_init (&ret, &ptr_ret, ptr_self->column, ptr_self->row);
563
572
  mpfi_matrix_transpose(ptr_ret, ptr_self);
564
573
  return ret;
@@ -567,6 +576,7 @@ static VALUE r_mpfi_matrix_transpose (VALUE self){
567
576
  /* Transpose self. This method is destroying method. */
568
577
  static VALUE r_mpfi_matrix_transpose2 (VALUE self){
569
578
  MPFIMatrix *ptr_self, tmp;
579
+ int i;
570
580
  r_mpfi_get_matrix_struct(ptr_self, self);
571
581
  if (ptr_self->column > 1 && ptr_self->row > 1) {
572
582
  mpfi_matrix_init(&tmp, ptr_self->column, ptr_self->row);
@@ -574,7 +584,6 @@ static VALUE r_mpfi_matrix_transpose2 (VALUE self){
574
584
  mpfi_matrix_set(ptr_self, &tmp);
575
585
  mpfi_matrix_clear(&tmp);
576
586
  }
577
- int i;
578
587
  i = ptr_self->column;
579
588
  ptr_self->column = ptr_self->row;
580
589
  ptr_self->row = i;
@@ -584,8 +593,8 @@ static VALUE r_mpfi_matrix_transpose2 (VALUE self){
584
593
  /* Return transposed matrix which is new object. */
585
594
  static VALUE r_mpfi_matrix_neg (VALUE self){
586
595
  MPFIMatrix *ptr_self, *ptr_ret;
587
- r_mpfi_get_matrix_struct(ptr_self, self);
588
596
  VALUE ret;
597
+ r_mpfi_get_matrix_struct(ptr_self, self);
589
598
  r_mpfi_matrix_suitable_matrix_init (&ret, &ptr_ret, ptr_self->row, ptr_self->column);
590
599
  mpfi_matrix_neg(ptr_ret, ptr_self);
591
600
  return ret;
@@ -597,19 +606,18 @@ static VALUE r_mpfi_matrix_equal_p (VALUE self, VALUE other){
597
606
  MPFIMatrix *ptr_self, *ptr_other;
598
607
  r_mpfi_get_matrix_struct(ptr_self, self);
599
608
  r_mpfi_get_matrix_struct(ptr_other, other);
600
- VALUE ret = Qtrue;
601
609
  if (mpfi_matrix_equal_p(ptr_self, ptr_other) != 0) {
602
- ret = Qnil;
610
+ return Qnil;
603
611
  }
604
- return ret;
612
+ return Qtrue;
605
613
  }
606
614
 
607
615
  /* Return _self_ + _other_. */
608
616
  static VALUE r_mpfi_matrix_add (VALUE self, VALUE other){
609
617
  MPFIMatrix *ptr_self, *ptr_other, *ptr_ret;
618
+ VALUE ret;
610
619
  r_mpfi_get_matrix_struct(ptr_self, self);
611
620
  r_mpfi_get_matrix_struct(ptr_other, other);
612
- VALUE ret;
613
621
  if (ptr_self->column == ptr_other->column && ptr_self->row == ptr_other->row) {
614
622
  r_mpfi_matrix_suitable_matrix_init (&ret, &ptr_ret, ptr_self->row, ptr_self->column);
615
623
  mpfi_matrix_add(ptr_ret, ptr_self, ptr_other);
@@ -622,8 +630,8 @@ static VALUE r_mpfi_matrix_add (VALUE self, VALUE other){
622
630
  /* Return _self_ + _other_ which is MPFI::Matrix. */
623
631
  static VALUE r_mpfi_matrix_add2 (VALUE self, VALUE other){
624
632
  MPFIMatrix *ptr_self, *ptr_ret;
625
- r_mpfi_get_matrix_struct(ptr_self, self);
626
633
  VALUE ret;
634
+ r_mpfi_get_matrix_struct(ptr_self, self);
627
635
  r_mpfi_make_matrix_struct(ret, ptr_ret);
628
636
 
629
637
  if(RTEST(rb_funcall(__mpfi_matrix_class__, eqq, 1, other))){
@@ -653,9 +661,9 @@ static VALUE r_mpfi_matrix_add2 (VALUE self, VALUE other){
653
661
  /* Return _self_ - _other_. */
654
662
  static VALUE r_mpfi_matrix_sub (VALUE self, VALUE other){
655
663
  MPFIMatrix *ptr_self, *ptr_other, *ptr_ret;
664
+ VALUE ret;
656
665
  r_mpfi_get_matrix_struct(ptr_self, self);
657
666
  r_mpfi_get_matrix_struct(ptr_other, other);
658
- VALUE ret;
659
667
  r_mpfi_make_matrix_struct(ret, ptr_ret);
660
668
  if (ptr_self->column == ptr_other->column && ptr_self->row == ptr_other->row) {
661
669
  r_mpfi_matrix_suitable_matrix_init (&ret, &ptr_ret, ptr_self->row, ptr_self->column);
@@ -669,8 +677,8 @@ static VALUE r_mpfi_matrix_sub (VALUE self, VALUE other){
669
677
  /* Return _self_ - _other_ which is MPFI::Matrix. */
670
678
  static VALUE r_mpfi_matrix_sub2 (VALUE self, VALUE other){
671
679
  MPFIMatrix *ptr_self, *ptr_ret;
672
- r_mpfi_get_matrix_struct(ptr_self, self);
673
680
  VALUE ret;
681
+ r_mpfi_get_matrix_struct(ptr_self, self);
674
682
  r_mpfi_make_matrix_struct(ret, ptr_ret);
675
683
 
676
684
  if(RTEST(rb_funcall(__mpfi_matrix_class__, eqq, 1, other))){
@@ -699,10 +707,10 @@ static VALUE r_mpfi_matrix_sub2 (VALUE self, VALUE other){
699
707
 
700
708
  static VALUE r_mpfi_matrix_vector_inner_product (VALUE self, VALUE arg){
701
709
  MPFIMatrix *ptr_self, *ptr_arg;
702
- r_mpfi_get_matrix_struct(ptr_self, self);
703
- r_mpfi_get_matrix_struct(ptr_arg, arg);
704
710
  VALUE ret;
705
711
  MPFI *ptr_ret;
712
+ r_mpfi_get_matrix_struct(ptr_self, self);
713
+ r_mpfi_get_matrix_struct(ptr_arg, arg);
706
714
  r_mpfi_make_struct_init(ret, ptr_ret);
707
715
  if(ptr_self->size == ptr_arg->size){
708
716
  mpfi_matrix_inner_product(ptr_ret, ptr_self, ptr_arg);
@@ -715,9 +723,9 @@ static VALUE r_mpfi_matrix_vector_inner_product (VALUE self, VALUE arg){
715
723
  /* Return _self_ * _other_. */
716
724
  static VALUE r_mpfi_matrix_mul_matrix (VALUE self, VALUE other){
717
725
  MPFIMatrix *ptr_self, *ptr_other, *ptr_ret;
726
+ VALUE ret;
718
727
  r_mpfi_get_matrix_struct(ptr_self, self);
719
728
  r_mpfi_get_matrix_struct(ptr_other, other);
720
- VALUE ret;
721
729
  r_mpfi_make_matrix_struct(ret, ptr_ret);
722
730
  if (ptr_self->column == ptr_other->row) {
723
731
  if((ptr_other->column == 1) && (ptr_self->row == 1)){
@@ -735,8 +743,8 @@ static VALUE r_mpfi_matrix_mul_matrix (VALUE self, VALUE other){
735
743
  /* Return _self_ * _other_ which is MPFI::Matrix. */
736
744
  static VALUE r_mpfi_matrix_mul_matrix2 (VALUE self, VALUE other){
737
745
  MPFIMatrix *ptr_self, *ptr_ret;
738
- r_mpfi_get_matrix_struct(ptr_self, self);
739
746
  VALUE ret;
747
+ r_mpfi_get_matrix_struct(ptr_self, self);
740
748
  r_mpfi_make_matrix_struct(ret, ptr_ret);
741
749
 
742
750
  if(RTEST(rb_funcall(__mpfi_matrix_class__, eqq, 1, other))){
@@ -767,8 +775,8 @@ static VALUE r_mpfi_matrix_mul_matrix2 (VALUE self, VALUE other){
767
775
  static VALUE r_mpfi_matrix_mul_scalar (VALUE self, VALUE scalar){
768
776
  MPFIMatrix *ptr_self, *ptr_ret;
769
777
  MPFI *ptr_scalar;
770
- r_mpfi_get_matrix_struct(ptr_self, self);
771
778
  VALUE ret;
779
+ r_mpfi_get_matrix_struct(ptr_self, self);
772
780
  r_mpfi_matrix_suitable_matrix_init (&ret, &ptr_ret, ptr_self->row, ptr_self->column);
773
781
  if(RTEST(rb_funcall(r_mpfi_class, eqq, 1, scalar))){
774
782
  r_mpfi_get_struct(ptr_scalar, scalar);
@@ -785,8 +793,8 @@ static VALUE r_mpfi_matrix_mul_scalar (VALUE self, VALUE scalar){
785
793
  static VALUE r_mpfi_matrix_div_scalar (VALUE self, VALUE scalar){
786
794
  MPFIMatrix *ptr_self, *ptr_ret;
787
795
  MPFI *ptr_scalar;
788
- r_mpfi_get_matrix_struct(ptr_self, self);
789
796
  VALUE ret;
797
+ r_mpfi_get_matrix_struct(ptr_self, self);
790
798
  r_mpfi_matrix_suitable_matrix_init (&ret, &ptr_ret, ptr_self->row, ptr_self->column);
791
799
  if(RTEST(rb_funcall(r_mpfi_class, eqq, 1, scalar))){
792
800
  r_mpfi_get_struct(ptr_scalar, scalar);
@@ -803,8 +811,9 @@ static VALUE r_mpfi_matrix_div_scalar (VALUE self, VALUE scalar){
803
811
 
804
812
  static VALUE r_mpfi_matrix_include_p (VALUE self, VALUE other){
805
813
  MPFIMatrix *ptr_self;
814
+ VALUE ret;
806
815
  r_mpfi_get_matrix_struct(ptr_self, self);
807
- VALUE ret = Qnil;
816
+ ret = Qnil;
808
817
  if(RTEST(rb_funcall(r_mpfi_matrix, eqq, 1, other))){
809
818
  MPFIMatrix *ptr_other;
810
819
  r_mpfi_get_matrix_struct(ptr_other, other);
@@ -825,8 +834,9 @@ static VALUE r_mpfi_matrix_include_p (VALUE self, VALUE other){
825
834
 
826
835
  static VALUE r_mpfi_matrix_strictly_include_p (VALUE self, VALUE other){
827
836
  MPFIMatrix *ptr_self;
837
+ VALUE ret;
828
838
  r_mpfi_get_matrix_struct(ptr_self, self);
829
- VALUE ret = Qnil;
839
+ ret = Qnil;
830
840
  if(RTEST(rb_funcall(r_mpfi_matrix, eqq, 1, other))){
831
841
  MPFIMatrix *ptr_other;
832
842
  r_mpfi_get_matrix_struct(ptr_other, other);
@@ -851,9 +861,9 @@ static VALUE r_mpfi_matrix_bounded_p (VALUE self) {
851
861
 
852
862
  static VALUE r_mpfi_matrix_mid (VALUE self){
853
863
  MPFIMatrix *ptr_self;
854
- r_mpfi_get_matrix_struct(ptr_self, self);
855
864
  VALUE val_ret;
856
865
  MPFRMatrix *ptr_ret;
866
+ r_mpfi_get_matrix_struct(ptr_self, self);
857
867
  r_mpfr_matrix_suitable_matrix_init(&val_ret, &ptr_ret, ptr_self->row, ptr_self->column);
858
868
  mpfi_matrix_mid(ptr_ret, ptr_self);
859
869
  return val_ret;
@@ -861,8 +871,8 @@ static VALUE r_mpfi_matrix_mid (VALUE self){
861
871
 
862
872
  static VALUE r_mpfi_matrix_mid_interval (VALUE self){
863
873
  MPFIMatrix *ptr_self, *ptr_ret;
864
- r_mpfi_get_matrix_struct(ptr_self, self);
865
874
  VALUE val_ret;
875
+ r_mpfi_get_matrix_struct(ptr_self, self);
866
876
  r_mpfi_matrix_suitable_matrix_init(&val_ret, &ptr_ret, ptr_self->row, ptr_self->column);
867
877
  mpfi_matrix_mid_interval(ptr_ret, ptr_self);
868
878
  return val_ret;
@@ -870,9 +880,9 @@ static VALUE r_mpfi_matrix_mid_interval (VALUE self){
870
880
 
871
881
  static VALUE r_mpfi_matrix_intersect (VALUE self, VALUE other){
872
882
  MPFIMatrix *ptr_self, *ptr_other, *ptr_ret;
883
+ VALUE val_ret;
873
884
  r_mpfi_get_matrix_struct(ptr_self, self);
874
885
  r_mpfi_get_matrix_struct(ptr_other, other);
875
- VALUE val_ret;
876
886
  r_mpfi_matrix_suitable_matrix_init(&val_ret, &ptr_ret, ptr_self->row, ptr_self->column);
877
887
  if(mpfi_matrix_intersect(ptr_ret, ptr_self, ptr_other) == 0){
878
888
  return val_ret;
@@ -883,9 +893,9 @@ static VALUE r_mpfi_matrix_intersect (VALUE self, VALUE other){
883
893
 
884
894
  static VALUE r_mpfi_matrix_union (VALUE self, VALUE other){
885
895
  MPFIMatrix *ptr_self, *ptr_other, *ptr_ret;
896
+ VALUE val_ret;
886
897
  r_mpfi_get_matrix_struct(ptr_self, self);
887
898
  r_mpfi_get_matrix_struct(ptr_other, other);
888
- VALUE val_ret;
889
899
  r_mpfi_matrix_suitable_matrix_init(&val_ret, &ptr_ret, ptr_self->row, ptr_self->column);
890
900
  if(mpfi_matrix_union(ptr_ret, ptr_self, ptr_other) == 0){
891
901
  return val_ret;
@@ -897,9 +907,9 @@ static VALUE r_mpfi_matrix_union (VALUE self, VALUE other){
897
907
 
898
908
  static VALUE r_mpfi_matrix_max_diam_abs (VALUE self){
899
909
  MPFIMatrix *ptr_self;
900
- r_mpfi_get_matrix_struct(ptr_self, self);
901
910
  MPFR *ptr_ret;
902
911
  VALUE ret_val;
912
+ r_mpfi_get_matrix_struct(ptr_self, self);
903
913
  r_mpfr_make_struct_init(ret_val, ptr_ret);
904
914
  mpfi_matrix_max_diam_abs(ptr_ret, ptr_self);
905
915
  return ret_val;
@@ -916,13 +926,13 @@ static VALUE r_mpfi_square_matrix_dim (VALUE self){
916
926
  static VALUE r_mpfi_square_matrix_lu_decomp (VALUE self){
917
927
  MPFIMatrix *ptr_self, *ptr_ret_l, *ptr_ret_u;
918
928
  VALUE ret_l, ret_u;
929
+ int i, j;
919
930
  r_mpfi_get_matrix_struct(ptr_self, self);
920
931
  r_mpfi_matrix_suitable_matrix_init (&ret_l, &ptr_ret_l, ptr_self->row, ptr_self->column);
921
932
  r_mpfi_matrix_suitable_matrix_init (&ret_u, &ptr_ret_u, ptr_self->row, ptr_self->column);
922
933
  VALUE ret_indx[ptr_self->row];
923
934
  int indx[ptr_self->row];
924
935
  if(mpfi_square_matrix_lu_decomp (ptr_ret_u, indx, ptr_self) >= 0){
925
- int i, j;
926
936
  for(i = 1; i < ptr_ret_u->row; i++){
927
937
  for(j = 0; j < i; j++){
928
938
  mpfi_set(mpfi_matrix_get_element(ptr_ret_l, i, j), mpfi_matrix_get_element(ptr_ret_u, i, j));
@@ -948,9 +958,9 @@ static VALUE r_mpfi_square_matrix_lu_decomp (VALUE self){
948
958
 
949
959
  static VALUE r_mpfi_square_matrix_determinant (VALUE self){
950
960
  MPFIMatrix *ptr_self;
951
- r_mpfi_get_matrix_struct(ptr_self, self);
952
961
  MPFI *ptr_ret;
953
962
  VALUE ret;
963
+ r_mpfi_get_matrix_struct(ptr_self, self);
954
964
  r_mpfi_make_struct_init(ret, ptr_ret);
955
965
  mpfi_square_matrix_determinant(ptr_ret, ptr_self);
956
966
  return ret;
@@ -958,8 +968,8 @@ static VALUE r_mpfi_square_matrix_determinant (VALUE self){
958
968
 
959
969
  static VALUE r_mpfi_square_matrix_qr_decomp (VALUE self){
960
970
  MPFIMatrix *ptr_self, *ptr_q, *ptr_r;
961
- r_mpfi_get_matrix_struct(ptr_self, self);
962
971
  VALUE q, r;
972
+ r_mpfi_get_matrix_struct(ptr_self, self);
963
973
  r_mpfi_matrix_suitable_matrix_init (&q, &ptr_q, ptr_self->row, ptr_self->column);
964
974
  r_mpfi_matrix_suitable_matrix_init (&r, &ptr_r, ptr_self->column, ptr_self->column);
965
975
  mpfi_square_matrix_qr_decomp(ptr_q, ptr_r, ptr_self);
@@ -986,9 +996,9 @@ static VALUE r_mpfi_vector_dim (VALUE self){
986
996
  /* Take matrix for vector and return length of the vector. */
987
997
  static VALUE r_mpfi_vector_abs (VALUE self){
988
998
  MPFIMatrix *ptr_self;
989
- r_mpfi_get_matrix_struct(ptr_self, self);
990
999
  VALUE ret;
991
1000
  MPFI *ptr_ret;
1001
+ r_mpfi_get_matrix_struct(ptr_self, self);
992
1002
  r_mpfi_make_struct_init(ret, ptr_ret);
993
1003
  mpfi_matrix_vector_norm(ptr_ret, ptr_self);
994
1004
  return ret;
@@ -997,8 +1007,9 @@ static VALUE r_mpfi_vector_abs (VALUE self){
997
1007
  /* Return element at _arg_.*/
998
1008
  static VALUE r_mpfi_vector_element (VALUE self, VALUE arg){
999
1009
  MPFIMatrix *ptr_self;
1010
+ int i;
1000
1011
  r_mpfi_get_matrix_struct(ptr_self, self);
1001
- int i = NUM2INT(arg);
1012
+ i = NUM2INT(arg);
1002
1013
  if (i < ptr_self->size) {
1003
1014
  VALUE ret;
1004
1015
  MPFI *ptr_ret;
@@ -1013,8 +1024,9 @@ static VALUE r_mpfi_vector_element (VALUE self, VALUE arg){
1013
1024
  /* Set _robj_ to _arg_ th element. */
1014
1025
  static VALUE r_mpfi_vector_set_element (VALUE self, VALUE arg, VALUE robj){
1015
1026
  MPFIMatrix *ptr_self;
1027
+ int i;
1016
1028
  r_mpfi_get_matrix_struct(ptr_self, self);
1017
- int i = NUM2INT(arg);
1029
+ i = NUM2INT(arg);
1018
1030
  if (i < ptr_self->size) {
1019
1031
  r_mpfi_set_robj(ptr_self->data + i, robj);
1020
1032
  }
@@ -1024,11 +1036,12 @@ static VALUE r_mpfi_vector_set_element (VALUE self, VALUE arg, VALUE robj){
1024
1036
  /* Evaluate block with each element of vector. */
1025
1037
  static VALUE r_mpfi_vector_each_element (VALUE self){
1026
1038
  MPFIMatrix *ptr_self;
1027
- r_mpfi_get_matrix_struct(ptr_self, self);
1028
- VALUE ret = Qnil, tmp;
1039
+ VALUE ret, tmp;
1029
1040
  MPFI *tmp_ptr;
1030
- r_mpfi_make_struct_init(tmp, tmp_ptr);
1031
1041
  int i;
1042
+ ret = Qnil;
1043
+ r_mpfi_get_matrix_struct(ptr_self, self);
1044
+ r_mpfi_make_struct_init(tmp, tmp_ptr);
1032
1045
  for (i = 0; i < ptr_self->size; i++) {
1033
1046
  mpfi_set(tmp_ptr, ptr_self->data + i);
1034
1047
  ret = rb_yield(tmp);
@@ -1039,11 +1052,12 @@ static VALUE r_mpfi_vector_each_element (VALUE self){
1039
1052
  /* Evaluate block with each element and its index. */
1040
1053
  static VALUE r_mpfi_vector_each_element_with_index (VALUE self){
1041
1054
  MPFIMatrix *ptr_self;
1042
- r_mpfi_get_matrix_struct(ptr_self, self);
1043
- VALUE ret = Qnil, tmp;
1055
+ VALUE ret, tmp;
1044
1056
  MPFI *tmp_ptr;
1045
- r_mpfi_make_struct_init(tmp, tmp_ptr);
1046
1057
  int i;
1058
+ r_mpfi_get_matrix_struct(ptr_self, self);
1059
+ r_mpfi_make_struct_init(tmp, tmp_ptr);
1060
+ ret = Qnil;
1047
1061
  for (i = 0; i < ptr_self->size; i++) {
1048
1062
  mpfi_set(tmp_ptr, ptr_self->data + i);
1049
1063
  ret = rb_yield(rb_ary_new3(2, tmp, INT2NUM(i)));
@@ -1053,10 +1067,10 @@ static VALUE r_mpfi_vector_each_element_with_index (VALUE self){
1053
1067
 
1054
1068
  static VALUE r_mpfi_vector_inner_product (VALUE self, VALUE arg){
1055
1069
  MPFIMatrix *ptr_self, *ptr_arg;
1056
- r_mpfi_get_matrix_struct(ptr_self, self);
1057
- r_mpfi_get_matrix_struct(ptr_arg, arg);
1058
1070
  VALUE ret;
1059
1071
  MPFI *ptr_ret;
1072
+ r_mpfi_get_matrix_struct(ptr_self, self);
1073
+ r_mpfi_get_matrix_struct(ptr_arg, arg);
1060
1074
  r_mpfi_make_struct_init(ret, ptr_ret);
1061
1075
  if(ptr_self->size == ptr_arg->size){
1062
1076
  mpfi_matrix_inner_product(ptr_ret, ptr_self, ptr_arg);
@@ -1068,10 +1082,10 @@ static VALUE r_mpfi_vector_inner_product (VALUE self, VALUE arg){
1068
1082
 
1069
1083
  static VALUE r_mpfi_vector_distance_from (VALUE self, VALUE arg){
1070
1084
  MPFIMatrix *ptr_self, *ptr_arg;
1071
- r_mpfi_get_matrix_struct(ptr_self, self);
1072
- r_mpfi_get_matrix_struct(ptr_arg, arg);
1073
1085
  VALUE ret;
1074
1086
  MPFI *ptr_ret;
1087
+ r_mpfi_get_matrix_struct(ptr_self, self);
1088
+ r_mpfi_get_matrix_struct(ptr_arg, arg);
1075
1089
  r_mpfi_make_struct_init(ret, ptr_ret);
1076
1090
  if(ptr_self->size == ptr_arg->size){
1077
1091
  mpfi_matrix_vector_distance(ptr_ret, ptr_self, ptr_arg);
@@ -1083,10 +1097,10 @@ static VALUE r_mpfi_vector_distance_from (VALUE self, VALUE arg){
1083
1097
 
1084
1098
  static VALUE r_mpfi_vector_distance_center_pts (VALUE self, VALUE arg){
1085
1099
  MPFIMatrix *ptr_self, *ptr_arg;
1086
- r_mpfi_get_matrix_struct(ptr_self, self);
1087
- r_mpfi_get_matrix_struct(ptr_arg, arg);
1088
1100
  VALUE ret;
1089
1101
  MPFR *ptr_ret;
1102
+ r_mpfi_get_matrix_struct(ptr_self, self);
1103
+ r_mpfi_get_matrix_struct(ptr_arg, arg);
1090
1104
  r_mpfr_make_struct_init(ret, ptr_ret);
1091
1105
  if(ptr_self->size == ptr_arg->size){
1092
1106
  mpfi_matrix_vector_distance_center_pts(ptr_ret, ptr_self, ptr_arg);
@@ -1098,9 +1112,9 @@ static VALUE r_mpfi_vector_distance_center_pts (VALUE self, VALUE arg){
1098
1112
 
1099
1113
  static VALUE r_mpfi_vector_midpoint (VALUE self, VALUE arg){
1100
1114
  MPFIMatrix *ptr_self, *ptr_arg, *ptr_ret;
1115
+ VALUE ret;
1101
1116
  r_mpfi_get_matrix_struct(ptr_self, self);
1102
1117
  r_mpfi_get_matrix_struct(ptr_arg, arg);
1103
- VALUE ret;
1104
1118
  r_mpfi_matrix_suitable_matrix_init (&ret, &ptr_ret, ptr_self->row, ptr_self->column);
1105
1119
  mpfi_vector_midpoint(ptr_ret, ptr_self, ptr_arg);
1106
1120
  return ret;
@@ -1108,8 +1122,8 @@ static VALUE r_mpfi_vector_midpoint (VALUE self, VALUE arg){
1108
1122
 
1109
1123
  static VALUE r_mpfi_vector_normalize (VALUE self){
1110
1124
  MPFIMatrix *ptr_self, *ptr_ret;
1111
- r_mpfi_get_matrix_struct(ptr_self, self);
1112
1125
  VALUE ret;
1126
+ r_mpfi_get_matrix_struct(ptr_self, self);
1113
1127
  r_mpfi_matrix_suitable_matrix_init (&ret, &ptr_ret, ptr_self->row, ptr_self->column);
1114
1128
  if(mpfi_vector_normalize(ptr_ret, ptr_self) == 0){
1115
1129
  return ret;
@@ -1121,8 +1135,9 @@ static VALUE r_mpfi_vector_normalize (VALUE self){
1121
1135
  /* Return normalized vector of _self_. This method is destroy method. */
1122
1136
  static VALUE r_mpfi_vector_normalize2 (VALUE self){
1123
1137
  MPFIMatrix *ptr_self, tmp;
1138
+ VALUE ret;
1124
1139
  r_mpfi_get_matrix_struct(ptr_self, self);
1125
- VALUE ret = self;
1140
+ ret = self;
1126
1141
  mpfi_matrix_init(&tmp, ptr_self->column, ptr_self->row);
1127
1142
  if(mpfi_vector_normalize(&tmp, ptr_self) == 0){
1128
1143
  mpfi_matrix_set(ptr_self, &tmp);
@@ -1135,9 +1150,10 @@ static VALUE r_mpfi_vector_normalize2 (VALUE self){
1135
1150
 
1136
1151
  static VALUE r_mpfi_vector_set_length (VALUE self, VALUE arg){
1137
1152
  MPFIMatrix *ptr_self, *ptr_ret;
1138
- r_mpfi_get_matrix_struct(ptr_self, self);
1139
- VALUE ret, returned_value = Qnil;
1153
+ VALUE ret, returned_value;
1140
1154
  MPFR *ptr_l;
1155
+ returned_value = Qnil;
1156
+ r_mpfi_get_matrix_struct(ptr_self, self);
1141
1157
  r_mpfi_matrix_suitable_matrix_init (&ret, &ptr_ret, ptr_self->row, ptr_self->column);
1142
1158
  if(RTEST(rb_funcall(r_mpfr_class, eqq, 1, arg))){
1143
1159
  r_mpfr_get_struct(ptr_l, arg);
@@ -1157,9 +1173,10 @@ static VALUE r_mpfi_vector_set_length (VALUE self, VALUE arg){
1157
1173
 
1158
1174
  static VALUE r_mpfi_vector_set_length2 (VALUE self, VALUE arg){
1159
1175
  MPFIMatrix *ptr_self, *ptr_ret;
1160
- r_mpfi_get_matrix_struct(ptr_self, self);
1161
- VALUE ret, returned_value = Qnil;
1176
+ VALUE ret, returned_value;
1162
1177
  MPFR *ptr_l;
1178
+ returned_value = Qnil;
1179
+ r_mpfi_get_matrix_struct(ptr_self, self);
1163
1180
  r_mpfi_matrix_suitable_matrix_init (&ret, &ptr_ret, ptr_self->row, ptr_self->column);
1164
1181
  if(RTEST(rb_funcall(r_mpfi_class, eqq, 1, arg))){
1165
1182
  r_mpfr_get_struct(ptr_l, arg);
@@ -1180,19 +1197,17 @@ static VALUE r_mpfi_vector_set_length2 (VALUE self, VALUE arg){
1180
1197
  }
1181
1198
 
1182
1199
 
1183
-
1184
1200
  static VALUE r_mpfr_matrix_to_fi_matrix(VALUE self){
1185
1201
  MPFRMatrix *ptr;
1186
- r_mpfr_get_matrix_struct(ptr, self);
1187
1202
  VALUE ret;
1188
1203
  MPFIMatrix *ptr_ret;
1204
+ r_mpfr_get_matrix_struct(ptr, self);
1189
1205
  r_mpfi_matrix_suitable_matrix_init (&ret, &ptr_ret, ptr->row, ptr->column);
1190
1206
  mpfi_matrix_from_mpfr_matrix(ptr_ret, ptr);
1191
1207
  return ret;
1192
1208
  }
1193
1209
 
1194
1210
  void Init_matrix(){
1195
-
1196
1211
  /* Initialization of MPFI::Matrix, MPFI::SquareMatrix, MPFI::ColumnVector and MPFI::RowVector */
1197
1212
  VALUE tmp_r_mpfi_class = rb_define_class("MPFI", rb_cNumeric);
1198
1213
  r_mpfi_matrix = rb_define_class_under(tmp_r_mpfi_class, "Matrix", rb_cObject);
@@ -1316,6 +1331,4 @@ void Init_matrix(){
1316
1331
  eqq = rb_intern("===");
1317
1332
  __mpfr_matrix_class__ = rb_eval_string("MPFR::Matrix");
1318
1333
  __mpfi_matrix_class__ = rb_eval_string("MPFI::Matrix");
1319
-
1320
1334
  }
1321
-