carray 1.2.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +0 -1
- data/ca_iter_block.c +32 -30
- data/ca_iter_dimension.c +24 -22
- data/ca_iter_window.c +25 -23
- data/ca_obj_array.c +58 -56
- data/ca_obj_bitarray.c +27 -27
- data/ca_obj_bitfield.c +46 -45
- data/ca_obj_block.c +77 -72
- data/ca_obj_fake.c +20 -20
- data/ca_obj_farray.c +22 -22
- data/ca_obj_field.c +31 -30
- data/ca_obj_grid.c +63 -62
- data/ca_obj_mapping.c +35 -32
- data/ca_obj_object.c +54 -54
- data/ca_obj_reduce.c +13 -13
- data/ca_obj_refer.c +42 -39
- data/ca_obj_repeat.c +50 -47
- data/ca_obj_select.c +24 -24
- data/ca_obj_shift.c +61 -58
- data/ca_obj_transpose.c +52 -51
- data/ca_obj_unbound_repeat.c +28 -27
- data/ca_obj_window.c +77 -72
- data/carray.gemspec +0 -2
- data/carray.h +190 -163
- data/carray_access.c +137 -136
- data/carray_attribute.c +24 -13
- data/carray_call_cfunc.c +21 -21
- data/carray_cast.c +106 -110
- data/carray_cast_func.rb +17 -17
- data/carray_class.c +3 -3
- data/carray_conversion.c +15 -15
- data/carray_copy.c +27 -27
- data/carray_core.c +22 -21
- data/carray_element.c +55 -47
- data/carray_generate.c +32 -32
- data/carray_iterator.c +36 -35
- data/carray_loop.c +37 -37
- data/carray_mask.c +21 -21
- data/carray_math.rb +18 -18
- data/carray_numeric.c +1 -1
- data/carray_operator.c +19 -18
- data/carray_order.c +30 -30
- data/carray_random.c +34 -32
- data/carray_sort_addr.c +12 -12
- data/carray_stat.c +127 -127
- data/carray_stat_proc.rb +152 -141
- data/carray_test.c +16 -16
- data/carray_utils.c +58 -56
- data/ext/calculus/carray_calculus.c +19 -20
- data/ext/calculus/carray_interp.c +12 -11
- data/ext/fortio/lib/fortio/fortran_sequential.rb +2 -2
- data/ext/fortio/ruby_fortio.c +1 -1
- data/ext/imagemap/carray_imagemap.c +14 -14
- data/ext/narray/ca_wrap_narray.c +30 -21
- data/extconf.rb +5 -0
- data/lib/carray/base/basic.rb +4 -3
- data/lib/carray/base/serialize.rb +3 -3
- data/lib/carray/graphics/gnuplot.rb +10 -7
- data/lib/carray/io/csv.rb +14 -9
- data/lib/carray/io/imagemagick.rb +7 -0
- data/lib/carray/io/sqlite3.rb +6 -4
- data/mkmath.rb +20 -20
- data/ruby_carray.c +2 -0
- data/ruby_ccomplex.c +3 -3
- data/test/test_130.rb +23 -0
- data/test/test_ALL.rb +2 -1
- data/test/test_order.rb +3 -3
- data/test/test_stat.rb +2 -2
- data/version.h +4 -4
- metadata +4 -37
- data/examples/ex001.rb +0 -10
- data/examples/test-int.rb +0 -13
- data/lib/carray/autoload/autoload_io_excel.rb +0 -5
- data/lib/carray/io/excel.rb +0 -26
data/carray_test.c
CHANGED
@@ -45,7 +45,7 @@ ca_check_rank (void *ap, int rank)
|
|
45
45
|
}
|
46
46
|
|
47
47
|
void
|
48
|
-
ca_check_shape (void *ap, int rank,
|
48
|
+
ca_check_shape (void *ap, int rank, ca_size_t *dim)
|
49
49
|
{
|
50
50
|
CArray *ca = (CArray *) ap;
|
51
51
|
int i;
|
@@ -110,7 +110,7 @@ ca_check_same_shape (void *ap1, void *ap2)
|
|
110
110
|
}
|
111
111
|
|
112
112
|
void
|
113
|
-
ca_check_index (void *ap,
|
113
|
+
ca_check_index (void *ap, ca_size_t *idx)
|
114
114
|
{
|
115
115
|
CArray *ca = (CArray *) ap;
|
116
116
|
int i;
|
@@ -154,10 +154,10 @@ ca_has_same_shape (void *ap1, void *ap2)
|
|
154
154
|
}
|
155
155
|
|
156
156
|
int
|
157
|
-
ca_is_valid_index (void *ap,
|
157
|
+
ca_is_valid_index (void *ap, ca_size_t *idx)
|
158
158
|
{
|
159
159
|
CArray *ca = (CArray *) ap;
|
160
|
-
|
160
|
+
int8_t i;
|
161
161
|
for (i=0; i<ca->rank; i++) {
|
162
162
|
if ( idx[i] < 0 || idx[i] >= ca->dim[i] ) {
|
163
163
|
return 0;
|
@@ -231,7 +231,7 @@ static VALUE
|
|
231
231
|
rb_ca_is_valid_index (int argc, VALUE *argv, VALUE self)
|
232
232
|
{
|
233
233
|
CArray *ca;
|
234
|
-
|
234
|
+
ca_size_t idx;
|
235
235
|
int i;
|
236
236
|
|
237
237
|
Data_Get_Struct(self, CArray, ca);
|
@@ -241,7 +241,7 @@ rb_ca_is_valid_index (int argc, VALUE *argv, VALUE self)
|
|
241
241
|
"invalid # of arguments (%i for %i)", argc, ca->rank);
|
242
242
|
}
|
243
243
|
for (i=0; i<ca->rank; i++) {
|
244
|
-
idx =
|
244
|
+
idx = NUM2SIZE(argv[i]);
|
245
245
|
if ( idx < 0 ) {
|
246
246
|
idx += ca->dim[i];
|
247
247
|
}
|
@@ -264,10 +264,10 @@ static VALUE
|
|
264
264
|
rb_ca_is_valid_addr (VALUE self, VALUE raddr)
|
265
265
|
{
|
266
266
|
CArray *ca;
|
267
|
-
|
267
|
+
ca_size_t addr;
|
268
268
|
|
269
269
|
Data_Get_Struct(self, CArray, ca);
|
270
|
-
addr =
|
270
|
+
addr = NUM2SIZE(raddr);
|
271
271
|
if ( addr < 0 ) {
|
272
272
|
addr += ca->elements;
|
273
273
|
}
|
@@ -363,8 +363,8 @@ ca_equal (void *ap, void *bp)
|
|
363
363
|
int flag = 1;
|
364
364
|
int masked_a, masked_b;
|
365
365
|
boolean8_t *ma, *mb;
|
366
|
-
|
367
|
-
|
366
|
+
ca_size_t i;
|
367
|
+
ca_size_t bytes;
|
368
368
|
char *pa;
|
369
369
|
char *pb;
|
370
370
|
ca_eql_func eql;
|
@@ -497,9 +497,9 @@ rb_ca_equal (VALUE self, VALUE other)
|
|
497
497
|
*/
|
498
498
|
|
499
499
|
int32_t
|
500
|
-
ca_mem_hash (char *mp,
|
500
|
+
ca_mem_hash (char *mp, ca_size_t mlen)
|
501
501
|
{
|
502
|
-
register
|
502
|
+
register ca_size_t len = mlen;
|
503
503
|
register char *p = mp;
|
504
504
|
register int32_t key = 0;
|
505
505
|
while (len--) {
|
@@ -509,13 +509,13 @@ ca_mem_hash (char *mp, int32_t mlen)
|
|
509
509
|
return key;
|
510
510
|
}
|
511
511
|
|
512
|
-
static
|
512
|
+
static int32_t
|
513
513
|
ca_hash (CArray *ca)
|
514
514
|
{
|
515
|
-
|
515
|
+
int32_t hash;
|
516
516
|
|
517
517
|
if ( ca_is_any_masked(ca) ) {
|
518
|
-
|
518
|
+
ca_size_t bytes = ca->bytes;
|
519
519
|
boolean8_t *m = (boolean8_t*) ca->mask->ptr;
|
520
520
|
/* char *tptr = ALLOC_N(char, ca_length(ca)); */
|
521
521
|
char *tptr = malloc_with_check(ca_length(ca));
|
@@ -556,7 +556,7 @@ VALUE
|
|
556
556
|
rb_ca_hash (VALUE self)
|
557
557
|
{
|
558
558
|
CArray *ca;
|
559
|
-
|
559
|
+
int32_t hash;
|
560
560
|
|
561
561
|
Data_Get_Struct(self, CArray, ca);
|
562
562
|
hash = ca_hash(ca);
|
data/carray_utils.c
CHANGED
@@ -71,20 +71,20 @@ ca_debug () {}
|
|
71
71
|
|
72
72
|
/* ------------------------------------------------------------------- */
|
73
73
|
|
74
|
-
|
74
|
+
ca_size_t
|
75
75
|
ca_set_iterator (int n, ...)
|
76
76
|
{
|
77
77
|
CArray *ca;
|
78
78
|
char **p;
|
79
|
-
|
80
|
-
|
79
|
+
ca_size_t *s;
|
80
|
+
ca_size_t max = -1;
|
81
81
|
int all_scalar = 1;
|
82
82
|
va_list args;
|
83
83
|
va_start(args, n);
|
84
84
|
while ( n-- ) {
|
85
85
|
ca = va_arg(args, CArray *);
|
86
86
|
p = va_arg(args, char **);
|
87
|
-
s = va_arg(args,
|
87
|
+
s = va_arg(args, ca_size_t *);
|
88
88
|
*p = ca->ptr;
|
89
89
|
if ( ca_is_scalar(ca) ) {
|
90
90
|
*s = 0;
|
@@ -112,11 +112,11 @@ ca_set_iterator (int n, ...)
|
|
112
112
|
|
113
113
|
/* ------------------------------------------------------------------- */
|
114
114
|
|
115
|
-
|
115
|
+
ca_size_t
|
116
116
|
ca_get_loop_count (int n, ...)
|
117
117
|
{
|
118
118
|
CArray *ca;
|
119
|
-
|
119
|
+
ca_size_t elements = -1;
|
120
120
|
int32_t is_scalar = 1;
|
121
121
|
va_list args;
|
122
122
|
va_start(args, n);
|
@@ -162,9 +162,10 @@ ca_get_loop_count (int n, ...)
|
|
162
162
|
*/
|
163
163
|
|
164
164
|
void
|
165
|
-
ca_parse_range (VALUE arg,
|
165
|
+
ca_parse_range (VALUE arg, ca_size_t size,
|
166
|
+
ca_size_t *poffset, ca_size_t *pcount, ca_size_t *pstep)
|
166
167
|
{
|
167
|
-
|
168
|
+
ca_size_t first, start, last, count, step, bound, excl;
|
168
169
|
|
169
170
|
retry:
|
170
171
|
|
@@ -175,7 +176,7 @@ ca_parse_range (VALUE arg, int size, int *poffset, int *pcount, int *pstep)
|
|
175
176
|
}
|
176
177
|
else if ( rb_obj_is_kind_of(arg, rb_cInteger) ) {
|
177
178
|
/* i */
|
178
|
-
start =
|
179
|
+
start = NUM2SIZE(arg);
|
179
180
|
CA_CHECK_INDEX(start, size);
|
180
181
|
*poffset = start;
|
181
182
|
*pcount = 1;
|
@@ -183,8 +184,8 @@ ca_parse_range (VALUE arg, int size, int *poffset, int *pcount, int *pstep)
|
|
183
184
|
}
|
184
185
|
else if ( rb_obj_is_kind_of(arg, rb_cRange) ) {
|
185
186
|
/* i..j */
|
186
|
-
first =
|
187
|
-
last =
|
187
|
+
first = NUM2SIZE(RANGE_BEG(arg));
|
188
|
+
last = NUM2SIZE(RANGE_END(arg));
|
188
189
|
excl = RTEST(RANGE_EXCL(arg));
|
189
190
|
CA_CHECK_INDEX(first, size);
|
190
191
|
if ( last < 0 ) {
|
@@ -198,7 +199,7 @@ ca_parse_range (VALUE arg, int size, int *poffset, int *pcount, int *pstep)
|
|
198
199
|
"invalid index range");
|
199
200
|
}
|
200
201
|
*poffset = first;
|
201
|
-
*pcount =
|
202
|
+
*pcount = llabs(last - first) + 1;
|
202
203
|
*pstep = 1;
|
203
204
|
}
|
204
205
|
else if ( TYPE(arg) == T_ARRAY ) {
|
@@ -210,12 +211,12 @@ ca_parse_range (VALUE arg, int size, int *poffset, int *pcount, int *pstep)
|
|
210
211
|
VALUE arg0 = rb_ary_entry(arg, 0);
|
211
212
|
VALUE arg1 = rb_ary_entry(arg, 1);
|
212
213
|
if ( NIL_P(arg0) ) { /* [nil,k] */
|
213
|
-
step =
|
214
|
+
step = NUM2SIZE(arg1);
|
214
215
|
if ( step == 0 ) {
|
215
216
|
rb_raise(rb_eRuntimeError, "step should not be 0");
|
216
217
|
}
|
217
218
|
start = 0;
|
218
|
-
count = (size-1)/
|
219
|
+
count = (size-1)/llabs(step) + 1;
|
219
220
|
bound = start + (count - 1)*step;
|
220
221
|
CA_CHECK_INDEX(start, size);
|
221
222
|
CA_CHECK_INDEX(bound, size);
|
@@ -224,10 +225,10 @@ ca_parse_range (VALUE arg, int size, int *poffset, int *pcount, int *pstep)
|
|
224
225
|
*pstep = step;
|
225
226
|
}
|
226
227
|
else if ( rb_obj_is_kind_of(arg0, rb_cRange) ) { /* [i..j,k] */
|
227
|
-
start =
|
228
|
-
last =
|
228
|
+
start = NUM2SIZE(RANGE_BEG(arg0));
|
229
|
+
last = NUM2SIZE(RANGE_END(arg0));
|
229
230
|
excl = RTEST(RANGE_EXCL(arg0));
|
230
|
-
step =
|
231
|
+
step = NUM2SIZE(arg1);
|
231
232
|
if ( step == 0 ) {
|
232
233
|
rb_raise(rb_eRuntimeError, "step should not be 0");
|
233
234
|
}
|
@@ -245,7 +246,7 @@ ca_parse_range (VALUE arg, int size, int *poffset, int *pcount, int *pstep)
|
|
245
246
|
count = 1;
|
246
247
|
}
|
247
248
|
else {
|
248
|
-
count =
|
249
|
+
count = llabs(last - start)/llabs(step) + 1;
|
249
250
|
}
|
250
251
|
bound = start + (count - 1)*step;
|
251
252
|
CA_CHECK_INDEX(bound, size);
|
@@ -254,8 +255,8 @@ ca_parse_range (VALUE arg, int size, int *poffset, int *pcount, int *pstep)
|
|
254
255
|
*pstep = step;
|
255
256
|
}
|
256
257
|
else { /* [i,n] */
|
257
|
-
start =
|
258
|
-
count =
|
258
|
+
start = NUM2SIZE(arg0);
|
259
|
+
count = NUM2SIZE(arg1);
|
259
260
|
bound = start + (count - 1);
|
260
261
|
CA_CHECK_INDEX(start, size);
|
261
262
|
CA_CHECK_INDEX(bound, size);
|
@@ -265,9 +266,9 @@ ca_parse_range (VALUE arg, int size, int *poffset, int *pcount, int *pstep)
|
|
265
266
|
}
|
266
267
|
}
|
267
268
|
else if ( RARRAY_LEN(arg) == 3 ) { /* [i,n,k] */
|
268
|
-
start =
|
269
|
-
count =
|
270
|
-
step =
|
269
|
+
start = NUM2SIZE(rb_ary_entry(arg, 0));
|
270
|
+
count = NUM2SIZE(rb_ary_entry(arg, 1));
|
271
|
+
step = NUM2SIZE(rb_ary_entry(arg, 2));
|
271
272
|
if ( step == 0 ) {
|
272
273
|
rb_raise(rb_eRuntimeError, "step should not be 0");
|
273
274
|
}
|
@@ -288,10 +289,10 @@ ca_parse_range (VALUE arg, int size, int *poffset, int *pcount, int *pstep)
|
|
288
289
|
}
|
289
290
|
|
290
291
|
void
|
291
|
-
ca_parse_range_without_check (VALUE arg,
|
292
|
-
|
292
|
+
ca_parse_range_without_check (VALUE arg, ca_size_t size,
|
293
|
+
ca_size_t *poffset, ca_size_t *pcount, ca_size_t *pstep)
|
293
294
|
{
|
294
|
-
|
295
|
+
ca_size_t first, start, last, count, step, bound, excl;
|
295
296
|
|
296
297
|
retry:
|
297
298
|
|
@@ -302,15 +303,15 @@ ca_parse_range_without_check (VALUE arg, int size,
|
|
302
303
|
}
|
303
304
|
else if ( rb_obj_is_kind_of(arg, rb_cInteger) ) {
|
304
305
|
/* i */
|
305
|
-
start =
|
306
|
+
start = NUM2SIZE(arg);
|
306
307
|
*poffset = start;
|
307
308
|
*pcount = 1;
|
308
309
|
*pstep = 1;
|
309
310
|
}
|
310
311
|
else if ( rb_obj_is_kind_of(arg, rb_cRange) ) {
|
311
312
|
/* i..j */
|
312
|
-
first =
|
313
|
-
last =
|
313
|
+
first = NUM2SIZE(RANGE_BEG(arg));
|
314
|
+
last = NUM2SIZE(RANGE_END(arg));
|
314
315
|
excl = RTEST(RANGE_EXCL(arg));
|
315
316
|
if ( excl ) {
|
316
317
|
last += ( (last>=first) ? -1 : 1 );
|
@@ -329,30 +330,30 @@ ca_parse_range_without_check (VALUE arg, int size,
|
|
329
330
|
VALUE arg1 = rb_ary_entry(arg, 1);
|
330
331
|
if ( NIL_P(arg0) ) { /* [nil,k] */
|
331
332
|
start = 0;
|
332
|
-
step =
|
333
|
-
count = (size-1)/
|
333
|
+
step = NUM2SIZE(arg1);
|
334
|
+
count = (size-1)/llabs(step) + 1;
|
334
335
|
bound = start + (count - 1)*step;
|
335
336
|
*poffset = start;
|
336
337
|
*pcount = count;
|
337
338
|
*pstep = step;
|
338
339
|
}
|
339
340
|
else if ( rb_obj_is_kind_of(arg0, rb_cRange) ) { /* [i..j,k] */
|
340
|
-
start =
|
341
|
-
last =
|
341
|
+
start = NUM2SIZE(RANGE_BEG(arg0));
|
342
|
+
last = NUM2SIZE(RANGE_END(arg0));
|
342
343
|
excl = RTEST(RANGE_EXCL(arg0));
|
343
|
-
step =
|
344
|
+
step = NUM2SIZE(arg1);
|
344
345
|
if ( excl ) {
|
345
346
|
last += ( (last>=start) ? -1 : 1 );
|
346
347
|
}
|
347
|
-
count = (last - start)/
|
348
|
+
count = (last - start)/llabs(step) + 1;
|
348
349
|
bound = start + (count - 1)*step;
|
349
350
|
*poffset = start;
|
350
351
|
*pcount = count;
|
351
352
|
*pstep = step;
|
352
353
|
}
|
353
354
|
else { /* [i,n] */
|
354
|
-
start =
|
355
|
-
count =
|
355
|
+
start = NUM2SIZE(arg0);
|
356
|
+
count = NUM2SIZE(arg1);
|
356
357
|
bound = start + (count - 1);
|
357
358
|
*poffset = start;
|
358
359
|
*pcount = count;
|
@@ -360,9 +361,9 @@ ca_parse_range_without_check (VALUE arg, int size,
|
|
360
361
|
}
|
361
362
|
}
|
362
363
|
else if ( RARRAY_LEN(arg) == 3 ) { /* [i,n,k] */
|
363
|
-
start =
|
364
|
-
count =
|
365
|
-
step =
|
364
|
+
start = NUM2SIZE(rb_ary_entry(arg, 0));
|
365
|
+
count = NUM2SIZE(rb_ary_entry(arg, 1));
|
366
|
+
step = NUM2SIZE(rb_ary_entry(arg, 2));
|
366
367
|
bound = start + (count - 1)*step;
|
367
368
|
*poffset = start;
|
368
369
|
*pcount = count;
|
@@ -377,8 +378,8 @@ ca_parse_range_without_check (VALUE arg, int size,
|
|
377
378
|
}
|
378
379
|
}
|
379
380
|
|
380
|
-
|
381
|
-
ca_bounds_normalize_index (int8_t bounds,
|
381
|
+
ca_size_t
|
382
|
+
ca_bounds_normalize_index (int8_t bounds, ca_size_t size0, ca_size_t k)
|
382
383
|
{
|
383
384
|
switch ( bounds ) {
|
384
385
|
case CA_BOUNDS_MASK:
|
@@ -428,7 +429,7 @@ rb_ca_s_scan_float (int argc, VALUE *argv, VALUE self)
|
|
428
429
|
double value;
|
429
430
|
int count;
|
430
431
|
|
431
|
-
rb_scan_args(argc, argv, "11", &rstr, &rfval);
|
432
|
+
rb_scan_args(argc, argv, "11", (VALUE *)&rstr, (VALUE *)&rfval);
|
432
433
|
|
433
434
|
if ( NIL_P(rstr) ) {
|
434
435
|
return ( NIL_P(rfval) ) ? rb_float_new(0.0/0.0) : rfval;
|
@@ -453,10 +454,10 @@ rb_ca_s_scan_int (int argc, VALUE *argv, VALUE self)
|
|
453
454
|
long value;
|
454
455
|
int count;
|
455
456
|
|
456
|
-
rb_scan_args(argc, argv, "11", &rstr, &rfval);
|
457
|
+
rb_scan_args(argc, argv, "11", (VALUE *) &rstr, (VALUE *) &rfval);
|
457
458
|
|
458
459
|
if ( NIL_P(rstr) ) {
|
459
|
-
return ( NIL_P(rfval) ) ?
|
460
|
+
return ( NIL_P(rfval) ) ? INT2NUM(0) : rfval;
|
460
461
|
}
|
461
462
|
|
462
463
|
Check_Type(rstr, T_STRING);
|
@@ -464,15 +465,15 @@ rb_ca_s_scan_int (int argc, VALUE *argv, VALUE self)
|
|
464
465
|
count = sscanf(StringValuePtr(rstr), "%li", &value);
|
465
466
|
|
466
467
|
if ( count == 1 ) {
|
467
|
-
return
|
468
|
+
return SIZE2NUM(value);
|
468
469
|
}
|
469
470
|
else {
|
470
|
-
return ( NIL_P(rfval) ) ?
|
471
|
+
return ( NIL_P(rfval) ) ? INT2NUM(0) : rfval;
|
471
472
|
}
|
472
473
|
}
|
473
474
|
|
474
475
|
static const struct {
|
475
|
-
char *name;
|
476
|
+
const char *name;
|
476
477
|
int data_type;
|
477
478
|
} ca_name_to_type[] = {
|
478
479
|
{ "fixlen", CA_FIXLEN },
|
@@ -510,10 +511,11 @@ rb_ca_guess_type (VALUE obj)
|
|
510
511
|
VALUE inspect;
|
511
512
|
|
512
513
|
if ( TYPE(obj) == T_FIXNUM ) {
|
513
|
-
return
|
514
|
+
return NUM2SIZE(obj);
|
514
515
|
}
|
515
516
|
else if ( TYPE(obj) == T_STRING ) {
|
516
|
-
char *name0
|
517
|
+
const char *name0;
|
518
|
+
char *name = StringValuePtr(obj);
|
517
519
|
int i;
|
518
520
|
i = 0;
|
519
521
|
while ( ( name0 = ca_name_to_type[i].name ) ) {
|
@@ -539,20 +541,20 @@ rb_ca_guess_type (VALUE obj)
|
|
539
541
|
|
540
542
|
void
|
541
543
|
rb_ca_guess_type_and_bytes (VALUE rtype, VALUE rbytes,
|
542
|
-
int8_t *data_type,
|
544
|
+
int8_t *data_type, ca_size_t *bytes)
|
543
545
|
{
|
544
546
|
*data_type = rb_ca_guess_type(rtype);
|
545
547
|
|
546
548
|
if ( *data_type == CA_FIXLEN ) {
|
547
549
|
if ( TYPE(rtype) == T_CLASS ) {
|
548
|
-
*bytes =
|
550
|
+
*bytes = NUM2SIZE(rb_const_get(rtype, rb_intern("DATA_SIZE")));
|
549
551
|
}
|
550
552
|
else {
|
551
553
|
if ( NIL_P(rbytes) ) {
|
552
554
|
*bytes = 0;
|
553
555
|
}
|
554
556
|
else {
|
555
|
-
*bytes =
|
557
|
+
*bytes = NUM2SIZE(rbytes);
|
556
558
|
}
|
557
559
|
}
|
558
560
|
}
|
@@ -572,10 +574,10 @@ rb_ca_s_guess_type_and_bytes (int argc, VALUE *argv, VALUE klass)
|
|
572
574
|
{
|
573
575
|
VALUE rtype, rbytes;
|
574
576
|
int8_t data_type;
|
575
|
-
|
576
|
-
rb_scan_args(argc, argv, "11", &rtype, &rbytes);
|
577
|
+
ca_size_t bytes;
|
578
|
+
rb_scan_args(argc, argv, "11", (VALUE *) &rtype, (VALUE *) &rbytes);
|
577
579
|
rb_ca_guess_type_and_bytes(rtype, rbytes, &data_type, &bytes);
|
578
|
-
return rb_assoc_new(
|
580
|
+
return rb_assoc_new(INT2NUM(data_type), SIZE2NUM(bytes));
|
579
581
|
}
|
580
582
|
|
581
583
|
VALUE
|
@@ -18,7 +18,7 @@
|
|
18
18
|
/* ----------------------------------------------------------------- */
|
19
19
|
|
20
20
|
static double
|
21
|
-
simpson (double *x, double *y,
|
21
|
+
simpson (double *x, double *y, ca_size_t n)
|
22
22
|
{
|
23
23
|
double s;
|
24
24
|
|
@@ -53,7 +53,7 @@ simpson (double *x, double *y, int n)
|
|
53
53
|
else {
|
54
54
|
double x0, x1, x2;
|
55
55
|
double h, m, c0, c1, c2;
|
56
|
-
|
56
|
+
ca_size_t i;
|
57
57
|
s = 0.0;
|
58
58
|
for (i=0; i<n-2; i+=2) {
|
59
59
|
x0 = x[i];
|
@@ -100,10 +100,10 @@ rb_ca_integrate (volatile VALUE self, volatile VALUE vsc)
|
|
100
100
|
|
101
101
|
/* ----------------------------------------------------------------- */
|
102
102
|
|
103
|
-
static
|
104
|
-
linear_index (
|
103
|
+
static ca_size_t
|
104
|
+
linear_index (ca_size_t n, double *y, double yy, double *idx)
|
105
105
|
{
|
106
|
-
|
106
|
+
ca_size_t a, b, c, x1;
|
107
107
|
double ya, yb, yc;
|
108
108
|
double y1, y2;
|
109
109
|
double rest;
|
@@ -120,7 +120,7 @@ linear_index (int n, double *y, double yy, double *idx)
|
|
120
120
|
|
121
121
|
/* check for equally spaced scale */
|
122
122
|
|
123
|
-
a = (
|
123
|
+
a = (ca_size_t)((yy-y[0])/(y[n-1]-y[0])*(n-1));
|
124
124
|
|
125
125
|
if ( a >= 0 && a < n-1 ) {
|
126
126
|
if ( (y[a] - yy) * (y[a+1] - yy) <= 0 ) { /* lucky case */
|
@@ -193,11 +193,11 @@ rb_ca_binary_search_linear_index (volatile VALUE self, volatile VALUE vx)
|
|
193
193
|
{
|
194
194
|
volatile VALUE out, out0;
|
195
195
|
CArray *ca, *sc, *cx, *co0, *co;
|
196
|
-
|
196
|
+
ca_size_t n;
|
197
197
|
double *x;
|
198
198
|
double *px;
|
199
199
|
double *po;
|
200
|
-
|
200
|
+
ca_size_t i;
|
201
201
|
|
202
202
|
Data_Get_Struct(self, CArray, ca);
|
203
203
|
|
@@ -246,7 +246,7 @@ rb_ca_binary_search_linear_index (volatile VALUE self, volatile VALUE vx)
|
|
246
246
|
ca_detach_n(3, sc, cx, co);
|
247
247
|
|
248
248
|
if ( rb_ca_is_scalar(vx) ) {
|
249
|
-
return rb_funcall(out0, rb_intern("[]"), 1,
|
249
|
+
return rb_funcall(out0, rb_intern("[]"), 1, INT2NUM(0));
|
250
250
|
}
|
251
251
|
else {
|
252
252
|
return out0;
|
@@ -496,10 +496,10 @@ deriv_penta (double *x, double *y, double xx)
|
|
496
496
|
}
|
497
497
|
|
498
498
|
static double
|
499
|
-
interpolate_linear (double *x, double *y,
|
499
|
+
interpolate_linear (double *x, double *y, ca_size_t n, double xx)
|
500
500
|
{
|
501
501
|
double ri;
|
502
|
-
|
502
|
+
ca_size_t i0;
|
503
503
|
if ( n == 1) {
|
504
504
|
return y[0];
|
505
505
|
}
|
@@ -524,10 +524,10 @@ interpolate_linear (double *x, double *y, int n, double xx)
|
|
524
524
|
}
|
525
525
|
|
526
526
|
static double
|
527
|
-
interpolate_cubic (double *x, double *y,
|
527
|
+
interpolate_cubic (double *x, double *y, ca_size_t n, double xx)
|
528
528
|
{
|
529
529
|
double ri;
|
530
|
-
|
530
|
+
ca_size_t i0;
|
531
531
|
if ( n == 1) {
|
532
532
|
return y[0];
|
533
533
|
}
|
@@ -558,10 +558,10 @@ interpolate_cubic (double *x, double *y, int n, double xx)
|
|
558
558
|
}
|
559
559
|
|
560
560
|
static double
|
561
|
-
differentiate (double *x, double *y,
|
561
|
+
differentiate (double *x, double *y, ca_size_t n, double xx)
|
562
562
|
{
|
563
563
|
double ri;
|
564
|
-
|
564
|
+
ca_size_t i0;
|
565
565
|
switch ( n ) {
|
566
566
|
case 1:
|
567
567
|
return 0.0/0.0;
|
@@ -600,7 +600,7 @@ rb_ca_interpolate (int argc, VALUE *argv, VALUE self)
|
|
600
600
|
char *typename = NULL;
|
601
601
|
int type = 0;
|
602
602
|
double *px, *po;
|
603
|
-
|
603
|
+
ca_size_t i;
|
604
604
|
|
605
605
|
Data_Get_Struct(self, CArray, ca);
|
606
606
|
|
@@ -612,7 +612,6 @@ rb_ca_interpolate (int argc, VALUE *argv, VALUE self)
|
|
612
612
|
typename = StringValuePtr(rtype);
|
613
613
|
}
|
614
614
|
|
615
|
-
|
616
615
|
if ( typename == NULL || ! strncmp("cubic", typename, 5) ) {
|
617
616
|
type = 3;
|
618
617
|
}
|
@@ -698,7 +697,7 @@ rb_ca_interpolate (int argc, VALUE *argv, VALUE self)
|
|
698
697
|
ca_detach_n(4, cv, sc, cx, co);
|
699
698
|
|
700
699
|
if ( rb_ca_is_scalar(vx) ) {
|
701
|
-
return rb_funcall(out0, rb_intern("[]"), 1,
|
700
|
+
return rb_funcall(out0, rb_intern("[]"), 1, INT2NUM(0));
|
702
701
|
}
|
703
702
|
else {
|
704
703
|
return out0;
|
@@ -713,7 +712,7 @@ rb_ca_differentiate (volatile VALUE self,
|
|
713
712
|
volatile VALUE out0, out;
|
714
713
|
CArray *ca, *cv, *sc, *cx, *co0, *co;
|
715
714
|
double *px, *po;
|
716
|
-
|
715
|
+
ca_size_t i;
|
717
716
|
|
718
717
|
Data_Get_Struct(self, CArray, ca);
|
719
718
|
|
@@ -769,7 +768,7 @@ rb_ca_differentiate (volatile VALUE self,
|
|
769
768
|
ca_detach_n(4, cv, sc, cx, co);
|
770
769
|
|
771
770
|
if ( rb_ca_is_scalar(vx) ) {
|
772
|
-
return rb_funcall(out0, rb_intern("[]"), 1,
|
771
|
+
return rb_funcall(out0, rb_intern("[]"), 1, INT2NUM(0));
|
773
772
|
}
|
774
773
|
else {
|
775
774
|
return out0;
|