carray 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +0 -1
  3. data/ca_iter_block.c +32 -30
  4. data/ca_iter_dimension.c +24 -22
  5. data/ca_iter_window.c +25 -23
  6. data/ca_obj_array.c +58 -56
  7. data/ca_obj_bitarray.c +27 -27
  8. data/ca_obj_bitfield.c +46 -45
  9. data/ca_obj_block.c +77 -72
  10. data/ca_obj_fake.c +20 -20
  11. data/ca_obj_farray.c +22 -22
  12. data/ca_obj_field.c +31 -30
  13. data/ca_obj_grid.c +63 -62
  14. data/ca_obj_mapping.c +35 -32
  15. data/ca_obj_object.c +54 -54
  16. data/ca_obj_reduce.c +13 -13
  17. data/ca_obj_refer.c +42 -39
  18. data/ca_obj_repeat.c +50 -47
  19. data/ca_obj_select.c +24 -24
  20. data/ca_obj_shift.c +61 -58
  21. data/ca_obj_transpose.c +52 -51
  22. data/ca_obj_unbound_repeat.c +28 -27
  23. data/ca_obj_window.c +77 -72
  24. data/carray.gemspec +0 -2
  25. data/carray.h +190 -163
  26. data/carray_access.c +137 -136
  27. data/carray_attribute.c +24 -13
  28. data/carray_call_cfunc.c +21 -21
  29. data/carray_cast.c +106 -110
  30. data/carray_cast_func.rb +17 -17
  31. data/carray_class.c +3 -3
  32. data/carray_conversion.c +15 -15
  33. data/carray_copy.c +27 -27
  34. data/carray_core.c +22 -21
  35. data/carray_element.c +55 -47
  36. data/carray_generate.c +32 -32
  37. data/carray_iterator.c +36 -35
  38. data/carray_loop.c +37 -37
  39. data/carray_mask.c +21 -21
  40. data/carray_math.rb +18 -18
  41. data/carray_numeric.c +1 -1
  42. data/carray_operator.c +19 -18
  43. data/carray_order.c +30 -30
  44. data/carray_random.c +34 -32
  45. data/carray_sort_addr.c +12 -12
  46. data/carray_stat.c +127 -127
  47. data/carray_stat_proc.rb +152 -141
  48. data/carray_test.c +16 -16
  49. data/carray_utils.c +58 -56
  50. data/ext/calculus/carray_calculus.c +19 -20
  51. data/ext/calculus/carray_interp.c +12 -11
  52. data/ext/fortio/lib/fortio/fortran_sequential.rb +2 -2
  53. data/ext/fortio/ruby_fortio.c +1 -1
  54. data/ext/imagemap/carray_imagemap.c +14 -14
  55. data/ext/narray/ca_wrap_narray.c +30 -21
  56. data/extconf.rb +5 -0
  57. data/lib/carray/base/basic.rb +4 -3
  58. data/lib/carray/base/serialize.rb +3 -3
  59. data/lib/carray/graphics/gnuplot.rb +10 -7
  60. data/lib/carray/io/csv.rb +14 -9
  61. data/lib/carray/io/imagemagick.rb +7 -0
  62. data/lib/carray/io/sqlite3.rb +6 -4
  63. data/mkmath.rb +20 -20
  64. data/ruby_carray.c +2 -0
  65. data/ruby_ccomplex.c +3 -3
  66. data/test/test_130.rb +23 -0
  67. data/test/test_ALL.rb +2 -1
  68. data/test/test_order.rb +3 -3
  69. data/test/test_stat.rb +2 -2
  70. data/version.h +4 -4
  71. metadata +4 -37
  72. data/examples/ex001.rb +0 -10
  73. data/examples/test-int.rb +0 -13
  74. data/lib/carray/autoload/autoload_io_excel.rb +0 -5
  75. data/lib/carray/io/excel.rb +0 -26
