ruby-mpfi 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -14,10 +14,8 @@ static VALUE r_mpfi_complex_alloc (VALUE self){
14
14
  return self;
15
15
  }
16
16
 
17
- /* Initialization function for MPF::Complex. */
18
- static VALUE r_mpfi_complex_initialize (int argc, VALUE *argv, VALUE self){
19
- MPFIComplex *ptr;
20
- r_mpfi_get_complex_struct(ptr, self);
17
+ static void r_mpfi_complex_set_initial_value(MPFIComplex *ptr, int argc, VALUE *argv)
18
+ {
21
19
  mpfi_complex_init(ptr);
22
20
  switch (argc) {
23
21
  case 0:
@@ -34,7 +32,24 @@ static VALUE r_mpfi_complex_initialize (int argc, VALUE *argv, VALUE self){
34
32
  default:
35
33
  rb_raise(rb_eArgError, "Number of MPF::Complex.new arguments must be lesser than three.");
36
34
  break;
37
- }
35
+ }
36
+ }
37
+
38
+ /* Return new MPFI::Complex instance. The same arguments as MPFI::Complex.new is acceptable. */
39
+ static VALUE r_mpfi_complex_global_new(int argc, VALUE *argv, VALUE self)
40
+ {
41
+ MPFIComplex *ptr;
42
+ VALUE val;
43
+ r_mpfi_make_complex_struct(val, ptr);
44
+ r_mpfi_complex_set_initial_value(ptr, argc, argv);
45
+ return val;
46
+ }
47
+
48
+ /* Initialization function for MPF::Complex. */
49
+ static VALUE r_mpfi_complex_initialize (int argc, VALUE *argv, VALUE self){
50
+ MPFIComplex *ptr;
51
+ r_mpfi_get_complex_struct(ptr, self);
52
+ r_mpfi_complex_set_initial_value(ptr, argc, argv);
38
53
  return Qtrue;
39
54
  }
40
55
 
@@ -48,7 +63,7 @@ static VALUE r_mpfi_complex_initialize_copy (VALUE self, VALUE other){
48
63
  return Qtrue;
49
64
  }
50
65
 
51
-
66
+ /* Return real part. */
52
67
  static VALUE r_mpfi_complex_real (VALUE self){
53
68
  MPFIComplex *ptr_self;
54
69
  r_mpfi_get_complex_struct(ptr_self, self);
@@ -59,6 +74,7 @@ static VALUE r_mpfi_complex_real (VALUE self){
59
74
  return ret;
60
75
  }
61
76
 
77
+ /* Return imaginary part. */
62
78
  static VALUE r_mpfi_complex_imaginary (VALUE self){
63
79
  MPFIComplex *ptr_self;
64
80
  r_mpfi_get_complex_struct(ptr_self, self);
@@ -69,6 +85,7 @@ static VALUE r_mpfi_complex_imaginary (VALUE self){
69
85
  return ret;
70
86
  }
71
87
 
88
+ /* If _p1_ is 0, return real part. If _p1_ is 1, return imaginary part. */
72
89
  static VALUE r_mpfi_complex_element (VALUE self, VALUE arg){
73
90
  MPFIComplex *ptr_self;
74
91
  r_mpfi_get_complex_struct(ptr_self, self);
@@ -89,6 +106,7 @@ static VALUE r_mpfi_complex_element (VALUE self, VALUE arg){
89
106
  return ret;
90
107
  }
91
108
 
109
+ /* Return conjugate complex number. */
92
110
  static VALUE r_mpfi_complex_conjugate (VALUE self){
93
111
  MPFIComplex *ptr_self, *ptr_ret;
94
112
  r_mpfi_get_complex_struct(ptr_self, self);
@@ -109,7 +127,7 @@ static VALUE r_mpfi_complex_conjugate (VALUE self){
109
127
  /* } */
110
128
 
111
129
 
112
-
130
+ /* String for inspect. */
113
131
  static VALUE r_mpfi_complex_inspect(VALUE self){
114
132
  MPFIComplex *ptr_s;
115
133
  r_mpfi_get_complex_struct(ptr_s, self);
@@ -122,7 +140,7 @@ static VALUE r_mpfi_complex_inspect(VALUE self){
122
140
  return ret_val;
123
141
  }
124
142
 
125
- /* Return array which has strings converted elements to. */
143
+ /* Return array including strings which the elements is converted to by _p1_. */
126
144
  static VALUE r_mpfi_complex_str_ary(VALUE self, VALUE format_str){
127
145
  MPFIComplex *ptr_self;
128
146
  r_mpfi_get_complex_struct(ptr_self, self);
@@ -137,8 +155,7 @@ static VALUE r_mpfi_complex_str_ary(VALUE self, VALUE format_str){
137
155
  return rb_ary_new4(2, ret_val);
138
156
  }
139
157
 
140
-
141
-
158
+ /* Return _self_ + _p1_.*/
142
159
  static VALUE r_mpfi_complex_add (VALUE self, VALUE other){
143
160
  MPFIComplex *ptr_self, *ptr_other, *ptr_ret;
144
161
  r_mpfi_get_complex_struct(ptr_self, self);
@@ -149,6 +166,7 @@ static VALUE r_mpfi_complex_add (VALUE self, VALUE other){
149
166
  return ret;
150
167
  }
151
168
 
169
+ /* Return _self_ - _p1_.*/
152
170
  static VALUE r_mpfi_complex_sub (VALUE self, VALUE other){
153
171
  MPFIComplex *ptr_self, *ptr_other, *ptr_ret;
154
172
  r_mpfi_get_complex_struct(ptr_self, self);
@@ -159,6 +177,7 @@ static VALUE r_mpfi_complex_sub (VALUE self, VALUE other){
159
177
  return ret;
160
178
  }
161
179
 
180
+ /* Return _self_ * _p1_.*/
162
181
  static VALUE r_mpfi_complex_mul (VALUE self, VALUE other){
163
182
  MPFIComplex *ptr_self, *ptr_other, *ptr_ret;
164
183
  r_mpfi_get_complex_struct(ptr_self, self);
@@ -169,6 +188,7 @@ static VALUE r_mpfi_complex_mul (VALUE self, VALUE other){
169
188
  return ret;
170
189
  }
171
190
 
191
+ /* Return _self_ / _p1_.*/
172
192
  static VALUE r_mpfi_complex_div (VALUE self, VALUE other){
173
193
  MPFIComplex *ptr_self, *ptr_other, *ptr_ret;
174
194
  r_mpfi_get_complex_struct(ptr_self, self);
@@ -180,16 +200,16 @@ static VALUE r_mpfi_complex_div (VALUE self, VALUE other){
180
200
  }
181
201
 
182
202
 
183
-
184
-
185
203
  void Init_complex(){
186
- r_mpfi_complex = rb_define_class_under(rb_define_class("MPFI", rb_cNumeric), "Complex", rb_cObject);
204
+ VALUE tmp_mpfi_class = rb_define_class("MPFI", rb_cNumeric);
187
205
 
206
+ r_mpfi_complex = rb_define_class_under(tmp_mpfi_class, "Complex", rb_cObject);
207
+
208
+ rb_define_singleton_method(r_mpfi_complex, "Complex", r_mpfi_complex_global_new, -1);
188
209
  rb_define_alloc_func(r_mpfi_complex, r_mpfi_complex_alloc);
189
210
  rb_define_private_method(r_mpfi_complex, "initialize", r_mpfi_complex_initialize, -1);
190
211
  rb_define_private_method(r_mpfi_complex, "initialize_copy", r_mpfi_complex_initialize_copy, 1);
191
212
 
192
-
193
213
  rb_define_method(r_mpfi_complex, "real", r_mpfi_complex_real, 0);
194
214
  rb_define_method(r_mpfi_complex, "imaginary", r_mpfi_complex_imaginary, 0);
195
215
  rb_define_method(r_mpfi_complex, "element", r_mpfi_complex_element, 1);
@@ -582,7 +582,7 @@ int mpfi_square_matrix_lu_decomp (MPFIMatrix *ret, int *indx, MPFIMatrix *x){
582
582
  return ret_val;
583
583
  }
584
584
 
585
- void mpfi_2d_square_matrix_determinant(MPFI *det, MPFIMatrix *x){
585
+ static void mpfi_2d_square_matrix_determinant(MPFI *det, MPFIMatrix *x){
586
586
  MPFI *tmp;
587
587
  r_mpfi_temp_alloc_init(tmp);
588
588
  mpfi_mul(det, x->data, x->data + 3);
@@ -591,7 +591,7 @@ void mpfi_2d_square_matrix_determinant(MPFI *det, MPFIMatrix *x){
591
591
  r_mpfi_temp_free(tmp);
592
592
  }
593
593
 
594
- void mpfi_3d_square_matrix_determinant(MPFI *det, MPFIMatrix *x){
594
+ static void mpfi_3d_square_matrix_determinant(MPFI *det, MPFIMatrix *x){
595
595
  MPFI *tmp;
596
596
  r_mpfi_temp_alloc_init(tmp);
597
597
 
@@ -695,90 +695,6 @@ void mpfi_square_matrix_qr_decomp(MPFIMatrix *q, MPFIMatrix *r, MPFIMatrix *x){
695
695
  r_mpfi_temp_free(tmp);
696
696
  }
697
697
 
698
- /* If inverse matrix does not exist, return 1. Otherwise return 0. */
699
- int mpfi_2d_square_matrix_inverse_matrix(MPFIMatrix *inv, MPFIMatrix *x){
700
- MPFIMatrix *t_mat;
701
- r_mpfi_matrix_temp_alloc_init(t_mat, inv->row, inv->column);
702
- MPFI *t_fi;
703
- r_mpfi_temp_alloc_init(t_fi);
704
- mpfi_2d_square_matrix_determinant(t_fi, x);
705
- if(mpfi_has_zero(t_fi) > 0){
706
- return 1;
707
- }else{
708
- mpfi_ui_div(t_fi, 1, t_fi);
709
- mpfi_mul(t_mat->data, x->data + 3, t_fi);
710
- mpfi_mul(t_mat->data + 3, x->data, t_fi);
711
- mpfi_neg(t_fi, t_fi);
712
- mpfi_mul(t_mat->data + 1, x->data + 1, t_fi);
713
- mpfi_mul(t_mat->data + 2, x->data + 2, t_fi);
714
- }
715
- mpfi_matrix_set(inv, t_mat);
716
- r_mpfi_matrix_temp_free(t_mat);
717
- r_mpfi_temp_free(t_fi);
718
- return 0;
719
- }
720
-
721
- /* x = -(sqrt(a11**2-2*a00*a11+4*a01*a10+a00**2)-a11-a00)/2.0E+0 */
722
- /* x = (sqrt(a11**2-2*a00*a11+4*a01*a10+a00**2)+a11+a00)/2.0E+0 */
723
- /* If there are two real eigenvalues, return positive number. */
724
- /* If only one eigenvalue exists, return 0. */
725
- /* If there are two complex eigenvalues, this functionreturn negative number and */
726
- /* first returned value is real part and second one is imaginary part. */
727
- int mpfi_2d_square_matrix_eigenvalue(MPFI *val1, MPFI *val2, MPFIMatrix *x){
728
- int ret;
729
- MPFI *d;
730
- r_mpfi_temp_alloc_init(d);
731
-
732
- mpfi_sub(val1, x->data, x->data + 3);
733
- mpfi_mul(val1, val1, val1);
734
- mpfi_mul(d, x->data + 1, x->data + 2);
735
- mpfi_mul_ui(d, d, 4);
736
- mpfi_add(d, d, val1);
737
-
738
- mpfi_add(val1, x->data, x->data + 3);
739
- mpfi_div_ui(val1, val1, 2);
740
- if(mpfr_cmp_si(r_mpfi_right_ptr(d), 0) > 0){
741
- ret = 1;
742
- mpfi_sqrt(d, d);
743
- mpfi_div_ui(d, d, 2);
744
- mpfi_sub(val2, val1, d);
745
- mpfi_add(val1, val1, d);
746
- }else if(mpfr_cmp_si(r_mpfi_right_ptr(d), 0) < 0){
747
- ret = -1;
748
- mpfi_neg(d, d);
749
- mpfi_sqrt(d, d);
750
- mpfi_div_ui(val2, d, 2);
751
- }else{
752
- ret = 0;
753
- mpfi_set(val2, val1);
754
- }
755
-
756
- r_mpfi_temp_free(d);
757
- return ret;
758
- }
759
-
760
- void mpfi_2d_square_matrix_real_eigenvector(MPFIMatrix *vec, MPFIMatrix *x, MPFI *eigenval){
761
- MPFIMatrix *tmp;
762
- r_mpfi_matrix_temp_alloc_init(tmp, 2, 1);
763
- MPFI *tmp_fi;
764
- r_mpfi_temp_alloc_init(tmp_fi);
765
- mpfi_sub(tmp_fi, x->data + 3, eigenval);
766
- if(mpfi_has_zero(x->data + 1) > 0 && mpfi_has_zero(tmp_fi) > 0){
767
- mpfi_set(tmp->data, x->data + 2);
768
- mpfi_sub(tmp->data + 1, eigenval, x->data);
769
- }else{
770
- mpfi_sub(tmp->data, eigenval, x->data + 3);
771
- mpfi_set(tmp->data + 1, x->data + 1);
772
- }
773
- if(mpfi_vector_normalize(vec, tmp) == 1){
774
- gmp_printf("Argument matrix\n%.Ff\n%.Ff\n%.Ff\n%.Ff\n", x->data, x->data + 1, x->data + 2, x->data + 3);
775
- gmp_printf("Argument eigenvalue\n%.Ff\n", eigenval);
776
- rb_raise(rb_eArgError, "Invalid eigenvalue or eigenvector.");
777
- }
778
- r_mpfi_matrix_temp_free(tmp);
779
- r_mpfi_temp_free(tmp_fi);
780
- }
781
-
782
698
  void mpfi_square_matrix_identity(MPFIMatrix *id){
783
699
  int i, j, index;
784
700
  for (j = 0; j < id->column; j++) {
@@ -5,7 +5,6 @@
5
5
  #include <mpfi_io.h>
6
6
  #include "ruby_mpfr_matrix.h"
7
7
  #include "ruby_mpfi.h"
8
- #include "ruby_mpfi_complex.h"
9
8
 
10
9
  typedef struct __MPFIMatrix{
11
10
  int row, column, size;
@@ -92,12 +91,7 @@ int mpfi_vector_set_length(MPFIMatrix *new, MPFIMatrix *x, MPFR *l);
92
91
 
93
92
  /* ----------------- square matrix ----------------- */
94
93
  int mpfi_square_matrix_lu_decomp (MPFIMatrix *ret, int *indx, MPFIMatrix *x);
95
- void mpfi_2d_square_matrix_determinant(MPFI *det, MPFIMatrix *x);
96
- void mpfi_3d_square_matrix_determinant(MPFI *det, MPFIMatrix *x);
97
94
  void mpfi_square_matrix_determinant(MPFI *det, MPFIMatrix *x);
98
95
  void mpfi_square_matrix_qr_decomp(MPFIMatrix *q, MPFIMatrix *r, MPFIMatrix *x);
99
- int mpfi_2d_square_matrix_inverse_matrix(MPFIMatrix *inv, MPFIMatrix *x);
100
- int mpfi_2d_square_matrix_eigenvalue(MPFI *val1, MPFI *val2, MPFIMatrix *x);
101
- void mpfi_2d_square_matrix_real_eigenvector(MPFIMatrix *vec, MPFIMatrix *x, MPFI *eigenval);
102
96
  void mpfi_square_matrix_identity(MPFIMatrix *id);
103
97
 
@@ -42,7 +42,7 @@ VALUE r_mpfi_matrix_robj(MPFIMatrix *x){
42
42
  return ret;
43
43
  }
44
44
 
45
- /* Allocation function for MPF::Matrix. */
45
+ /* Allocation function for MPFI::Matrix. */
46
46
  static VALUE r_mpfi_matrix_alloc (VALUE self){
47
47
  MPFIMatrix *ptr;
48
48
  r_mpfi_make_matrix_struct(self, ptr);
@@ -56,10 +56,8 @@ static VALUE r_mpfi_matrix_alloc (VALUE self){
56
56
  /* mpfi_matrix_set(x, ptr_src); */
57
57
  /* } */
58
58
 
59
- /* Initialization function for MPF::Matrix. */
60
- static VALUE r_mpfi_matrix_initialize (int argc, VALUE *argv, VALUE self){
61
- MPFIMatrix *ptr;
62
- r_mpfi_get_matrix_struct(ptr, self);
59
+ static void r_mpfi_matrix_set_initial_value(MPFIMatrix *ptr, int argc, VALUE *argv)
60
+ {
63
61
  int row, column, i, j;
64
62
  VALUE row_ary;
65
63
  switch (argc) {
@@ -70,7 +68,7 @@ static VALUE r_mpfi_matrix_initialize (int argc, VALUE *argv, VALUE self){
70
68
  for (i = 0; i < row; i++) {
71
69
  row_ary = rb_ary_entry(argv[0], i);
72
70
  if (column != RARRAY_LEN(row_ary)) {
73
- rb_raise(rb_eArgError, "MPF::Matrix.new needs Array which has arrays of same sizes.");
71
+ rb_raise(rb_eArgError, "MPFI::Matrix.new needs Array which has arrays of same sizes.");
74
72
  }
75
73
  for (j = 0; j < column; j++) {
76
74
  r_mpfi_set_robj(mpfi_matrix_get_element(ptr, i, j), rb_ary_entry(row_ary, j));
@@ -82,23 +80,38 @@ static VALUE r_mpfi_matrix_initialize (int argc, VALUE *argv, VALUE self){
82
80
  mpfi_matrix_set_zeros(ptr);
83
81
  break;
84
82
  default:
85
- rb_raise(rb_eArgError, "MPF::Matrix.new needs one or two arguments.");
83
+ rb_raise(rb_eArgError, "MPFI::Matrix.new needs one or two arguments.");
86
84
  break;
87
85
  }
86
+ }
87
+
88
+ /* 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
+ {
91
+ MPFIMatrix *ptr;
92
+ VALUE val;
93
+ r_mpfi_make_matrix_struct(val, ptr);
94
+ r_mpfi_matrix_set_initial_value(ptr, argc, argv);
95
+ return val;
96
+ }
97
+
98
+ /* Initialization function for MPFI::Matrix. */
99
+ static VALUE r_mpfi_matrix_initialize (int argc, VALUE *argv, VALUE self){
100
+ MPFIMatrix *ptr;
101
+ r_mpfi_get_matrix_struct(ptr, self);
102
+ r_mpfi_matrix_set_initial_value(ptr, argc, argv);
88
103
  return Qtrue;
89
104
  }
90
105
 
91
- /* Allocation function for MPF::SquareMatrix. */
106
+ /* Allocation function for MPFI::SquareMatrix. */
92
107
  static VALUE r_mpfi_square_matrix_alloc (VALUE self){
93
108
  MPFIMatrix *ptr;
94
109
  r_mpfi_make_square_matrix_struct(self, ptr);
95
110
  return self;
96
111
  }
97
112
 
98
- /* Initialization function for MPF::SquareMatrix. */
99
- static VALUE r_mpfi_square_matrix_initialize (VALUE self, VALUE arg){
100
- MPFIMatrix *ptr;
101
- r_mpfi_get_matrix_struct(ptr, self);
113
+ static void r_mpfi_square_matrix_set_initial_value(MPFIMatrix *ptr, VALUE arg)
114
+ {
102
115
  int row, column, i, j;
103
116
  VALUE row_ary;
104
117
  switch(TYPE(arg)){
@@ -110,14 +123,14 @@ static VALUE r_mpfi_square_matrix_initialize (VALUE self, VALUE arg){
110
123
  for (i = 0; i < row; i++) {
111
124
  row_ary = rb_ary_entry(arg, i);
112
125
  if (column != RARRAY_LEN(row_ary)) {
113
- rb_raise(rb_eArgError, "MPF::Matrix.new needs Array which has arrays of same sizes.");
126
+ rb_raise(rb_eArgError, "MPFI::Matrix.new needs Array which has arrays of same sizes.");
114
127
  }
115
128
  for (j = 0; j < column; j++) {
116
129
  r_mpfi_set_robj(mpfi_matrix_get_element(ptr, i, j), rb_ary_entry(row_ary, j));
117
130
  }
118
131
  }
119
132
  }else{
120
- rb_raise(rb_eArgError, "MPF::SquareMatrix.new needs two dimensinal Array which has the same sizes of row and column.");
133
+ rb_raise(rb_eArgError, "MPFI::SquareMatrix.new needs two dimensinal Array which has the same sizes of row and column.");
121
134
  }
122
135
  break;
123
136
  case T_FIXNUM:
@@ -126,9 +139,26 @@ static VALUE r_mpfi_square_matrix_initialize (VALUE self, VALUE arg){
126
139
  mpfi_matrix_set_zeros(ptr);
127
140
  break;
128
141
  default:
129
- rb_raise(rb_eArgError, "MPF::SquareMatrix.new needs Array or Fixnum.");
142
+ rb_raise(rb_eArgError, "MPFI::SquareMatrix.new needs Array or Fixnum.");
130
143
  break;
131
144
  }
145
+ }
146
+
147
+ /* 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
+ {
150
+ MPFIMatrix *ptr;
151
+ VALUE val;
152
+ r_mpfi_make_matrix_struct(val, ptr);
153
+ r_mpfi_square_matrix_set_initial_value(ptr, arg);
154
+ return val;
155
+ }
156
+
157
+ /* Initialization function for MPFI::SquareMatrix. */
158
+ static VALUE r_mpfi_square_matrix_initialize (VALUE self, VALUE arg){
159
+ MPFIMatrix *ptr;
160
+ r_mpfi_get_matrix_struct(ptr, self);
161
+ r_mpfi_square_matrix_set_initial_value(ptr, arg);
132
162
  return Qtrue;
133
163
  }
134
164
 
@@ -142,17 +172,15 @@ static VALUE r_mpfi_matrix_initialize_copy (VALUE self, VALUE other){
142
172
  return Qtrue;
143
173
  }
144
174
 
145
- /* Allocation function for MPF::ColumnVector. */
175
+ /* Allocation function for MPFI::ColumnVector. */
146
176
  static VALUE r_mpfi_col_vector_alloc (VALUE self){
147
177
  MPFIMatrix *ptr;
148
178
  r_mpfi_make_col_vector_struct(self, ptr);
149
179
  return self;
150
180
  }
151
181
 
152
- /* Initialization function for MPF::ColumnVector. */
153
- static VALUE r_mpfi_col_vector_initialize (VALUE self, VALUE arg){
154
- MPFIMatrix *ptr;
155
- r_mpfi_get_matrix_struct(ptr, self);
182
+ static void r_mpfi_col_vector_set_initial_value(MPFIMatrix *ptr, VALUE arg)
183
+ {
156
184
  int row, i;
157
185
  switch(TYPE(arg)){
158
186
  case T_ARRAY:
@@ -170,23 +198,38 @@ static VALUE r_mpfi_col_vector_initialize (VALUE self, VALUE arg){
170
198
  }
171
199
  break;
172
200
  default:
173
- rb_raise(rb_eArgError, "MPF::ColumnVector.new needs Array or Fixnum.");
201
+ rb_raise(rb_eArgError, "MPFI::ColumnVector.new needs Array or Fixnum.");
174
202
  break;
175
203
  }
204
+ }
205
+
206
+ /* 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)
208
+ {
209
+ MPFIMatrix *ptr;
210
+ VALUE val;
211
+ r_mpfi_make_matrix_struct(val, ptr);
212
+ r_mpfi_col_vector_set_initial_value(ptr, arg);
213
+ return val;
214
+ }
215
+
216
+ /* Initialization function for MPFI::ColumnVector. */
217
+ static VALUE r_mpfi_col_vector_initialize (VALUE self, VALUE arg){
218
+ MPFIMatrix *ptr;
219
+ r_mpfi_get_matrix_struct(ptr, self);
220
+ r_mpfi_col_vector_set_initial_value(ptr, arg);
176
221
  return Qtrue;
177
222
  }
178
223
 
179
- /* Allocation function for MPF::RowVector. */
224
+ /* Allocation function for MPFI::RowVector. */
180
225
  static VALUE r_mpfi_row_vector_alloc (VALUE self){
181
226
  MPFIMatrix *ptr;
182
227
  r_mpfi_make_row_vector_struct(self, ptr);
183
228
  return self;
184
229
  }
185
230
 
186
- /* Initialization function for MPF::RowVector. */
187
- static VALUE r_mpfi_row_vector_initialize (VALUE self, VALUE arg){
188
- MPFIMatrix *ptr;
189
- r_mpfi_get_matrix_struct(ptr, self);
231
+ static void r_mpfi_row_vector_set_initial_value(MPFIMatrix *ptr, VALUE arg)
232
+ {
190
233
  int column, i;
191
234
  switch(TYPE(arg)){
192
235
  case T_ARRAY:
@@ -204,9 +247,26 @@ static VALUE r_mpfi_row_vector_initialize (VALUE self, VALUE arg){
204
247
  }
205
248
  break;
206
249
  default:
207
- rb_raise(rb_eArgError, "MPF::RowVector.new needs Array or Fixnum.");
250
+ rb_raise(rb_eArgError, "MPFI::RowVector.new needs Array or Fixnum.");
208
251
  break;
209
- }
252
+ }
253
+ }
254
+
255
+ /* 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)
257
+ {
258
+ MPFIMatrix *ptr;
259
+ VALUE val;
260
+ r_mpfi_make_matrix_struct(val, ptr);
261
+ r_mpfi_row_vector_set_initial_value(ptr, arg);
262
+ return val;
263
+ }
264
+
265
+ /* Initialization function for MPFI::RowVector. */
266
+ static VALUE r_mpfi_row_vector_initialize (VALUE self, VALUE arg){
267
+ MPFIMatrix *ptr;
268
+ r_mpfi_get_matrix_struct(ptr, self);
269
+ r_mpfi_row_vector_set_initial_value(ptr, arg);
210
270
  return Qtrue;
211
271
  }
212
272
 
@@ -1079,22 +1139,26 @@ static VALUE r_mpfr_matrix_to_fi_matrix(VALUE self){
1079
1139
  void Init_matrix(){
1080
1140
 
1081
1141
  /* Initialization of MPFI::Matrix, MPFI::SquareMatrix, MPFI::ColumnVector and MPFI::RowVector */
1082
- VALUE tmp_mpfi_class = rb_define_class("MPFI", rb_cNumeric);
1083
- r_mpfi_matrix = rb_define_class_under(tmp_mpfi_class, "Matrix", rb_cObject);
1084
- r_mpfi_square_matrix = rb_define_class_under(tmp_mpfi_class, "SquareMatrix", r_mpfi_matrix);
1085
- r_mpfi_col_vector = rb_define_class_under(tmp_mpfi_class, "ColumnVector", r_mpfi_matrix);
1086
- r_mpfi_row_vector = rb_define_class_under(tmp_mpfi_class, "RowVector", r_mpfi_matrix);
1142
+ VALUE tmp_r_mpfi_class = rb_define_class("MPFI", rb_cNumeric);
1143
+ r_mpfi_matrix = rb_define_class_under(tmp_r_mpfi_class, "Matrix", rb_cObject);
1144
+ r_mpfi_square_matrix = rb_define_class_under(tmp_r_mpfi_class, "SquareMatrix", r_mpfi_matrix);
1145
+ r_mpfi_col_vector = rb_define_class_under(tmp_r_mpfi_class, "ColumnVector", r_mpfi_matrix);
1146
+ r_mpfi_row_vector = rb_define_class_under(tmp_r_mpfi_class, "RowVector", r_mpfi_matrix);
1087
1147
 
1148
+ rb_define_singleton_method(r_mpfi_matrix, "Matrix", r_mpfi_matrix_global_new, -1);
1088
1149
  rb_define_alloc_func(r_mpfi_matrix, r_mpfi_matrix_alloc);
1089
1150
  rb_define_private_method(r_mpfi_matrix, "initialize", r_mpfi_matrix_initialize, -1);
1090
1151
  rb_define_private_method(r_mpfi_matrix, "initialize_copy", r_mpfi_matrix_initialize_copy, 1);
1091
1152
 
1153
+ rb_define_singleton_method(tmp_r_mpfi_class, "SquareMatrix", r_mpfi_square_matrix_global_new, 1);
1092
1154
  rb_define_alloc_func(r_mpfi_square_matrix, r_mpfi_square_matrix_alloc);
1093
1155
  rb_define_private_method(r_mpfi_square_matrix, "initialize", r_mpfi_square_matrix_initialize, 1);
1094
-
1156
+
1157
+ rb_define_singleton_method(tmp_r_mpfi_class, "ColumnVector", r_mpfi_col_vector_global_new, 1);
1095
1158
  rb_define_alloc_func(r_mpfi_col_vector, r_mpfi_col_vector_alloc);
1096
1159
  rb_define_private_method(r_mpfi_col_vector, "initialize", r_mpfi_col_vector_initialize, 1);
1097
1160
 
1161
+ rb_define_singleton_method(tmp_r_mpfi_class, "RowVector", r_mpfi_row_vector_global_new, 1);
1098
1162
  rb_define_alloc_func(r_mpfi_row_vector, r_mpfi_row_vector_alloc);
1099
1163
  rb_define_private_method(r_mpfi_row_vector, "initialize", r_mpfi_row_vector_initialize, 1);
1100
1164
 
@@ -1161,7 +1225,7 @@ void Init_matrix(){
1161
1225
  rb_define_singleton_method(r_mpfi_square_matrix, "identity", r_mpfi_square_matrix_identity, 1);
1162
1226
 
1163
1227
  /* Initialization of MPFI::Vector module */
1164
- r_mpfi_vector_module = rb_define_module_under(tmp_mpfi_class, "Vector");
1228
+ r_mpfi_vector_module = rb_define_module_under(tmp_r_mpfi_class, "Vector");
1165
1229
 
1166
1230
  rb_include_module(r_mpfi_col_vector, r_mpfi_vector_module);
1167
1231
  rb_include_module(r_mpfi_row_vector, r_mpfi_vector_module);
data/lib/mpfi/version.rb CHANGED
@@ -1,3 +1 @@
1
- module MPFI
2
- VERSION = '0.0.2'
3
- end
1
+ RUBY_MPFI_VERSION = '0.0.3'
data/ruby-mpfi.gemspec CHANGED
@@ -2,17 +2,17 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{ruby-mpfi}
5
- s.version = "0.0.2"
5
+ s.version = "0.0.3"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Takayuki YAMAGUCHI"]
9
- s.date = %q{2009-12-17}
9
+ s.date = %q{2009-12-19}
10
10
  s.description = %q{FIX (describe your package)}
11
11
  s.email = ["d@ytak.info"]
12
12
  s.extensions = ["ext/mpfi/extconf.rb", "ext/mpfi_complex/mpfi/extconf.rb", "ext/mpfi_matrix/mpfi/extconf.rb"]
13
- s.extra_rdoc_files = ["History.txt", "Manifest.txt", "PostInstall.txt"]
14
- s.files = ["History.txt", "Manifest.txt", "PostInstall.txt", "README.rdoc", "Rakefile", "ext/mpfi/extconf.rb", "ext/mpfi/func_mpfi_extention.c", "ext/mpfi/func_mpfi_extention.h", "ext/mpfi/make_c_source.rb", "ext/mpfi/ruby_mpfi.c", "ext/mpfi/ruby_mpfi.h", "ext/mpfi/ruby_mpfr.h", "ext/mpfi/yasnippet_mpfi.el", "ext/mpfi_complex/mpfi/extconf.rb", "ext/mpfi_complex/mpfi/func_mpfi_extention.h", "ext/mpfi_complex/mpfi/func_ruby_mpfi_complex.c", "ext/mpfi_complex/mpfi/func_ruby_mpfi_complex.h", "ext/mpfi_complex/mpfi/ruby_mpfi.h", "ext/mpfi_complex/mpfi/ruby_mpfi_complex.c", "ext/mpfi_complex/mpfi/ruby_mpfi_complex.h", "ext/mpfi_complex/mpfi/ruby_mpfr.h", "ext/mpfi_matrix/mpfi/extconf.rb", "ext/mpfi_matrix/mpfi/func_mpfi_extention.h", "ext/mpfi_matrix/mpfi/func_mpfi_matrix.c", "ext/mpfi_matrix/mpfi/func_mpfi_matrix.h", "ext/mpfi_matrix/mpfi/func_mpfr_matrix.h", "ext/mpfi_matrix/mpfi/func_ruby_mpfi_complex.h", "ext/mpfi_matrix/mpfi/ruby_mpfi.h", "ext/mpfi_matrix/mpfi/ruby_mpfi_complex.h", "ext/mpfi_matrix/mpfi/ruby_mpfi_matrix.c", "ext/mpfi_matrix/mpfi/ruby_mpfi_matrix.h", "ext/mpfi_matrix/mpfi/ruby_mpfr.h", "ext/mpfi_matrix/mpfi/ruby_mpfr_matrix.h", "lib/mpfi/matrix.rb", "lib/mpfi/version.rb", "ruby-mpfi.gemspec", "script/console", "script/destroy", "script/generate", "spec/mpfi/generate_number_module.rb", "spec/mpfi/mpfi_alloc_spec.rb", "spec/mpfi/mpfi_diam_arithmetic_spec.rb", "spec/mpfi/mpfi_interval_arithmetic_spec.rb", "spec/mpfi/mpfi_interval_functions_spec.rb", "spec/mpfi/mpfi_math_functions_spec.rb", "spec/mpfi/mpfi_set_operation_spec.rb", "spec/mpfi/ruby-mpfi_spec.rb", "spec/mpfi/spec_helper.rb", "spec/mpfi_complex/spec_helper.rb", "spec/mpfi_matrix/generate_matrix_arguments.rb", "spec/mpfi_matrix/mpfi_matrix_alloc_spec.rb", "spec/mpfi_matrix/mpfi_matrix_arithmetic_spec.rb", "spec/mpfi_matrix/mpfi_matrix_interval_func_spec.rb", "spec/mpfi_matrix/mpfi_matrix_set_element_spec.rb", "spec/mpfi_matrix/mpfi_matrix_set_operation_spec.rb", "spec/mpfi_matrix/mpfi_matrix_string_spec.rb", "spec/mpfi_matrix/mpfi_matrix_subdivision_spec.rb", "spec/mpfi_matrix/mpfi_square_matrix_spec.rb", "spec/mpfi_matrix/mpfi_vector_spec.rb", "spec/mpfi_matrix/spec_helper.rb", "spec/spec.opts", "tasks/extconf.rake"]
15
- s.homepage = %q{http://github.com/#{github_username}/#{project_name}}
13
+ s.extra_rdoc_files = ["History.txt", "Manifest.txt", "PostInstall.txt", "README.rdoc"]
14
+ s.files = ["History.txt", "Manifest.txt", "PostInstall.txt", "README.rdoc", "Rakefile", "ext/mpfi/extconf.rb", "ext/mpfi/func_mpfi_extention.c", "ext/mpfi/func_mpfi_extention.h", "ext/mpfi/ruby_mpfi.c", "ext/mpfi/ruby_mpfi.h", "ext/mpfi/ruby_mpfr.h", "ext/mpfi_complex/mpfi/extconf.rb", "ext/mpfi_complex/mpfi/func_mpfi_extention.h", "ext/mpfi_complex/mpfi/func_ruby_mpfi_complex.c", "ext/mpfi_complex/mpfi/func_ruby_mpfi_complex.h", "ext/mpfi_complex/mpfi/ruby_mpfi.h", "ext/mpfi_complex/mpfi/ruby_mpfi_complex.c", "ext/mpfi_complex/mpfi/ruby_mpfi_complex.h", "ext/mpfi_complex/mpfi/ruby_mpfr.h", "ext/mpfi_matrix/mpfi/extconf.rb", "ext/mpfi_matrix/mpfi/func_mpfi_extention.h", "ext/mpfi_matrix/mpfi/func_mpfi_matrix.c", "ext/mpfi_matrix/mpfi/func_mpfi_matrix.h", "ext/mpfi_matrix/mpfi/func_mpfr_matrix.h", "ext/mpfi_matrix/mpfi/ruby_mpfi.h", "ext/mpfi_matrix/mpfi/ruby_mpfi_matrix.c", "ext/mpfi_matrix/mpfi/ruby_mpfi_matrix.h", "ext/mpfi_matrix/mpfi/ruby_mpfr.h", "ext/mpfi_matrix/mpfi/ruby_mpfr_matrix.h", "lib/mpfi/matrix.rb", "lib/mpfi/version.rb", "ruby-mpfi.gemspec", "script/console", "script/destroy", "script/generate", "spec/mpfi/generate_number_module.rb", "spec/mpfi/mpfi_alloc_spec.rb", "spec/mpfi/mpfi_diam_arithmetic_spec.rb", "spec/mpfi/mpfi_interval_arithmetic_spec.rb", "spec/mpfi/mpfi_interval_functions_spec.rb", "spec/mpfi/mpfi_math_functions_spec.rb", "spec/mpfi/mpfi_set_operation_spec.rb", "spec/mpfi/ruby-mpfi_spec.rb", "spec/mpfi/spec_helper.rb", "spec/mpfi_complex/spec_helper.rb", "spec/mpfi_matrix/generate_matrix_arguments.rb", "spec/mpfi_matrix/mpfi_matrix_alloc_spec.rb", "spec/mpfi_matrix/mpfi_matrix_arithmetic_spec.rb", "spec/mpfi_matrix/mpfi_matrix_interval_func_spec.rb", "spec/mpfi_matrix/mpfi_matrix_set_element_spec.rb", "spec/mpfi_matrix/mpfi_matrix_set_operation_spec.rb", "spec/mpfi_matrix/mpfi_matrix_string_spec.rb", "spec/mpfi_matrix/mpfi_matrix_subdivision_spec.rb", "spec/mpfi_matrix/mpfi_square_matrix_spec.rb", "spec/mpfi_matrix/mpfi_vector_spec.rb", "spec/mpfi_matrix/spec_helper.rb", "spec/spec.opts", "tasks/extconf.rake"]
15
+ s.homepage = %q{http://rubyforge.org/projects/ruby-mpfr/}
16
16
  s.post_install_message = %q{PostInstall.txt}
17
17
  s.rdoc_options = ["--main", "README.rdoc"]
18
18
  s.require_paths = ["lib", "ext"]
@@ -25,11 +25,14 @@ Gem::Specification.new do |s|
25
25
  s.specification_version = 3
26
26
 
27
27
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
28
+ s.add_runtime_dependency(%q<ruby-mpfr>, [">= 0.0.4"])
28
29
  s.add_development_dependency(%q<hoe>, [">= 2.4.0"])
29
30
  else
31
+ s.add_dependency(%q<ruby-mpfr>, [">= 0.0.4"])
30
32
  s.add_dependency(%q<hoe>, [">= 2.4.0"])
31
33
  end
32
34
  else
35
+ s.add_dependency(%q<ruby-mpfr>, [">= 0.0.4"])
33
36
  s.add_dependency(%q<hoe>, [">= 2.4.0"])
34
37
  end
35
38
  end
@@ -9,8 +9,8 @@ describe MPFI, "when calculating mathematical functions" do
9
9
  it "should not raise error" do
10
10
  MPFR.set_default_prec(256)
11
11
  num = MPFI.new('4.2184930258398098')
12
- p MPFI::Math.sqr(num)
13
- p MPFI::Math.sqrt(num)
12
+ # p MPFI::Math.sqr(num)
13
+ # p MPFI::Math.sqrt(num)
14
14
  end
15
15
  end
16
16
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-mpfi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Takayuki YAMAGUCHI
@@ -9,9 +9,19 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-12-17 00:00:00 +09:00
12
+ date: 2009-12-19 00:00:00 +09:00
13
13
  default_executable:
14
14
  dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: ruby-mpfr
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.4
24
+ version:
15
25
  - !ruby/object:Gem::Dependency
16
26
  name: hoe
17
27
  type: :development
@@ -35,6 +45,7 @@ extra_rdoc_files:
35
45
  - History.txt
36
46
  - Manifest.txt
37
47
  - PostInstall.txt
48
+ - README.rdoc
38
49
  files:
39
50
  - History.txt
40
51
  - Manifest.txt
@@ -44,11 +55,9 @@ files:
44
55
  - ext/mpfi/extconf.rb
45
56
  - ext/mpfi/func_mpfi_extention.c
46
57
  - ext/mpfi/func_mpfi_extention.h
47
- - ext/mpfi/make_c_source.rb
48
58
  - ext/mpfi/ruby_mpfi.c
49
59
  - ext/mpfi/ruby_mpfi.h
50
60
  - ext/mpfi/ruby_mpfr.h
51
- - ext/mpfi/yasnippet_mpfi.el
52
61
  - ext/mpfi_complex/mpfi/extconf.rb
53
62
  - ext/mpfi_complex/mpfi/func_mpfi_extention.h
54
63
  - ext/mpfi_complex/mpfi/func_ruby_mpfi_complex.c
@@ -62,9 +71,7 @@ files:
62
71
  - ext/mpfi_matrix/mpfi/func_mpfi_matrix.c
63
72
  - ext/mpfi_matrix/mpfi/func_mpfi_matrix.h
64
73
  - ext/mpfi_matrix/mpfi/func_mpfr_matrix.h
65
- - ext/mpfi_matrix/mpfi/func_ruby_mpfi_complex.h
66
74
  - ext/mpfi_matrix/mpfi/ruby_mpfi.h
67
- - ext/mpfi_matrix/mpfi/ruby_mpfi_complex.h
68
75
  - ext/mpfi_matrix/mpfi/ruby_mpfi_matrix.c
69
76
  - ext/mpfi_matrix/mpfi/ruby_mpfi_matrix.h
70
77
  - ext/mpfi_matrix/mpfi/ruby_mpfr.h
@@ -99,7 +106,7 @@ files:
99
106
  - spec/spec.opts
100
107
  - tasks/extconf.rake
101
108
  has_rdoc: true
102
- homepage: http://github.com/#{github_username}/#{project_name}
109
+ homepage: http://rubyforge.org/projects/ruby-mpfr/
103
110
  licenses: []
104
111
 
105
112
  post_install_message: PostInstall.txt