carray 1.3.5 → 1.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSES +22 -0
- data/README.md +18 -21
- data/Rakefile +31 -0
- data/carray.gemspec +13 -26
- data/{ca_iter_block.c → ext/ca_iter_block.c} +13 -13
- data/{ca_iter_dimension.c → ext/ca_iter_dimension.c} +16 -16
- data/{ca_iter_window.c → ext/ca_iter_window.c} +10 -10
- data/{ca_obj_array.c → ext/ca_obj_array.c} +60 -55
- data/{ca_obj_bitarray.c → ext/ca_obj_bitarray.c} +12 -12
- data/{ca_obj_bitfield.c → ext/ca_obj_bitfield.c} +7 -7
- data/{ca_obj_block.c → ext/ca_obj_block.c} +42 -42
- data/{ca_obj_fake.c → ext/ca_obj_fake.c} +7 -7
- data/{ca_obj_farray.c → ext/ca_obj_farray.c} +18 -18
- data/{ca_obj_field.c → ext/ca_obj_field.c} +15 -15
- data/{ca_obj_grid.c → ext/ca_obj_grid.c} +27 -27
- data/{ca_obj_mapping.c → ext/ca_obj_mapping.c} +9 -9
- data/{ca_obj_object.c → ext/ca_obj_object.c} +37 -37
- data/{ca_obj_reduce.c → ext/ca_obj_reduce.c} +1 -1
- data/{ca_obj_refer.c → ext/ca_obj_refer.c} +33 -33
- data/{ca_obj_repeat.c → ext/ca_obj_repeat.c} +43 -43
- data/{ca_obj_select.c → ext/ca_obj_select.c} +2 -2
- data/{ca_obj_shift.c → ext/ca_obj_shift.c} +23 -23
- data/{ca_obj_transpose.c → ext/ca_obj_transpose.c} +23 -23
- data/{ca_obj_unbound_repeat.c → ext/ca_obj_unbound_repeat.c} +55 -55
- data/{ca_obj_window.c → ext/ca_obj_window.c} +26 -26
- data/{carray.h → ext/carray.h} +77 -51
- data/{carray_access.c → ext/carray_access.c} +133 -91
- data/{carray_attribute.c → ext/carray_attribute.c} +12 -12
- data/{carray_call_cfunc.c → ext/carray_call_cfunc.c} +0 -0
- data/{carray_cast.c → ext/carray_cast.c} +6 -6
- data/{carray_cast_func.rb → ext/carray_cast_func.rb} +0 -0
- data/{carray_class.c → ext/carray_class.c} +0 -0
- data/{carray_conversion.c → ext/carray_conversion.c} +11 -13
- data/{carray_copy.c → ext/carray_copy.c} +19 -19
- data/{carray_core.c → ext/carray_core.c} +2 -2
- data/ext/carray_data_type.c +66 -0
- data/{carray_element.c → ext/carray_element.c} +9 -9
- data/{carray_generate.c → ext/carray_generate.c} +67 -1
- data/{carray_iterator.c → ext/carray_iterator.c} +40 -38
- data/{carray_loop.c → ext/carray_loop.c} +24 -24
- data/{carray_mask.c → ext/carray_mask.c} +17 -6
- data/{carray_math.rb → ext/carray_math.rb} +25 -25
- data/ext/{mathfunc/carray_mathfunc.c → carray_mathfunc.c} +0 -0
- data/{carray_numeric.c → ext/carray_numeric.c} +1 -1
- data/{carray_operator.c → ext/carray_operator.c} +32 -9
- data/{carray_order.c → ext/carray_order.c} +2 -153
- data/{carray_sort_addr.c → ext/carray_sort_addr.c} +0 -0
- data/{carray_stat.c → ext/carray_stat.c} +5 -5
- data/{carray_stat_proc.rb → ext/carray_stat_proc.rb} +23 -23
- data/{carray_test.c → ext/carray_test.c} +22 -21
- data/{carray_undef.c → ext/carray_undef.c} +0 -0
- data/{carray_utils.c → ext/carray_utils.c} +0 -0
- data/{extconf.rb → ext/extconf.rb} +0 -5
- data/{mkmath.rb → ext/mkmath.rb} +12 -2
- data/{ruby_carray.c → ext/ruby_carray.c} +9 -2
- data/{ruby_ccomplex.c → ext/ruby_ccomplex.c} +0 -0
- data/{ruby_float_func.c → ext/ruby_float_func.c} +0 -0
- data/{version.h → ext/version.h} +5 -5
- data/{version.rb → ext/version.rb} +0 -0
- data/lib/carray.rb +49 -7
- data/lib/carray/{base/autoload.rb → autoload.rb} +48 -6
- data/lib/carray/autoload/autoload_base.rb +1 -5
- data/lib/carray/autoload/autoload_gem_cairo.rb +9 -0
- data/lib/carray/autoload/autoload_gem_ffi.rb +9 -0
- data/lib/carray/autoload/autoload_gem_gnuplot.rb +2 -0
- data/lib/carray/autoload/autoload_gem_io_csv.rb +14 -0
- data/lib/carray/autoload/autoload_gem_io_pg.rb +6 -0
- data/lib/carray/autoload/autoload_gem_io_sqlite3.rb +12 -0
- data/lib/carray/autoload/autoload_gem_narray.rb +10 -0
- data/lib/carray/autoload/autoload_gem_numo_narray.rb +15 -0
- data/lib/carray/autoload/autoload_gem_opencv.rb +16 -0
- data/lib/carray/autoload/autoload_gem_random.rb +8 -0
- data/lib/carray/autoload/autoload_gem_rmagick.rb +23 -0
- data/lib/carray/autoload/{autoload_graphics_zimg.rb → autoload_gem_zimg.rb} +0 -0
- data/lib/carray/basic.rb +193 -0
- data/lib/carray/compose.rb +291 -0
- data/lib/carray/construct.rb +445 -0
- data/lib/carray/convert.rb +115 -0
- data/lib/carray/{base/inspect.rb → inspect.rb} +6 -6
- data/lib/carray/io/imagemagick.rb +1 -1
- data/lib/carray/{base/iterator.rb → iterator.rb} +3 -3
- data/lib/carray/mask.rb +91 -0
- data/lib/carray/{base/math.rb → math.rb} +17 -47
- data/lib/carray/math/histogram.rb +7 -7
- data/lib/carray/mkmf.rb +8 -0
- data/lib/carray/object/ca_obj_pack.rb +8 -8
- data/lib/carray/obsolete.rb +272 -0
- data/lib/carray/ordering.rb +157 -0
- data/lib/carray/{base/serialize.rb → serialize.rb} +28 -53
- data/lib/carray/string.rb +190 -0
- data/lib/carray/{base/struct.rb → struct.rb} +20 -20
- data/lib/carray/{io/table.rb → table.rb} +1 -9
- data/lib/carray/testing.rb +56 -0
- data/lib/carray/time.rb +78 -0
- data/lib/carray/transform.rb +100 -0
- data/misc/Methods.ja.md +182 -0
- data/{NOTE → misc/NOTE} +0 -0
- data/test/test_ALL.rb +0 -2
- data/test/test_order.rb +7 -7
- data/test/test_ref_store.rb +13 -13
- data/test/test_stat.rb +7 -15
- data/{devel → utils}/guess_shape.rb +0 -0
- data/utils/{diff_method.rb → monkey_patch_methods.rb} +17 -7
- metadata +100 -254
- data/COPYING +0 -56
- data/GPL +0 -340
- data/Gemfile +0 -8
- data/Gemfile.lock +0 -33
- data/LEGAL +0 -50
- data/TODO +0 -5
- data/carray_random.c +0 -531
- data/ext/calculus/carray_calculus.c +0 -931
- data/ext/calculus/carray_interp.c +0 -358
- data/ext/calculus/extconf.rb +0 -12
- data/ext/calculus/lib/autoload/autoload_math_calculus.rb +0 -2
- data/ext/calculus/lib/math/calculus.rb +0 -119
- data/ext/calculus/lib/math/interp/adapter_interp1d.rb +0 -31
- data/ext/fortio/extconf.rb +0 -3
- data/ext/fortio/lib/carray/autoload/autoload_fortran_format.rb +0 -5
- data/ext/fortio/lib/carray/io/fortran_format.rb +0 -43
- data/ext/fortio/lib/fortio.rb +0 -3
- data/ext/fortio/lib/fortio/fortran_format.rb +0 -605
- data/ext/fortio/lib/fortio/fortran_format.tab.rb +0 -536
- data/ext/fortio/lib/fortio/fortran_format.y +0 -215
- data/ext/fortio/lib/fortio/fortran_namelist.rb +0 -151
- data/ext/fortio/lib/fortio/fortran_namelist.tab.rb +0 -470
- data/ext/fortio/lib/fortio/fortran_namelist.y +0 -213
- data/ext/fortio/lib/fortio/fortran_sequential.rb +0 -345
- data/ext/fortio/ruby_fortio.c +0 -182
- data/ext/fortio/test/test_H.rb +0 -5
- data/ext/fortio/test/test_T.rb +0 -7
- data/ext/fortio/test/test_fortran_format.rb +0 -86
- data/ext/fortio/test/test_namelist.rb +0 -25
- data/ext/fortio/test/test_namelist_write.rb +0 -10
- data/ext/fortio/test/test_sequential.rb +0 -13
- data/ext/fortio/test/test_sequential2.rb +0 -13
- data/ext/fortio/work/test.rb +0 -10
- data/ext/fortio/work/test_e.rb +0 -19
- data/ext/fortio/work/test_ep.rb +0 -10
- data/ext/fortio/work/test_parse.rb +0 -12
- data/ext/imagemap/carray_imagemap.c +0 -495
- data/ext/imagemap/doc/call_graph.dot +0 -28
- data/ext/imagemap/draw.c +0 -567
- data/ext/imagemap/extconf.rb +0 -13
- data/ext/imagemap/lib/autoload/autoload_graphics_imagemap.rb +0 -1
- data/ext/imagemap/lib/graphics/imagemap.rb +0 -273
- data/ext/imagemap/lib/image_map.rb +0 -4
- data/ext/imagemap/test/swath_index.rb +0 -83
- data/ext/imagemap/test/swath_warp.rb +0 -99
- data/ext/imagemap/test/test.rb +0 -23
- data/ext/imagemap/test/test_image.rb +0 -42
- data/ext/imagemap/test/test_line.rb +0 -14
- data/ext/imagemap/test/test_rotate.rb +0 -17
- data/ext/imagemap/test/test_triangle.rb +0 -20
- data/ext/imagemap/test/test_warp.rb +0 -26
- data/ext/mathfunc/extconf.rb +0 -18
- data/ext/mathfunc/lib/autoload/autoload_math_mathfunc.rb +0 -1
- data/ext/mathfunc/lib/math/mathfunc.rb +0 -15
- data/ext/mathfunc/test/test_hypot.rb +0 -5
- data/ext/mathfunc/test/test_j0.rb +0 -22
- data/ext/mathfunc/test/test_jn.rb +0 -8
- data/ext/mathfunc/test/test_sph.rb +0 -9
- data/ext/narray/README +0 -22
- data/ext/narray/ca_wrap_narray.c +0 -500
- data/ext/narray/carray_narray.c +0 -21
- data/ext/narray/extconf.rb +0 -57
- data/ext/narray/lib/autoload/autoload_math_narray.rb +0 -1
- data/ext/narray/lib/autoload/autoload_math_narray_miss.rb +0 -11
- data/ext/narray/lib/math/narray.rb +0 -17
- data/ext/narray/lib/math/narray_miss.rb +0 -45
- data/lib/carray/autoload/autoload_graphics_gnuplot.rb +0 -2
- data/lib/carray/autoload/autoload_io_csv.rb +0 -14
- data/lib/carray/autoload/autoload_io_pg.rb +0 -6
- data/lib/carray/autoload/autoload_io_sqlite3.rb +0 -12
- data/lib/carray/autoload/autoload_io_table.rb +0 -1
- data/lib/carray/autoload/autoload_math_interp.rb +0 -4
- data/lib/carray/base/basic.rb +0 -1090
- data/lib/carray/base/obsolete.rb +0 -131
- data/lib/carray/graphics/gnuplot.rb +0 -2131
- data/lib/carray/graphics/zimg.rb +0 -296
- data/lib/carray/io/csv.rb +0 -572
- data/lib/carray/io/pg.rb +0 -101
- data/lib/carray/io/sqlite3.rb +0 -215
- data/lib/carray/math/interp.rb +0 -57
- data/lib/carray/math/interp/adapter_gsl_spline.rb +0 -47
- data/mt19937ar.c +0 -182
- data/mt19937ar.h +0 -86
- data/rdoc_main.rb +0 -27
- data/rdoc_math.rb +0 -5
- data/rdoc_stat.rb +0 -31
- data/test/test_narray.rb +0 -64
- data/test/test_random.rb +0 -15
- data/utils/create_rdoc.sh +0 -9
- data/utils/make_tgz.sh +0 -3
@@ -562,7 +562,7 @@ rb_ca_swap_bytes (VALUE self)
|
|
562
562
|
|
563
563
|
/* ----------------------------------------------------------------- */
|
564
564
|
|
565
|
-
#define
|
565
|
+
#define proc_trim_bang2(type, from) \
|
566
566
|
{ \
|
567
567
|
type *ptr = (type *) ca->ptr; \
|
568
568
|
boolean8_t *m = (ca->mask) ? (boolean8_t*) ca->mask->ptr : NULL; \
|
@@ -601,6 +601,72 @@ rb_ca_swap_bytes (VALUE self)
|
|
601
601
|
} \
|
602
602
|
}
|
603
603
|
|
604
|
+
#define proc_trim_bang(type, from) \
|
605
|
+
{ \
|
606
|
+
type *ptr = (type *) ca->ptr; \
|
607
|
+
boolean8_t *m = (ca->mask) ? (boolean8_t*) ca->mask->ptr : NULL; \
|
608
|
+
if ( ! NIL_P(rmin) ) { \
|
609
|
+
type min = (type) from(rmin); \
|
610
|
+
ca_size_t i; \
|
611
|
+
if ( m && rfval == CA_UNDEF) { \
|
612
|
+
for (i=ca->elements; i; i--, ptr++, m++) { \
|
613
|
+
if ( ! *m ) { \
|
614
|
+
if ( *ptr < min ) \
|
615
|
+
*m = 1; \
|
616
|
+
} \
|
617
|
+
} \
|
618
|
+
} \
|
619
|
+
else { \
|
620
|
+
int has_fill = ! ( NIL_P(rfval) ); \
|
621
|
+
type fill = (has_fill) ? (type) from(rfval) : (type) 0; \
|
622
|
+
if ( m ) { \
|
623
|
+
for (i=ca->elements; i; i--, ptr++) { \
|
624
|
+
if ( ! *m++ ) { \
|
625
|
+
if ( *ptr < min ) \
|
626
|
+
*ptr = (has_fill) ? fill : min; \
|
627
|
+
} \
|
628
|
+
} \
|
629
|
+
} \
|
630
|
+
else { \
|
631
|
+
for (i=ca->elements; i; i--, ptr++) { \
|
632
|
+
if ( *ptr < min ) \
|
633
|
+
*ptr = (has_fill) ? fill : min; \
|
634
|
+
} \
|
635
|
+
} \
|
636
|
+
} \
|
637
|
+
} \
|
638
|
+
if ( ! NIL_P(rmax) ) { \
|
639
|
+
type max = (type) from(rmax); \
|
640
|
+
ca_size_t i; \
|
641
|
+
if ( m && rfval == CA_UNDEF) { \
|
642
|
+
for (i=ca->elements; i; i--, ptr++, m++) { \
|
643
|
+
if ( ! *m ) { \
|
644
|
+
if ( *ptr >= max ) \
|
645
|
+
*m = 1; \
|
646
|
+
} \
|
647
|
+
} \
|
648
|
+
} \
|
649
|
+
else { \
|
650
|
+
int has_fill = ! ( NIL_P(rfval) ); \
|
651
|
+
type fill = (has_fill) ? (type) from(rfval) : (type) 0; \
|
652
|
+
if ( m ) { \
|
653
|
+
for (i=ca->elements; i; i--, ptr++) { \
|
654
|
+
if ( ! *m++ ) { \
|
655
|
+
if ( *ptr >= max ) \
|
656
|
+
*ptr = (has_fill) ? fill : max; \
|
657
|
+
} \
|
658
|
+
} \
|
659
|
+
} \
|
660
|
+
else { \
|
661
|
+
for (i=ca->elements; i; i--, ptr++) { \
|
662
|
+
if ( *ptr >= max ) \
|
663
|
+
*ptr = (has_fill) ? fill : max; \
|
664
|
+
} \
|
665
|
+
} \
|
666
|
+
} \
|
667
|
+
} \
|
668
|
+
}
|
669
|
+
|
604
670
|
/* rdoc:
|
605
671
|
class CArray
|
606
672
|
# trims the data into the range between min and max. If `fill_value`
|
@@ -15,19 +15,19 @@
|
|
15
15
|
VALUE rb_cCAIterator;
|
16
16
|
|
17
17
|
int8_t
|
18
|
-
|
18
|
+
ca_iter_ndim (VALUE self)
|
19
19
|
{
|
20
|
-
int8_t
|
20
|
+
int8_t ndim;
|
21
21
|
if ( TYPE(self) == T_DATA ) {
|
22
22
|
CAIterator *it;
|
23
23
|
Data_Get_Struct(self, CAIterator, it);
|
24
|
-
|
24
|
+
ndim = it->ndim;
|
25
25
|
}
|
26
26
|
else {
|
27
|
-
VALUE
|
28
|
-
|
27
|
+
VALUE rndim = rb_ivar_get(self, rb_intern("@ndim"));
|
28
|
+
ndim = (int8_t) NUM2LONG(rndim);
|
29
29
|
}
|
30
|
-
return
|
30
|
+
return ndim;
|
31
31
|
}
|
32
32
|
|
33
33
|
void
|
@@ -37,16 +37,16 @@ ca_iter_dim (VALUE self, ca_size_t *dim)
|
|
37
37
|
if ( TYPE(self) == T_DATA ) {
|
38
38
|
CAIterator *it;
|
39
39
|
Data_Get_Struct(self, CAIterator, it);
|
40
|
-
for (i=0; i<it->
|
40
|
+
for (i=0; i<it->ndim; i++) {
|
41
41
|
dim[i] = it->dim[i];
|
42
42
|
}
|
43
43
|
}
|
44
44
|
else {
|
45
|
-
VALUE
|
45
|
+
VALUE rndim = rb_ivar_get(self, rb_intern("@ndim"));
|
46
46
|
VALUE rdim = rb_ivar_get(self, rb_intern("@dim"));
|
47
|
-
int8_t
|
48
|
-
|
49
|
-
for (i=0; i<
|
47
|
+
int8_t ndim;
|
48
|
+
ndim = (int8_t) NUM2INT(rndim);
|
49
|
+
for (i=0; i<ndim; i++) {
|
50
50
|
dim[i] = NUM2SIZE(rb_ary_entry(rdim, i));
|
51
51
|
}
|
52
52
|
}
|
@@ -60,16 +60,16 @@ ca_iter_elements (VALUE self)
|
|
60
60
|
CAIterator *it;
|
61
61
|
Data_Get_Struct(self, CAIterator, it);
|
62
62
|
elements = 1;
|
63
|
-
for (i=0; i<it->
|
63
|
+
for (i=0; i<it->ndim; i++) {
|
64
64
|
elements *= it->dim[i];
|
65
65
|
}
|
66
66
|
}
|
67
67
|
else {
|
68
|
-
VALUE
|
68
|
+
VALUE rndim = rb_ivar_get(self, rb_intern("@ndim"));
|
69
69
|
VALUE rdim = rb_ivar_get(self, rb_intern("@dim"));
|
70
|
-
int8_t
|
70
|
+
int8_t ndim = (int8_t) NUM2INT(rndim);
|
71
71
|
elements = 1;
|
72
|
-
for (i=0; i<
|
72
|
+
for (i=0; i<ndim; i++) {
|
73
73
|
elements *= NUM2SIZE(rb_ary_entry(rdim, i));
|
74
74
|
}
|
75
75
|
}
|
@@ -119,10 +119,10 @@ ca_iter_kernel_at_index (VALUE self, ca_size_t *idx, VALUE rref)
|
|
119
119
|
}
|
120
120
|
else {
|
121
121
|
VALUE vidx;
|
122
|
-
int8_t
|
122
|
+
int8_t ndim = ca_iter_ndim(self);
|
123
123
|
int i;
|
124
|
-
vidx = rb_ary_new2(
|
125
|
-
for (i=0; i<
|
124
|
+
vidx = rb_ary_new2(ndim);
|
125
|
+
for (i=0; i<ndim; i++) {
|
126
126
|
rb_ary_store(vidx, i, SIZE2NUM(idx[i]));
|
127
127
|
}
|
128
128
|
rker = rb_funcall(self, rb_intern("kernel_at_index"), 2,
|
@@ -161,10 +161,10 @@ ca_iter_kernel_move_to_index (VALUE self, ca_size_t *idx, VALUE rref)
|
|
161
161
|
}
|
162
162
|
else {
|
163
163
|
VALUE vidx;
|
164
|
-
int8_t
|
164
|
+
int8_t ndim = ca_iter_ndim(self);
|
165
165
|
int i;
|
166
|
-
vidx = rb_ary_new2(
|
167
|
-
for (i=0; i<
|
166
|
+
vidx = rb_ary_new2(ndim);
|
167
|
+
for (i=0; i<ndim; i++) {
|
168
168
|
rb_ary_store(vidx, i, SIZE2NUM(idx[i]));
|
169
169
|
}
|
170
170
|
rker = rb_funcall(self, rb_intern("kernel_move_to_index"), 2,
|
@@ -188,17 +188,17 @@ ca_iter_prepare_output (VALUE self, VALUE rtype, VALUE rbytes)
|
|
188
188
|
if ( TYPE(self) == T_DATA ) {
|
189
189
|
CAIterator *it;
|
190
190
|
Data_Get_Struct(self, CAIterator, it);
|
191
|
-
co = carray_new_safe(data_type, it->
|
191
|
+
co = carray_new_safe(data_type, it->ndim, it->dim, bytes, NULL);
|
192
192
|
}
|
193
193
|
else {
|
194
|
-
VALUE
|
194
|
+
VALUE rndim = rb_ivar_get(self, rb_intern("@ndim"));
|
195
195
|
VALUE rdim = rb_ivar_get(self, rb_intern("@dim"));
|
196
|
-
int8_t
|
196
|
+
int8_t ndim = NUM2LONG(rndim);
|
197
197
|
ca_size_t dim[CA_RANK_MAX];
|
198
|
-
for (i=0; i<
|
198
|
+
for (i=0; i<ndim; i++) {
|
199
199
|
dim[i] = NUM2SIZE(rb_ary_entry(rdim, i));
|
200
200
|
}
|
201
|
-
co = carray_new_safe(data_type,
|
201
|
+
co = carray_new_safe(data_type, ndim, dim, bytes, NULL);
|
202
202
|
}
|
203
203
|
|
204
204
|
obj = ca_wrap_struct(co);
|
@@ -211,16 +211,16 @@ ca_iter_prepare_output (VALUE self, VALUE rtype, VALUE rbytes)
|
|
211
211
|
|
212
212
|
/* rdoc:
|
213
213
|
class CAIterator
|
214
|
-
def
|
214
|
+
def ndim
|
215
215
|
end
|
216
216
|
end
|
217
217
|
*/
|
218
218
|
|
219
219
|
|
220
220
|
VALUE
|
221
|
-
|
221
|
+
rb_ca_iter_ndim (VALUE self)
|
222
222
|
{
|
223
|
-
return LONG2NUM(
|
223
|
+
return LONG2NUM(ca_iter_ndim(self));
|
224
224
|
}
|
225
225
|
|
226
226
|
/* rdoc:
|
@@ -235,11 +235,11 @@ rb_ca_iter_dim (VALUE self)
|
|
235
235
|
{
|
236
236
|
VALUE rdim;
|
237
237
|
ca_size_t dim[CA_RANK_MAX];
|
238
|
-
int8_t
|
238
|
+
int8_t ndim = ca_iter_ndim(self);
|
239
239
|
int i;
|
240
240
|
ca_iter_dim(self, dim);
|
241
|
-
rdim = rb_ary_new2(
|
242
|
-
for (i=0; i<
|
241
|
+
rdim = rb_ary_new2(ndim);
|
242
|
+
for (i=0; i<ndim; i++) {
|
243
243
|
rb_ary_store(rdim, i, SIZE2NUM(dim[i]));
|
244
244
|
}
|
245
245
|
return rdim;
|
@@ -301,7 +301,7 @@ rb_ca_iter_kernel_at_index (int argc, VALUE *argv, VALUE self)
|
|
301
301
|
{
|
302
302
|
volatile VALUE rindex, rcarray;
|
303
303
|
ca_size_t idx[CA_RANK_MAX];
|
304
|
-
int8_t
|
304
|
+
int8_t ndim = ca_iter_ndim(self);
|
305
305
|
int i;
|
306
306
|
|
307
307
|
rb_scan_args(argc, argv, "11", (VALUE *) &rindex, (VALUE *) &rcarray);
|
@@ -310,7 +310,7 @@ rb_ca_iter_kernel_at_index (int argc, VALUE *argv, VALUE self)
|
|
310
310
|
rcarray = rb_ca_iter_reference(self);
|
311
311
|
}
|
312
312
|
|
313
|
-
for (i=0; i<
|
313
|
+
for (i=0; i<ndim; i++) {
|
314
314
|
idx[i] = NUM2SIZE(rb_ary_entry(rindex, i));
|
315
315
|
}
|
316
316
|
|
@@ -341,10 +341,10 @@ VALUE
|
|
341
341
|
rb_ca_iter_kernel_move_to_index (VALUE self, VALUE rindex, VALUE rker)
|
342
342
|
{
|
343
343
|
ca_size_t idx[CA_RANK_MAX];
|
344
|
-
int8_t
|
344
|
+
int8_t ndim = ca_iter_ndim(self);
|
345
345
|
int i;
|
346
346
|
|
347
|
-
for (i=0; i<
|
347
|
+
for (i=0; i<ndim; i++) {
|
348
348
|
idx[i] = NUM2SIZE(rb_ary_entry(rindex, i));
|
349
349
|
}
|
350
350
|
|
@@ -501,7 +501,7 @@ rb_ca_iter_filter (int argc, VALUE *argv, VALUE self)
|
|
501
501
|
argc--;
|
502
502
|
argv++;
|
503
503
|
|
504
|
-
co = carray_new(data_type, cr->
|
504
|
+
co = carray_new(data_type, cr->ndim, cr->dim, 0, NULL);
|
505
505
|
routput = ca_wrap_struct(co);
|
506
506
|
|
507
507
|
if ( NIL_P(argv[0]) ) {
|
@@ -606,8 +606,10 @@ Init_carray_iterator ()
|
|
606
606
|
{
|
607
607
|
rb_cCAIterator = rb_define_class("CAIterator", rb_cObject);
|
608
608
|
|
609
|
-
rb_define_method(rb_cCAIterator, "
|
609
|
+
rb_define_method(rb_cCAIterator, "ndim", rb_ca_iter_ndim, 0);
|
610
|
+
rb_define_method(rb_cCAIterator, "rank", rb_ca_iter_ndim, 0); /* alias */
|
610
611
|
rb_define_method(rb_cCAIterator, "dim", rb_ca_iter_dim, 0);
|
612
|
+
rb_define_method(rb_cCAIterator, "shape", rb_ca_iter_dim, 0); /* alias */
|
611
613
|
rb_define_method(rb_cCAIterator, "elements", rb_ca_iter_elements, 0);
|
612
614
|
rb_define_method(rb_cCAIterator, "reference", rb_ca_iter_reference, 0);
|
613
615
|
|
@@ -13,29 +13,29 @@
|
|
13
13
|
#include "carray.h"
|
14
14
|
|
15
15
|
static VALUE
|
16
|
-
rb_ca_s_each_index_internal (int
|
16
|
+
rb_ca_s_each_index_internal (int ndim, VALUE *dim, uint8_t indim, VALUE ridx)
|
17
17
|
{
|
18
18
|
volatile VALUE ret = Qnil;
|
19
|
-
int32_t is_leaf = (
|
19
|
+
int32_t is_leaf = (indim == ndim - 1);
|
20
20
|
ca_size_t i;
|
21
21
|
|
22
|
-
if ( NIL_P(dim[
|
23
|
-
rb_ary_store(ridx,
|
22
|
+
if ( NIL_P(dim[indim]) ) {
|
23
|
+
rb_ary_store(ridx, indim, Qnil);
|
24
24
|
if ( is_leaf ) {
|
25
25
|
ret = rb_yield_splat(rb_obj_clone(ridx));
|
26
26
|
}
|
27
27
|
else {
|
28
|
-
ret = rb_ca_s_each_index_internal(
|
28
|
+
ret = rb_ca_s_each_index_internal(ndim, dim, indim+1, ridx);
|
29
29
|
}
|
30
30
|
}
|
31
31
|
else {
|
32
|
-
for (i=0; i<NUM2SIZE(dim[
|
33
|
-
rb_ary_store(ridx,
|
32
|
+
for (i=0; i<NUM2SIZE(dim[indim]); i++) {
|
33
|
+
rb_ary_store(ridx, indim, SIZE2NUM(i));
|
34
34
|
if ( is_leaf ) {
|
35
35
|
ret = rb_yield_splat(rb_obj_clone(ridx));
|
36
36
|
}
|
37
37
|
else {
|
38
|
-
ret = rb_ca_s_each_index_internal(
|
38
|
+
ret = rb_ca_s_each_index_internal(ndim, dim, indim+1, ridx);
|
39
39
|
}
|
40
40
|
}
|
41
41
|
}
|
@@ -58,13 +58,13 @@ rb_ca_s_each_index_internal (int rank, VALUE *dim, uint8_t irank, VALUE ridx)
|
|
58
58
|
*/
|
59
59
|
|
60
60
|
static VALUE
|
61
|
-
rb_ca_s_each_index (int
|
61
|
+
rb_ca_s_each_index (int ndim, VALUE *dim, VALUE self)
|
62
62
|
{
|
63
|
-
volatile VALUE ridx = rb_ary_new2(
|
63
|
+
volatile VALUE ridx = rb_ary_new2(ndim);
|
64
64
|
#if RUBY_VERSION_CODE >= 190
|
65
|
-
RETURN_ENUMERATOR(self,
|
65
|
+
RETURN_ENUMERATOR(self, ndim, dim);
|
66
66
|
#endif
|
67
|
-
return rb_ca_s_each_index_internal(
|
67
|
+
return rb_ca_s_each_index_internal(ndim, dim, 0, ridx);
|
68
68
|
}
|
69
69
|
|
70
70
|
/* ------------------------------------------------------------------- */
|
@@ -145,7 +145,7 @@ rb_ca_each_index_internal (VALUE self, int8_t level, VALUE ridx)
|
|
145
145
|
CArray *ca;
|
146
146
|
ca_size_t i;
|
147
147
|
Data_Get_Struct(self, CArray, ca);
|
148
|
-
if ( level == ca->
|
148
|
+
if ( level == ca->ndim - 1 ) {
|
149
149
|
for (i=0; i<ca->dim[level]; i++) {
|
150
150
|
rb_ary_store(ridx, level, SIZE2NUM(i));
|
151
151
|
ret = rb_yield_splat(rb_obj_clone(ridx));
|
@@ -179,8 +179,8 @@ static VALUE
|
|
179
179
|
rb_ca_each_index (VALUE self)
|
180
180
|
{
|
181
181
|
volatile VALUE ridx;
|
182
|
-
int8_t
|
183
|
-
ridx = rb_ary_new2(
|
182
|
+
int8_t ndim = NUM2INT(rb_ca_ndim(self));
|
183
|
+
ridx = rb_ary_new2(ndim);
|
184
184
|
#if RUBY_VERSION_CODE >= 190
|
185
185
|
RETURN_ENUMERATOR(self, 0, 0);
|
186
186
|
#endif
|
@@ -225,7 +225,7 @@ rb_ca_each_with_index_internal (VALUE self,
|
|
225
225
|
CArray *ca;
|
226
226
|
ca_size_t i;
|
227
227
|
Data_Get_Struct(self, CArray, ca);
|
228
|
-
if ( level == ca->
|
228
|
+
if ( level == ca->ndim - 1 ) {
|
229
229
|
for (i=0; i<ca->dim[level]; i++) {
|
230
230
|
idx[level] = i;
|
231
231
|
rb_ary_store(ridx, level, SIZE2NUM(i));
|
@@ -256,12 +256,12 @@ rb_ca_each_with_index (VALUE self)
|
|
256
256
|
{
|
257
257
|
volatile VALUE ridx, ret;
|
258
258
|
ca_size_t idx[CA_RANK_MAX];
|
259
|
-
int8_t
|
259
|
+
int8_t ndim = NUM2INT(rb_ca_ndim(self));
|
260
260
|
#if RUBY_VERSION_CODE >= 190
|
261
261
|
RETURN_ENUMERATOR(self, 0, 0);
|
262
262
|
#endif
|
263
263
|
rb_ca_modify(self);
|
264
|
-
ridx = rb_ary_new2(
|
264
|
+
ridx = rb_ary_new2(ndim);
|
265
265
|
ret = rb_ca_each_with_index_internal(self, 0, idx, ridx);
|
266
266
|
return ret;
|
267
267
|
}
|
@@ -274,7 +274,7 @@ rb_ca_map_with_index_bang_internal (VALUE self,
|
|
274
274
|
CArray *ca;
|
275
275
|
ca_size_t i;
|
276
276
|
Data_Get_Struct(self, CArray, ca);
|
277
|
-
if ( level == ca->
|
277
|
+
if ( level == ca->ndim - 1 ) {
|
278
278
|
volatile VALUE obj;
|
279
279
|
for (i=0; i<ca->dim[level]; i++) {
|
280
280
|
idx[level] = i;
|
@@ -307,14 +307,14 @@ rb_ca_map_with_index_bang (VALUE self)
|
|
307
307
|
volatile VALUE ridx;
|
308
308
|
CArray *ca;
|
309
309
|
ca_size_t idx[CA_RANK_MAX];
|
310
|
-
int8_t
|
310
|
+
int8_t ndim = NUM2INT(rb_ca_ndim(self));
|
311
311
|
#if RUBY_VERSION_CODE >= 190
|
312
312
|
RETURN_ENUMERATOR(self, 0, 0);
|
313
313
|
#endif
|
314
314
|
rb_ca_modify(self);
|
315
315
|
Data_Get_Struct(self, CArray, ca);
|
316
316
|
ca_attach(ca);
|
317
|
-
ridx = rb_ary_new2(
|
317
|
+
ridx = rb_ary_new2(ndim);
|
318
318
|
rb_ca_map_with_index_bang_internal(self, 0, idx, ridx);
|
319
319
|
ca_sync(ca);
|
320
320
|
ca_detach(ca);
|
@@ -329,7 +329,7 @@ rb_ca_map_index_bang_internal (VALUE self,
|
|
329
329
|
CArray *ca;
|
330
330
|
ca_size_t i;
|
331
331
|
Data_Get_Struct(self, CArray, ca);
|
332
|
-
if ( level == ca->
|
332
|
+
if ( level == ca->ndim - 1 ) {
|
333
333
|
volatile VALUE obj;
|
334
334
|
for (i=0; i<ca->dim[level]; i++) {
|
335
335
|
idx[level] = i;
|
@@ -361,14 +361,14 @@ rb_ca_map_index_bang (VALUE self)
|
|
361
361
|
volatile VALUE ridx;
|
362
362
|
CArray *ca;
|
363
363
|
ca_size_t idx[CA_RANK_MAX];
|
364
|
-
int8_t
|
364
|
+
int8_t ndim = NUM2INT(rb_ca_ndim(self));
|
365
365
|
#if RUBY_VERSION_CODE >= 190
|
366
366
|
RETURN_ENUMERATOR(self, 0, 0);
|
367
367
|
#endif
|
368
368
|
rb_ca_modify(self);
|
369
369
|
Data_Get_Struct(self, CArray, ca);
|
370
370
|
ca_attach(ca);
|
371
|
-
ridx = rb_ary_new2(
|
371
|
+
ridx = rb_ary_new2(ndim);
|
372
372
|
rb_ca_map_index_bang_internal(self, 0, idx, ridx);
|
373
373
|
ca_sync(ca);
|
374
374
|
ca_detach(ca);
|
@@ -668,7 +668,7 @@ rb_ca_value_array (VALUE self)
|
|
668
668
|
|
669
669
|
Data_Get_Struct(self, CArray, ca);
|
670
670
|
|
671
|
-
obj = rb_ca_refer_new(self, ca->data_type, ca->
|
671
|
+
obj = rb_ca_refer_new(self, ca->data_type, ca->ndim, ca->dim, ca->bytes, 0);
|
672
672
|
Data_Get_Struct(obj, CArray, co);
|
673
673
|
|
674
674
|
ca_set_flag(co, CA_FLAG_VALUE_ARRAY);
|
@@ -777,7 +777,7 @@ rb_ca_is_masked (VALUE self)
|
|
777
777
|
|
778
778
|
Data_Get_Struct(self, CArray, ca);
|
779
779
|
|
780
|
-
co = carray_new(CA_BOOLEAN, ca->
|
780
|
+
co = carray_new(CA_BOOLEAN, ca->ndim, ca->dim, ca->bytes, NULL);
|
781
781
|
|
782
782
|
ca_update_mask(ca);
|
783
783
|
if ( ! ca->mask ) {
|
@@ -820,7 +820,7 @@ rb_ca_is_not_masked (VALUE self)
|
|
820
820
|
|
821
821
|
Data_Get_Struct(self, CArray, ca);
|
822
822
|
|
823
|
-
co = carray_new(CA_BOOLEAN, ca->
|
823
|
+
co = carray_new(CA_BOOLEAN, ca->ndim, ca->dim, ca->bytes, NULL);
|
824
824
|
|
825
825
|
ca_update_mask(ca);
|
826
826
|
if ( ! ca->mask ) {
|
@@ -874,6 +874,17 @@ rb_ca_count_not_masked (VALUE self)
|
|
874
874
|
return SIZE2NUM(ca_count_not_masked(ca));
|
875
875
|
}
|
876
876
|
|
877
|
+
/* rdoc:
|
878
|
+
class CArray
|
879
|
+
# Unmask all elements of the object.
|
880
|
+
# If the optional argument <code>fill_value</code> is given,
|
881
|
+
# the masked elements are filled by <code>fill_value</code>.
|
882
|
+
# The returned array doesn't have the mask array.
|
883
|
+
def unmask (fill_value=nil)
|
884
|
+
end
|
885
|
+
end
|
886
|
+
*/
|
887
|
+
|
877
888
|
static VALUE
|
878
889
|
rb_ca_unmask_method (int argc, VALUE *argv, VALUE self)
|
879
890
|
{
|
@@ -1168,9 +1179,9 @@ Init_carray_mask ()
|
|
1168
1179
|
rb_define_method(rb_cCArray, "inherit_mask_replace",
|
1169
1180
|
rb_ca_inherit_mask_replace_method, -1);
|
1170
1181
|
|
1171
|
-
/* These methods go to lib/carray/
|
1172
|
-
/*
|
1173
|
-
/*
|
1182
|
+
/* These methods go to lib/carray/mask.rb. */
|
1183
|
+
/* def count_masked (*axis); end */
|
1184
|
+
/* def count_not_masked (*axis); end */
|
1174
1185
|
|
1175
1186
|
}
|
1176
1187
|
|