data/ca_obj_fake.c CHANGED
@@ -17,9 +17,9 @@ typedef struct {
17
17
  int8_t data_type;
18
18
  int8_t rank;
19
19
  int32_t flags;
20
- int32_t bytes;
21
- int32_t elements;
22
- int32_t *dim;
20
+ ca_size_t bytes;
21
+ ca_size_t elements;
22
+ ca_size_t *dim;
23
23
  char *ptr;
24
24
  CArray *mask;
25
25
  CArray *parent;
@@ -39,10 +39,10 @@ static VALUE rb_cCAFake;
39
39
  /* ------------------------------------------------------------------- */
40
40
 
41
41
  int
42
- ca_fake_setup (CAFake *ca, CArray *parent, int8_t data_type, int32_t bytes)
42
+ ca_fake_setup (CAFake *ca, CArray *parent, int8_t data_type, ca_size_t bytes)
43
43
  {
44
44
  int8_t rank;
45
- int32_t *dim, elements;
45
+ ca_size_t *dim, elements;
46
46
 
47
47
  /* check arguments */
48
48
 
@@ -61,13 +61,13 @@ ca_fake_setup (CAFake *ca, CArray *parent, int8_t data_type, int32_t bytes)
61
61
  ca->elements = elements;
62
62
  ca->ptr = NULL;
63
63
  ca->mask = NULL;
64
- ca->dim = ALLOC_N(int32_t, rank);
64
+ ca->dim = ALLOC_N(ca_size_t, rank);
65
65
 
66
66
  ca->parent = parent;
67
67
  ca->attach = 0;
68
68
  ca->nosync = 0;
69
69
 
70
- memcpy(ca->dim, dim, rank * sizeof(int32_t));
70
+ memcpy(ca->dim, dim, rank * sizeof(ca_size_t));
71
71
 
72
72
  if ( ca_has_mask(parent) ) {
73
73
  ca_create_mask(ca);
@@ -81,7 +81,7 @@ ca_fake_setup (CAFake *ca, CArray *parent, int8_t data_type, int32_t bytes)
81
81
  }
82
82
 
83
83
  CAFake *
84
- ca_fake_new (CArray *parent, int8_t data_type, int32_t bytes)
84
+ ca_fake_new (CArray *parent, int8_t data_type, ca_size_t bytes)
85
85
  {
86
86
  CAFake *ca = ALLOC(CAFake);
87
87
  ca_fake_setup(ca, parent, data_type, bytes);
@@ -110,21 +110,21 @@ ca_fake_func_clone (void *ap)
110
110
  }
111
111
 
112
112
  static char *
113
- ca_fake_func_ptr_at_addr (void *ap, int32_t addr)
113
+ ca_fake_func_ptr_at_addr (void *ap, ca_size_t addr)
114
114
  {
115
115
  CAFake *ca = (CAFake *) ap;
116
116
  return ca->ptr + ca->bytes * addr;
117
117
  }
118
118
 
119
119
  static char *
120
- ca_fake_func_ptr_at_index (void *ap, int32_t *idx)
120
+ ca_fake_func_ptr_at_index (void *ap, ca_size_t *idx)
121
121
  {
122
122
  CAFake *ca = (CAFake *) ap;
123
123
  return ca_func[CA_OBJ_ARRAY].ptr_at_index(ca, idx);
124
124
  }
125
125
 
126
126
  static void
127
- ca_fake_func_fetch_index (void *ap, int32_t *idx, void *ptr)
127
+ ca_fake_func_fetch_index (void *ap, ca_size_t *idx, void *ptr)
128
128
  {
129
129
  CAFake *ca = (CAFake *) ap;
130
130
  if ( ca->parent->bytes <= 32 ) {
@@ -141,7 +141,7 @@ ca_fake_func_fetch_index (void *ap, int32_t *idx, void *ptr)
141
141
  }
142
142
 
143
143
  static void
144
- ca_fake_func_store_index (void *ap, int32_t *idx, void *ptr)
144
+ ca_fake_func_store_index (void *ap, ca_size_t *idx, void *ptr)
145
145
  {
146
146
  CAFake *ca = (CAFake *) ap;
147
147
  if ( ca->parent->bytes <= 32 ) {
@@ -168,8 +168,8 @@ ca_fake_func_allocate (void *ap)
168
168
  /* initialize elements with 0 for CA_OBJECT data_type */
169
169
  if ( ca->data_type == CA_OBJECT ) {
170
170
  VALUE *p = (VALUE *) ca->ptr;
171
- VALUE zero = INT2FIX(0);
172
- int32_t i;
171
+ VALUE zero = SIZE2NUM(0);
172
+ ca_size_t i;
173
173
  for (i=0; i<ca->elements; i++) {
174
174
  *p++ = zero;
175
175
  }
@@ -189,8 +189,8 @@ ca_fake_func_attach (void *ap)
189
189
  /* initialize elements with 0 for CA_OBJECT data_type */
190
190
  if ( ca->data_type == CA_OBJECT ) {
191
191
  VALUE *p = (VALUE *) ca->ptr;
192
- VALUE zero = INT2FIX(0);
193
- int32_t i;
192
+ VALUE zero = SIZE2NUM(0);
193
+ ca_size_t i;
194
194
  for (i=0; i<ca->elements; i++) {
195
195
  *p++ = zero;
196
196
  }
@@ -315,7 +315,7 @@ ca_operation_function_t ca_fake_func = {
315
315
  /* ------------------------------------------------------------------- */
316
316
 
317
317
  VALUE
318
- rb_ca_fake_new (VALUE cary, int8_t data_type, int32_t bytes)
318
+ rb_ca_fake_new (VALUE cary, int8_t data_type, ca_size_t bytes)
319
319
  {
320
320
  volatile VALUE obj;
321
321
  CArray *parent;
@@ -341,11 +341,11 @@ rb_ca_fake (int argc, VALUE *argv, VALUE self)
341
341
  volatile VALUE obj, rtype, ropt, rbytes = Qnil;
342
342
  CArray *ca;
343
343
  int8_t data_type;
344
- int32_t bytes;
344
+ ca_size_t bytes;
345
345
 
346
346
  Data_Get_Struct(self, CArray, ca);
347
347
 
348
- rb_scan_args(argc, argv, "11", &rtype, &ropt);
348
+ rb_scan_args(argc, argv, "11", (VALUE *) &rtype, (VALUE *) &ropt);
349
349
  rb_scan_options(ropt, "bytes", &rbytes);
350
350
 
351
351
  rb_ca_guess_type_and_bytes(rtype, rbytes, &data_type, &bytes);
@@ -360,7 +360,7 @@ rb_ca_fake_type (VALUE self, VALUE rtype, VALUE rbytes)
360
360
  {
361
361
  volatile VALUE obj;
362
362
  int8_t data_type;
363
- int32_t bytes;
363
+ ca_size_t bytes;
364
364
  rb_ca_guess_type_and_bytes(rtype, rbytes, &data_type, &bytes);
365
365
  obj = rb_ca_fake_new(self, data_type, bytes);
366
366
  rb_ca_data_type_import(obj, rtype);
data/ca_obj_farray.c CHANGED
@@ -17,16 +17,16 @@ typedef struct {
17
17
  int8_t data_type;
18
18
  int8_t rank;
19
19
  int32_t flags;
20
- int32_t bytes;
21
- int32_t elements;
22
- int32_t *dim;
20
+ ca_size_t bytes;
21
+ ca_size_t elements;
22
+ ca_size_t *dim;
23
23
  char *ptr;
24
24
  CArray *mask;
25
25
  CArray *parent;
26
26
  uint32_t attach;
27
27
  uint8_t nosync;
28
28
  /* --------------- */
29
- int32_t step;
29
+ ca_size_t step;
30
30
  } CAFarray;
31
31
 
32
32
  static int8_t CA_OBJ_FARRAY;
@@ -44,7 +44,7 @@ int
44
44
  ca_farray_setup (CAFarray *ca, CArray *parent)
45
45
  {
46
46
  int8_t rank, data_type;
47
- int32_t *dim, elements, bytes;
47
+ ca_size_t *dim, elements, bytes;
48
48
  int i;
49
49
 
50
50
  /* check arguments */
@@ -63,7 +63,7 @@ ca_farray_setup (CAFarray *ca, CArray *parent)
63
63
  ca->elements = elements;
64
64
  ca->ptr = NULL;
65
65
  ca->mask = NULL;
66
- ca->dim = ALLOC_N(int32_t, rank);
66
+ ca->dim = ALLOC_N(ca_size_t, rank);
67
67
 
68
68
  ca->parent = parent;
69
69
  ca->attach = 0;
@@ -121,11 +121,11 @@ ca_farray_func_clone (void *ap)
121
121
  #define ca_farray_func_ptr_at_index ca_array_func_ptr_at_index
122
122
 
123
123
  static void
124
- ca_farray_func_fetch_index (void *ap, int32_t *idx, void *ptr)
124
+ ca_farray_func_fetch_index (void *ap, ca_size_t *idx, void *ptr)
125
125
  {
126
126
  CAFarray *ca = (CAFarray *) ap;
127
127
  int8_t rank = ca->rank;
128
- int32_t idx0[CA_RANK_MAX];
128
+ ca_size_t idx0[CA_RANK_MAX];
129
129
  int i;
130
130
  for (i=0; i<rank; i++) {
131
131
  idx0[i] = idx[rank-1-i];
@@ -134,11 +134,11 @@ ca_farray_func_fetch_index (void *ap, int32_t *idx, void *ptr)
134
134
  }
135
135
 
136
136
  static void
137
- ca_farray_func_store_index (void *ap, int32_t *idx, void *ptr)
137
+ ca_farray_func_store_index (void *ap, ca_size_t *idx, void *ptr)
138
138
  {
139
139
  CAFarray *ca = (CAFarray *) ap;
140
140
  int8_t rank = ca->rank;
141
- int32_t idx0[CA_RANK_MAX];
141
+ ca_size_t idx0[CA_RANK_MAX];
142
142
  int i;
143
143
  for (i=0; i<rank; i++) {
144
144
  idx0[i] = idx[rank-1-i];
@@ -253,11 +253,11 @@ ca_operation_function_t ca_farray_func = {
253
253
 
254
254
 
255
255
  static void
256
- ca_fa_attach_loop (CAFarray *ca, int8_t level, int32_t *idx, int32_t *idx0)
256
+ ca_fa_attach_loop (CAFarray *ca, int8_t level, ca_size_t *idx, ca_size_t *idx0)
257
257
  {
258
- int32_t step = ca->step;
259
- int32_t dim = ca->dim[level];
260
- int32_t i;
258
+ ca_size_t step = ca->step;
259
+ ca_size_t dim = ca->dim[level];
260
+ ca_size_t i;
261
261
  if ( level == ca->rank - 1 ) {
262
262
  idx[level] = 0;
263
263
  idx0[0] = 0;
@@ -327,17 +327,17 @@ ca_fa_attach_loop (CAFarray *ca, int8_t level, int32_t *idx, int32_t *idx0)
327
327
  static void
328
328
  ca_fa_attach (CAFarray *ca)
329
329
  {
330
- int32_t idx[CA_RANK_MAX];
331
- int32_t idx0[CA_RANK_MAX];
330
+ ca_size_t idx[CA_RANK_MAX];
331
+ ca_size_t idx0[CA_RANK_MAX];
332
332
  ca_fa_attach_loop(ca, 0, idx, idx0);
333
333
  }
334
334
 
335
335
  static void
336
- ca_fa_sync_loop (CAFarray *ca, int8_t level, int32_t *idx, int32_t *idx0)
336
+ ca_fa_sync_loop (CAFarray *ca, int8_t level, ca_size_t *idx, ca_size_t *idx0)
337
337
  {
338
- int32_t step = ca->step;
339
- int32_t dim = ca->dim[level];
340
- int32_t i;
338
+ ca_size_t step = ca->step;
339
+ ca_size_t dim = ca->dim[level];
340
+ ca_size_t i;
341
341
 
342
342
  if ( level == ca->rank - 1 ) {
343
343
  idx[level] = 0;
@@ -407,8 +407,8 @@ ca_fa_sync_loop (CAFarray *ca, int8_t level, int32_t *idx, int32_t *idx0)
407
407
  static void
408
408
  ca_fa_sync (CAFarray *ca)
409
409
  {
410
- int32_t idx[CA_RANK_MAX];
411
- int32_t idx0[CA_RANK_MAX];
410
+ ca_size_t idx[CA_RANK_MAX];
411
+ ca_size_t idx0[CA_RANK_MAX];
412
412
  ca_fa_sync_loop(ca, 0, idx, idx0);
413
413
  }
414
414
 
data/ca_obj_field.c CHANGED
@@ -17,16 +17,16 @@ typedef struct {
17
17
  int8_t data_type;
18
18
  int8_t rank;
19
19
  int32_t flags;
20
- int32_t bytes;
21
- int32_t elements;
22
- int32_t *dim;
20
+ ca_size_t bytes;
21
+ ca_size_t elements;
22
+ ca_size_t *dim;
23
23
  char *ptr;
24
24
  CArray *mask;
25
25
  CArray *parent;
26
26
  uint32_t attach;
27
27
  uint8_t nosync;
28
28
  /* -------------*/
29
- int32_t offset;
29
+ ca_size_t offset;
30
30
  } CAField;
31
31
 
32
32
  static int8_t CA_OBJ_FIELD;
@@ -42,10 +42,10 @@ static VALUE rb_cCAField;
42
42
 
43
43
  int
44
44
  ca_field_setup (CAField *ca, CArray *parent,
45
- int32_t offset, int8_t data_type, int32_t bytes)
45
+ ca_size_t offset, int8_t data_type, ca_size_t bytes)
46
46
  {
47
47
  int8_t rank;
48
- int32_t elements;
48
+ ca_size_t elements;
49
49
 
50
50
  /* check arguments */
51
51
 
@@ -75,14 +75,14 @@ ca_field_setup (CAField *ca, CArray *parent,
75
75
  ca->elements = elements;
76
76
  ca->ptr = NULL;
77
77
  ca->mask = NULL;
78
- ca->dim = ALLOC_N(int32_t, rank);
78
+ ca->dim = ALLOC_N(ca_size_t, rank);
79
79
 
80
80
  ca->parent = parent;
81
81
  ca->attach = 0;
82
82
  ca->nosync = 0;
83
83
  ca->offset = offset;
84
84
 
85
- memcpy(ca->dim, parent->dim, rank * sizeof(int32_t));
85
+ memcpy(ca->dim, parent->dim, rank * sizeof(ca_size_t));
86
86
 
87
87
  if ( ca_has_mask(parent) ) {
88
88
  ca_create_mask(ca);
@@ -96,7 +96,7 @@ ca_field_setup (CAField *ca, CArray *parent,
96
96
  }
97
97
 
98
98
  CAField *
99
- ca_field_new (CArray *parent, int32_t offset, int8_t data_type, int32_t bytes)
99
+ ca_field_new (CArray *parent, ca_size_t offset, int8_t data_type, ca_size_t bytes)
100
100
  {
101
101
  CAField *ca = ALLOC(CAField);
102
102
  ca_field_setup(ca, parent, offset, data_type, bytes);
@@ -128,11 +128,11 @@ ca_field_func_clone (void *ap)
128
128
  }
129
129
 
130
130
  static char *
131
- ca_field_func_ptr_at_addr (void *ap, int32_t addr)
131
+ ca_field_func_ptr_at_addr (void *ap, ca_size_t addr)
132
132
  {
133
133
  CAField *ca = (CAField *) ap;
134
134
  if ( ! ca->ptr ) {
135
- int32_t idx[CA_RANK_MAX];
135
+ ca_size_t idx[CA_RANK_MAX];
136
136
  ca_addr2index((CArray *)ca, addr, idx);
137
137
  return ca_ptr_at_index(ca, idx);
138
138
  }
@@ -142,12 +142,13 @@ ca_field_func_ptr_at_addr (void *ap, int32_t addr)
142
142
  }
143
143
 
144
144
  static char *
145
- ca_field_func_ptr_at_index (void *ap, int32_t *idx)
145
+ ca_field_func_ptr_at_index (void *ap, ca_size_t *idx)
146
146
  {
147
147
  CAField *ca = (CAField *) ap;
148
148
  if ( ! ca->ptr ) {
149
- int32_t *dim = ca->dim;
150
- int32_t i, n;
149
+ ca_size_t *dim = ca->dim;
150
+ int8_t i;
151
+ ca_size_t n;
151
152
  n = idx[0]; /* n = idx[0]*dim[1]*dim[2]*...*dim[rank-1] */
152
153
  for (i=1; i<ca->rank; i++) { /* + idx[1]*dim[1]*dim[2]*...*dim[rank-1] */
153
154
  n = dim[i]*n+idx[i]; /* ... + idx[rank-2]*dim[1] + idx[rank-1] */
@@ -166,7 +167,7 @@ ca_field_func_ptr_at_index (void *ap, int32_t *idx)
166
167
  }
167
168
 
168
169
  static void
169
- ca_field_func_fetch_index (void *ap, int32_t *idx, void *ptr)
170
+ ca_field_func_fetch_index (void *ap, ca_size_t *idx, void *ptr)
170
171
  {
171
172
  CAField *ca = (CAField *) ap;
172
173
  if ( ca->parent->bytes <= 32 ) {
@@ -183,7 +184,7 @@ ca_field_func_fetch_index (void *ap, int32_t *idx, void *ptr)
183
184
  }
184
185
 
185
186
  static void
186
- ca_field_func_store_index (void *ap, int32_t *idx, void *ptr)
187
+ ca_field_func_store_index (void *ap, ca_size_t *idx, void *ptr)
187
188
  {
188
189
  CAField *ca = (CAField *) ap;
189
190
  if ( ca->parent->bytes <= 32 ) {
@@ -313,9 +314,9 @@ ca_operation_function_t ca_field_func = {
313
314
  static void
314
315
  ca_field_attach (CAField *ca)
315
316
  {
316
- int32_t pbytes = ca->parent->bytes;
317
- int32_t bytes = ca->bytes;
318
- int32_t n = ca->elements;
317
+ ca_size_t pbytes = ca->parent->bytes;
318
+ ca_size_t bytes = ca->bytes;
319
+ ca_size_t n = ca->elements;
319
320
 
320
321
  switch ( ca->data_type ) {
321
322
  case CA_BOOLEAN:
@@ -380,9 +381,9 @@ ca_field_attach (CAField *ca)
380
381
  static void
381
382
  ca_field_sync (CAField *ca)
382
383
  {
383
- int32_t pbytes = ca->parent->bytes;
384
- int32_t bytes = ca->bytes;
385
- int32_t n = ca->elements;
384
+ ca_size_t pbytes = ca->parent->bytes;
385
+ ca_size_t bytes = ca->bytes;
386
+ ca_size_t n = ca->elements;
386
387
 
387
388
  switch ( ca->data_type ) {
388
389
  case CA_BOOLEAN:
@@ -447,8 +448,8 @@ ca_field_sync (CAField *ca)
447
448
  static void
448
449
  ca_field_fill (CAField *ca, char *ptr)
449
450
  {
450
- int32_t pbytes = ca->parent->bytes;
451
- int32_t n = ca->elements;
451
+ ca_size_t pbytes = ca->parent->bytes;
452
+ ca_size_t n = ca->elements;
452
453
  char *q = ca_ptr_at_addr(ca->parent, 0) + ca->offset;
453
454
 
454
455
  switch ( ca->data_type ) {
@@ -509,7 +510,7 @@ ca_field_fill (CAField *ca, char *ptr)
509
510
  /* ------------------------------------------------------------------- */
510
511
 
511
512
  VALUE
512
- rb_ca_field_new (VALUE cary, int32_t offset, int8_t data_type, int32_t bytes)
513
+ rb_ca_field_new (VALUE cary, ca_size_t offset, int8_t data_type, ca_size_t bytes)
513
514
  {
514
515
  volatile VALUE obj;
515
516
  CArray *parent;
@@ -562,7 +563,7 @@ rb_ca_field (int argc, VALUE *argv, VALUE self)
562
563
  volatile VALUE obj, voffset, rtype, ropt, rbytes = Qnil;
563
564
  CArray *ca;
564
565
  int8_t data_type;
565
- int32_t offset, bytes;
566
+ ca_size_t offset, bytes;
566
567
 
567
568
  if ( argc == 1 ) {
568
569
  return rb_ca_field_as_member(self, argv[0]);
@@ -574,16 +575,16 @@ rb_ca_field (int argc, VALUE *argv, VALUE self)
574
575
  /* CArray#field(offset, data_class) */
575
576
  /* CArray#field(offset, template) */
576
577
 
577
- rb_scan_args(argc, argv, "21", &voffset, &rtype, &ropt);
578
+ rb_scan_args(argc, argv, "21", (VALUE *) &voffset, (VALUE *) &rtype, (VALUE *) &ropt);
578
579
  rb_scan_options(ropt, "bytes", &rbytes);
579
580
 
580
- offset = NUM2INT(voffset);
581
+ offset = NUM2SIZE(voffset);
581
582
 
582
583
  if ( rb_obj_is_carray(rtype) ) {
583
584
  CArray *ct;
584
- int32_t dim[CA_RANK_MAX];
585
+ ca_size_t dim[CA_RANK_MAX];
585
586
  int8_t rank;
586
- int i, j;
587
+ int8_t i, j;
587
588
  Data_Get_Struct(rtype, CArray, ct);
588
589
  data_type = CA_FIXLEN;
589
590
  bytes = ct->bytes * ct->elements;
data/ca_obj_grid.c CHANGED
@@ -17,9 +17,9 @@ typedef struct {
17
17
  int8_t data_type;
18
18
  int8_t rank;
19
19
  int32_t flags;
20
- int32_t bytes;
21
- int32_t elements;
22
- int32_t *dim;
20
+ ca_size_t bytes;
21
+ ca_size_t elements;
22
+ ca_size_t *dim;
23
23
  char *ptr;
24
24
  CArray *mask;
25
25
  CArray *parent;
@@ -40,12 +40,12 @@ static VALUE rb_cCAGrid;
40
40
  static int8_t CA_OBJ_GRID;
41
41
 
42
42
  int
43
- ca_grid_setup (CAGrid *ca, CArray *parent, int32_t *dim,
43
+ ca_grid_setup (CAGrid *ca, CArray *parent, ca_size_t *dim,
44
44
  CArray **grid, int8_t *contig, int share)
45
45
  {
46
46
  int8_t rank, data_type;
47
- int32_t *dim0;
48
- int32_t elements, bytes;
47
+ ca_size_t *dim0;
48
+ ca_size_t elements, bytes;
49
49
  double length;
50
50
  int i, j, k;
51
51
 
@@ -76,7 +76,7 @@ ca_grid_setup (CAGrid *ca, CArray *parent, int32_t *dim,
76
76
  ca->elements = elements;
77
77
  ca->ptr = NULL;
78
78
  ca->mask = NULL;
79
- ca->dim = ALLOC_N(int32_t, rank);
79
+ ca->dim = ALLOC_N(ca_size_t, rank);
80
80
 
81
81
  ca->parent = parent;
82
82
  ca->attach = 0;
@@ -92,23 +92,23 @@ ca_grid_setup (CAGrid *ca, CArray *parent, int32_t *dim,
92
92
  ca->contig = ALLOC_N(int8_t, rank);
93
93
  }
94
94
 
95
- memcpy(ca->dim, dim, rank * sizeof(int32_t));
95
+ memcpy(ca->dim, dim, rank * sizeof(ca_size_t));
96
96
 
97
97
  if ( ! share ) {
98
98
  for (i=0; i<rank; i++) {
99
99
  if ( grid[i] ) {
100
100
  if ( ca_is_any_masked(grid[i]) ) {
101
- int32_t gsize = grid[i]->elements - ca_count_masked(grid[i]);
101
+ ca_size_t gsize = grid[i]->elements - ca_count_masked(grid[i]);
102
102
  boolean8_t *m;
103
- int32_t n;
104
- ca->grid[i] = carray_new(CA_INT32, 1, &gsize, 0, NULL);
103
+ ca_size_t n;
104
+ ca->grid[i] = carray_new(CA_SIZE, 1, &gsize, 0, NULL);
105
105
  m = (boolean8_t *)grid[i]->mask->ptr;
106
106
  n = 0;
107
107
  for (j=0; j<grid[i]->elements; j++) {
108
108
  if ( ! *m ) {
109
- k = ((int32_t*)grid[i]->ptr)[j];
109
+ k = ((ca_size_t*)grid[i]->ptr)[j];
110
110
  CA_CHECK_INDEX(k, dim0[i]);
111
- ((int32_t*)ca->grid[i]->ptr)[n] = k;
111
+ ((ca_size_t*)ca->grid[i]->ptr)[n] = k;
112
112
  n++;
113
113
  }
114
114
  m++;
@@ -118,17 +118,17 @@ ca_grid_setup (CAGrid *ca, CArray *parent, int32_t *dim,
118
118
  else {
119
119
  ca->grid[i] = ca_template(grid[i]);
120
120
  for (j=0; j<grid[i]->elements; j++) {
121
- k = ((int32_t*)grid[i]->ptr)[j];
121
+ k = ((ca_size_t*)grid[i]->ptr)[j];
122
122
  CA_CHECK_INDEX(k, dim0[i]);
123
- ((int32_t*)ca->grid[i]->ptr)[j] = k;
123
+ ((ca_size_t*)ca->grid[i]->ptr)[j] = k;
124
124
  }
125
125
  ca->contig[i] = 0;
126
126
  }
127
127
  }
128
128
  else {
129
- int32_t *p;
130
- ca->grid[i] = carray_new(CA_INT32, 1, &dim[i], 0, NULL);
131
- p = (int32_t *)ca->grid[i]->ptr;
129
+ ca_size_t *p;
130
+ ca->grid[i] = carray_new(CA_SIZE, 1, &dim[i], 0, NULL);
131
+ p = (ca_size_t *)ca->grid[i]->ptr;
132
132
  for (j=0; j<dim[i]; j++) {
133
133
  *p++ = j;
134
134
  }
@@ -145,7 +145,7 @@ ca_grid_setup (CAGrid *ca, CArray *parent, int32_t *dim,
145
145
  }
146
146
 
147
147
  CAGrid *
148
- ca_grid_new (CArray *parent, int32_t *dim, CArray **grid)
148
+ ca_grid_new (CArray *parent, ca_size_t *dim, CArray **grid)
149
149
  {
150
150
  CAGrid *ca = ALLOC(CAGrid);
151
151
  ca_grid_setup(ca, parent, dim, grid, NULL, 0);
@@ -153,7 +153,7 @@ ca_grid_new (CArray *parent, int32_t *dim, CArray **grid)
153
153
  }
154
154
 
155
155
  CAGrid *
156
- ca_grid_new_share (CArray *parent, int32_t *dim, CArray **grid, int8_t *contig)
156
+ ca_grid_new_share (CArray *parent, ca_size_t *dim, CArray **grid, int8_t *contig)
157
157
  {
158
158
  CAGrid *ca = ALLOC(CAGrid);
159
159
  ca_grid_setup(ca, parent, dim, grid, contig, 1);
@@ -164,7 +164,7 @@ static void
164
164
  free_ca_grid (void *ap)
165
165
  {
166
166
  CAGrid *ca = (CAGrid *) ap;
167
- int32_t i;
167
+ ca_size_t i;
168
168
  if ( ca != NULL ) {
169
169
  ca_free(ca->mask);
170
170
  if ( ! (ca->flags & CA_FLAG_SHARE_INDEX)) {
@@ -193,11 +193,11 @@ ca_grid_func_clone (void *ap)
193
193
  }
194
194
 
195
195
  static char *
196
- ca_grid_func_ptr_at_addr (void *ap, int32_t addr)
196
+ ca_grid_func_ptr_at_addr (void *ap, ca_size_t addr)
197
197
  {
198
198
  CAGrid *ca = (CAGrid *) ap;
199
199
  if ( ! ca->ptr ) {
200
- int32_t idx[CA_RANK_MAX];
200
+ ca_size_t idx[CA_RANK_MAX];
201
201
  ca_addr2index((CArray *)ca, addr, idx);
202
202
  return ca_ptr_at_index(ca, idx);
203
203
  }
@@ -207,17 +207,18 @@ ca_grid_func_ptr_at_addr (void *ap, int32_t addr)
207
207
  }
208
208
 
209
209
  static char *
210
- ca_grid_func_ptr_at_index (void *ap, int32_t *idx)
210
+ ca_grid_func_ptr_at_index (void *ap, ca_size_t *idx)
211
211
  {
212
212
  CAGrid *ca = (CAGrid *) ap;
213
213
  if ( ! ca->ptr ) {
214
214
  CArray **grid = ca->grid;
215
- int32_t *dim0 = ca->parent->dim;
216
- int32_t n, i;
215
+ ca_size_t *dim0 = ca->parent->dim;
216
+ int8_t i;
217
+ ca_size_t n;
217
218
 
218
219
  n = 0;
219
220
  for (i=0; i<ca->rank; i++) {
220
- n = dim0[i]*n + *(int32_t*) ca_ptr_at_addr(grid[i], idx[i]);
221
+ n = dim0[i]*n + *(ca_size_t*) ca_ptr_at_addr(grid[i], idx[i]);
221
222
  }
222
223
 
223
224
  if ( ca->parent->ptr == NULL ) {
@@ -233,12 +234,12 @@ ca_grid_func_ptr_at_index (void *ap, int32_t *idx)
233
234
  }
234
235
 
235
236
  static void
236
- ca_grid_func_fetch_index (void *ap, int32_t *idx, void *ptr)
237
+ ca_grid_func_fetch_index (void *ap, ca_size_t *idx, void *ptr)
237
238
  {
238
239
  CAGrid *ca = (CAGrid *) ap;
239
240
  CArray **grid = ca->grid;
240
- int32_t idx0[CA_RANK_MAX];
241
- int32_t i;
241
+ ca_size_t idx0[CA_RANK_MAX];
242
+ int8_t i;
242
243
  for (i=0; i<ca->rank; i++) {
243
244
  ca_fetch_addr(grid[i], idx[i], &idx0[i]);
244
245
  }
@@ -246,12 +247,12 @@ ca_grid_func_fetch_index (void *ap, int32_t *idx, void *ptr)
246
247
  }
247
248
 
248
249
  static void
249
- ca_grid_func_store_index (void *ap, int32_t *idx, void *ptr)
250
+ ca_grid_func_store_index (void *ap, ca_size_t *idx, void *ptr)
250
251
  {
251
252
  CAGrid *ca = (CAGrid *) ap;
252
253
  CArray **grid = ca->grid;
253
- int32_t idx0[CA_RANK_MAX];
254
- int32_t i;
254
+ ca_size_t idx0[CA_RANK_MAX];
255
+ int8_t i;
255
256
  for (i=0; i<ca->rank; i++) {
256
257
  ca_fetch_addr(grid[i], idx[i], &idx0[i]);
257
258
  }
@@ -370,7 +371,7 @@ ca_operation_function_t ca_grid_func = {
370
371
 
371
372
  #define proc_grid_attach(type) \
372
373
  { \
373
- int32_t *pi = (int32_t*) ca_ptr_at_addr(grid[level], 0); \
374
+ ca_size_t *pi = (ca_size_t*) ca_ptr_at_addr(grid[level], 0); \
374
375
  type *p = (type*) ca_ptr_at_index(ca, idx); \
375
376
  type *q = (type*) ca_ptr_at_index(ca->parent, idx0); \
376
377
  for (i=0; i<ca->dim[level]; i++, pi++, p++) { \
@@ -380,10 +381,10 @@ ca_operation_function_t ca_grid_func = {
380
381
  }
381
382
 
382
383
  static void
383
- ca_grid_attach_loop (CAGrid *ca, int16_t level, int32_t *idx, int32_t *idx0)
384
+ ca_grid_attach_loop (CAGrid *ca, int16_t level, ca_size_t *idx, ca_size_t *idx0)
384
385
  {
385
386
  CArray **grid = ca->grid;
386
- int32_t i, k;
387
+ ca_size_t i, k;
387
388
 
388
389
  if ( level == ca->rank - 1 ) {
389
390
  idx[level] = 0;
@@ -400,7 +401,7 @@ ca_grid_attach_loop (CAGrid *ca, int16_t level, int32_t *idx, int32_t *idx0)
400
401
  case 8: proc_grid_attach(float64_t); break;
401
402
  default:
402
403
  {
403
- int32_t *pi = (int32_t*) ca_ptr_at_addr(grid[level], 0);
404
+ ca_size_t *pi = (ca_size_t*) ca_ptr_at_addr(grid[level], 0);
404
405
  char *p = ca_ptr_at_index(ca, idx);
405
406
  char *q;
406
407
  idx0[level] = 0;
@@ -422,8 +423,8 @@ ca_grid_attach_loop (CAGrid *ca, int16_t level, int32_t *idx, int32_t *idx0)
422
423
  }
423
424
  }
424
425
  else {
425
- int32_t *pi;
426
- pi = (int32_t*) ca_ptr_at_addr(grid[level], 0);
426
+ ca_size_t *pi;
427
+ pi = (ca_size_t*) ca_ptr_at_addr(grid[level], 0);
427
428
  for (i=0; i<ca->dim[level]; i++, pi++) {
428
429
  k = *pi;
429
430
  idx[level] = i;
@@ -437,14 +438,14 @@ ca_grid_attach_loop (CAGrid *ca, int16_t level, int32_t *idx, int32_t *idx0)
437
438
  static void
438
439
  ca_grid_attach (CAGrid *ca)
439
440
  {
440
- int32_t idx[CA_RANK_MAX];
441
- int32_t idx0[CA_RANK_MAX];
441
+ ca_size_t idx[CA_RANK_MAX];
442
+ ca_size_t idx0[CA_RANK_MAX];
442
443
  ca_grid_attach_loop(ca, (int16_t) 0, idx, idx0);
443
444
  }
444
445
 
445
446
  #define proc_grid_sync(type) \
446
447
  { \
447
- int32_t *pi = (int32_t*) ca_ptr_at_addr(grid[level], 0); \
448
+ ca_size_t *pi = (ca_size_t*) ca_ptr_at_addr(grid[level], 0); \
448
449
  type *p = (type*) ca_ptr_at_index(ca, idx); \
449
450
  type *q = (type*) ca_ptr_at_index(ca->parent, idx0); \
450
451
  for (i=0; i<ca->dim[level]; i++, pi++, p++) { \
@@ -454,10 +455,10 @@ ca_grid_attach (CAGrid *ca)
454
455
  }
455
456
 
456
457
  static void
457
- ca_grid_sync_loop (CAGrid *ca, int16_t level, int32_t *idx, int32_t *idx0)
458
+ ca_grid_sync_loop (CAGrid *ca, int16_t level, ca_size_t *idx, ca_size_t *idx0)
458
459
  {
459
460
  CArray **grid = ca->grid;
460
- int32_t i, k;
461
+ ca_size_t i, k;
461
462
 
462
463
  if ( level == ca->rank - 1 ) {
463
464
  idx[level] = 0;
@@ -474,7 +475,7 @@ ca_grid_sync_loop (CAGrid *ca, int16_t level, int32_t *idx, int32_t *idx0)
474
475
  case 8: proc_grid_sync(float64_t); break;
475
476
  default:
476
477
  {
477
- int32_t *pi = (int32_t*) ca_ptr_at_addr(grid[level], 0);
478
+ ca_size_t *pi = (ca_size_t*) ca_ptr_at_addr(grid[level], 0);
478
479
  char *p = ca_ptr_at_index(ca, idx);
479
480
  char *q;
480
481
  idx0[level] = 0;
@@ -497,7 +498,7 @@ ca_grid_sync_loop (CAGrid *ca, int16_t level, int32_t *idx, int32_t *idx0)
497
498
  }
498
499
  else {
499
500
  for (i=0; i<ca->dim[level]; i++) {
500
- k = *(int32_t*) ca_ptr_at_addr(grid[level], i);
501
+ k = *(ca_size_t*) ca_ptr_at_addr(grid[level], i);
501
502
  idx[level] = i;
502
503
  idx0[level] = k;
503
504
  ca_grid_sync_loop(ca, level+1, idx, idx0);
@@ -509,14 +510,14 @@ ca_grid_sync_loop (CAGrid *ca, int16_t level, int32_t *idx, int32_t *idx0)
509
510
  static void
510
511
  ca_grid_sync (CAGrid *ca)
511
512
  {
512
- int32_t idx[CA_RANK_MAX];
513
- int32_t idx0[CA_RANK_MAX];
513
+ ca_size_t idx[CA_RANK_MAX];
514
+ ca_size_t idx0[CA_RANK_MAX];
514
515
  ca_grid_sync_loop(ca, (int16_t) 0, idx, idx0);
515
516
  }
516
517
 
517
518
  #define proc_grid_fill(type) \
518
519
  { \
519
- int32_t *pi = (int32_t*) ca_ptr_at_addr(grid[level], 0); \
520
+ ca_size_t *pi = (ca_size_t*) ca_ptr_at_addr(grid[level], 0); \
520
521
  type fval = *(type*)ptr; \
521
522
  type *q = (type*) ca_ptr_at_index(ca->parent, idx0); \
522
523
  for (i=0; i<ca->dim[level]; i++, pi++) { \
@@ -527,10 +528,10 @@ ca_grid_sync (CAGrid *ca)
527
528
 
528
529
  static void
529
530
  ca_grid_fill_loop (CAGrid *ca, char *ptr,
530
- int16_t level, int32_t *idx0)
531
+ int16_t level, ca_size_t *idx0)
531
532
  {
532
533
  CArray **grid = ca->grid;
533
- int32_t i, k;
534
+ ca_size_t i, k;
534
535
  if ( level == ca->rank - 1 ) {
535
536
  idx0[level] = 0;
536
537
  if ( ca->contig[level] ) {
@@ -548,7 +549,7 @@ ca_grid_fill_loop (CAGrid *ca, char *ptr,
548
549
  case 8: proc_grid_fill(float64_t); break;
549
550
  default:
550
551
  {
551
- int32_t *pi = (int32_t*) ca_ptr_at_addr(grid[level], 0);
552
+ ca_size_t *pi = (ca_size_t*) ca_ptr_at_addr(grid[level], 0);
552
553
  char *q;
553
554
  idx0[level] = 0;
554
555
  q = ca_ptr_at_index(ca->parent, idx0);
@@ -569,7 +570,7 @@ ca_grid_fill_loop (CAGrid *ca, char *ptr,
569
570
  }
570
571
  else {
571
572
  for (i=0; i<ca->dim[level]; i++) {
572
- k = *(int32_t*) ca_ptr_at_addr(grid[level], i);
573
+ k = *(ca_size_t*) ca_ptr_at_addr(grid[level], i);
573
574
  idx0[level] = k;
574
575
  ca_grid_fill_loop(ca, ptr, level+1, idx0);
575
576
  }
@@ -580,14 +581,14 @@ ca_grid_fill_loop (CAGrid *ca, char *ptr,
580
581
  static void
581
582
  ca_grid_fill (CAGrid *ca, char *ptr)
582
583
  {
583
- int32_t idx0[CA_RANK_MAX];
584
+ ca_size_t idx0[CA_RANK_MAX];
584
585
  ca_grid_fill_loop(ca, ptr, (int16_t) 0, idx0);
585
586
  }
586
587
 
587
588
  /* ------------------------------------------------------------------- */
588
589
 
589
590
  VALUE
590
- rb_ca_grid_new (VALUE cary, int32_t *dim, CArray **grid)
591
+ rb_ca_grid_new (VALUE cary, ca_size_t *dim, CArray **grid)
591
592
  {
592
593
  volatile VALUE obj;
593
594
  CArray *parent;
@@ -615,9 +616,9 @@ rb_ca_grid (int argc, VALUE *argv, VALUE self)
615
616
  volatile VALUE list = rb_ary_new();
616
617
  CArray *ca;
617
618
  CArray *ci[CA_RANK_MAX];
618
- int32_t dim[CA_RANK_MAX];
619
+ ca_size_t dim[CA_RANK_MAX];
619
620
  CArray *grid[CA_RANK_MAX];
620
- int32_t i;
621
+ ca_size_t i;
621
622
 
622
623
  Data_Get_Struct(self, CArray, ca);
623
624
 
@@ -629,9 +630,9 @@ rb_ca_grid (int argc, VALUE *argv, VALUE self)
629
630
  else if ( RARRAY_LEN(ridx) < ca->rank ) {
630
631
  volatile VALUE ref;
631
632
  CArray *cv;
632
- int32_t rdim[CA_RANK_MAX];
633
- int32_t rrank = RARRAY_LEN(ridx);
634
- int32_t j = 0, k;
633
+ ca_size_t rdim[CA_RANK_MAX];
634
+ ca_size_t rrank = RARRAY_LEN(ridx);
635
+ ca_size_t j = 0, k;
635
636
  for (i=0; i<rrank; i++) {
636
637
  rval = rb_ary_entry(ridx, i);
637
638
  if ( rb_obj_is_carray(rval) ) {
@@ -668,12 +669,12 @@ rb_ca_grid (int argc, VALUE *argv, VALUE self)
668
669
  }
669
670
  }
670
671
  else if ( rb_obj_is_kind_of(rval, rb_cRange) ) {
671
- rval = rb_funcall(rb_mKernel, rb_intern("CA_INT32"), 1, rval);
672
+ rval = rb_funcall(rb_mKernel, rb_intern("CA_SIZE"), 1, rval);
672
673
  }
673
674
  else if ( TYPE(rval) == T_ARRAY ) {
674
675
  rb_raise(rb_eRuntimeError, "not implemented for this index");
675
676
  }
676
- ci[i] = ca_wrap_readonly(rval, CA_INT32);
677
+ ci[i] = ca_wrap_readonly(rval, CA_SIZE);
677
678
  rb_ary_push(list, rval);
678
679
  ca_attach(ci[i]);
679
680