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
@@ -10,7 +10,7 @@
|
|
10
10
|
#
|
11
11
|
# ----------------------------------------------------------------------------
|
12
12
|
|
13
|
-
|
13
|
+
require_relative './mkmath'
|
14
14
|
|
15
15
|
HEADERS << <<HERE_END
|
16
16
|
/* ---------------------------------------------------------------------------
|
@@ -228,22 +228,22 @@ binop("pmin", "pmin",
|
|
228
228
|
CMPLX_TYPES => nil,
|
229
229
|
OBJ_TYPES =>'(#3) = rb_funcall(rb_assoc_new((#1),(#2)), rb_intern("min"), 0);')
|
230
230
|
|
231
|
-
binop("
|
231
|
+
binop("+", "add",
|
232
232
|
ALL_TYPES =>"(#3) = (#1) + (#2);",
|
233
233
|
CMPLX_TYPES => HAVE_COMPLEX ? "(#3) = (#1) + (#2);" : nil,
|
234
234
|
OBJ_TYPES =>'(#3) = rb_funcall((#1), id_plus, 1, (#2));')
|
235
235
|
|
236
|
-
binop("
|
236
|
+
binop("-", "sub",
|
237
237
|
ALL_TYPES => "(#3) = (#1) - (#2);",
|
238
238
|
CMPLX_TYPES => HAVE_COMPLEX ? "(#3) = (#1) - (#2);" : nil,
|
239
239
|
OBJ_TYPES => '(#3) = rb_funcall((#1), id_minus, 1, (#2));')
|
240
240
|
|
241
|
-
binop("
|
241
|
+
binop("*", "mul",
|
242
242
|
ALL_TYPES => "(#3) = (#1) * (#2);",
|
243
243
|
CMPLX_TYPES => HAVE_COMPLEX ? "(#3) = (#1) * (#2);" : nil,
|
244
244
|
OBJ_TYPES => '(#3) = rb_funcall((#1), id_star, 1, (#2));')
|
245
245
|
|
246
|
-
binop("
|
246
|
+
binop("/", "div",
|
247
247
|
INT_TYPES => "if ((#2)==0) {ca_zerodiv();}; (#3) = (#1) / (#2);",
|
248
248
|
FLOAT_TYPES => "(#3) = (#1) / (#2);",
|
249
249
|
CMPLX_TYPES => HAVE_COMPLEX ? "(#3) = (#1) / (#2);" : nil,
|
@@ -258,21 +258,21 @@ binop("rcp_mul", "rcp_mul",
|
|
258
258
|
CMPLX_TYPES => HAVE_COMPLEX ? "(#3) = (#2) / (#1);" : nil,
|
259
259
|
OBJ_TYPES => '(#3) = rb_funcall((#2), id_slash, 1, (#1));')
|
260
260
|
|
261
|
-
binop("
|
261
|
+
binop("%", "mod",
|
262
262
|
INT_TYPES => "if ((#2)==0) {ca_zerodiv();}; (#3) = (#1) % (#2);",
|
263
263
|
OBJ_TYPES => '(#3) = rb_funcall((#1), id_percent, 1, (#2));')
|
264
264
|
|
265
|
-
binop("
|
265
|
+
binop("&", "bit_and_i",
|
266
266
|
BOOL_TYPES => "(#3) = (#1) & (#2);",
|
267
267
|
INT_TYPES => "(#3) = (#1) & (#2);",
|
268
268
|
OBJ_TYPES => '(#3) = rb_funcall((#1), id_and, 1, (#2));')
|
269
269
|
|
270
|
-
binop("
|
270
|
+
binop("|", "bit_or_i",
|
271
271
|
BOOL_TYPES => "(#3) = (#1) | (#2);",
|
272
272
|
INT_TYPES => "(#3) = (#1) | (#2);",
|
273
273
|
OBJ_TYPES => '(#3) = rb_funcall((#1), id_or, 1, (#2));')
|
274
274
|
|
275
|
-
binop("
|
275
|
+
binop("^", "bit_xor_i",
|
276
276
|
BOOL_TYPES => "(#3) = ((#1) != (#2)) ? 1 : 0;",
|
277
277
|
INT_TYPES => "(#3) = (#1) ^ (#2);",
|
278
278
|
OBJ_TYPES => '(#3) = rb_funcall((#1), id_xor, 1, (#2));')
|
@@ -329,11 +329,11 @@ METHODS << %{
|
|
329
329
|
rb_define_method(rb_cCArray, "bit_xor", rb_ca_bit_xor, 1);
|
330
330
|
}
|
331
331
|
|
332
|
-
binop("
|
332
|
+
binop("<<", "bit_lshift",
|
333
333
|
INT_TYPES => "(#3) = (#1) << (#2);",
|
334
334
|
OBJ_TYPES => '(#3) = rb_funcall((#1), id_lshift, 1, (#2));')
|
335
335
|
|
336
|
-
binop("
|
336
|
+
binop(">>", "bit_rshift",
|
337
337
|
INT_TYPES => "(#3) = (#1) >> (#2);",
|
338
338
|
OBJ_TYPES => '(#3) = rb_funcall((#1), id_rshift, 1, (#2));')
|
339
339
|
|
@@ -461,16 +461,16 @@ METHODS << %{
|
|
461
461
|
rb_define_method(rb_cCArray, "xor", rb_ca_xor, 1);
|
462
462
|
}
|
463
463
|
|
464
|
-
alias_op("
|
465
|
-
alias_op("
|
466
|
-
alias_op("
|
467
|
-
alias_op("
|
468
|
-
alias_op("
|
469
|
-
alias_op("
|
470
|
-
alias_op("
|
471
|
-
alias_op("
|
472
|
-
alias_op("
|
473
|
-
alias_op("
|
464
|
+
alias_op("add", "+")
|
465
|
+
alias_op("sub", "-")
|
466
|
+
alias_op("mul", "*")
|
467
|
+
alias_op("div", "/")
|
468
|
+
alias_op("mod", "%")
|
469
|
+
alias_op("bit_and", "&")
|
470
|
+
alias_op("bit_or", "|")
|
471
|
+
alias_op("bit_xor", "^")
|
472
|
+
alias_op("bit_lshift", "<<")
|
473
|
+
alias_op("bit_rshift", ">>")
|
474
474
|
|
475
475
|
#alias_op("==", "eq")
|
476
476
|
#alias_op("!=", "ne")
|
@@ -697,7 +697,7 @@ rb_ca_ipower (VALUE self, VALUE other)
|
|
697
697
|
/* unresolved unbound repeat array generates unbound repeat array again */
|
698
698
|
if ( ca->obj_type == CA_OBJ_UNBOUND_REPEAT ) {
|
699
699
|
CAUnboundRepeat *cx = (CAUnboundRepeat *) ca;
|
700
|
-
obj = rb_ca_ubrep_new(obj, cx->
|
700
|
+
obj = rb_ca_ubrep_new(obj, cx->rep_ndim, cx->rep_dim);
|
701
701
|
}
|
702
702
|
|
703
703
|
return obj;
|
@@ -752,7 +752,7 @@ rb_ca_ipower_bang (VALUE self, VALUE other)
|
|
752
752
|
|
753
753
|
}
|
754
754
|
|
755
|
-
binop("
|
755
|
+
binop("**", "power",
|
756
756
|
INT_TYPES => "(#3) = op_powi_<type>((#1), (#2));",
|
757
757
|
FLOAT_TYPES => "(#3) = pow((#1), (#2));",
|
758
758
|
CMPLX_TYPES => HAVE_COMPLEX ? "(#3) = cpow((#1), (#2));" : nil,
|
@@ -776,7 +776,7 @@ static VALUE rb_ca_pow (VALUE self, VALUE other)
|
|
776
776
|
/* unresolved unbound repeat array generates unbound repeat array again */
|
777
777
|
if ( ca->obj_type == CA_OBJ_UNBOUND_REPEAT ) {
|
778
778
|
CAUnboundRepeat *cx = (CAUnboundRepeat *) ca;
|
779
|
-
obj = rb_ca_ubrep_new(obj, cx->
|
779
|
+
obj = rb_ca_ubrep_new(obj, cx->rep_ndim, cx->rep_dim);
|
780
780
|
}
|
781
781
|
|
782
782
|
return obj;
|
@@ -803,7 +803,7 @@ METHODS << %{
|
|
803
803
|
rb_define_method(rb_cCArray, "pow!", rb_ca_pow_bang, 1);
|
804
804
|
}
|
805
805
|
|
806
|
-
alias_op("
|
806
|
+
alias_op("pow", "**")
|
807
807
|
|
808
808
|
METHODS << %{
|
809
809
|
id_equal = rb_intern("==");
|
File without changes
|
@@ -168,7 +168,7 @@ rb_ca_arg (VALUE self)
|
|
168
168
|
|
169
169
|
Data_Get_Struct(self, CArray, ca);
|
170
170
|
|
171
|
-
co = carray_new(CA_FLOAT64, ca->
|
171
|
+
co = carray_new(CA_FLOAT64, ca->ndim, ca->dim, 0, NULL);
|
172
172
|
obj = ca_wrap_struct(co);
|
173
173
|
|
174
174
|
if ( ca_has_mask(ca) ) {
|
@@ -58,7 +58,7 @@ rb_ca_call_monop (VALUE self, ca_monop_func_t func[])
|
|
58
58
|
/* unresolved unbound repeat array generates unbound repeat array again */
|
59
59
|
if ( ca1->obj_type == CA_OBJ_UNBOUND_REPEAT ) {
|
60
60
|
CAUnboundRepeat *cx = (CAUnboundRepeat *) ca1;
|
61
|
-
out = rb_ca_ubrep_new(out, cx->
|
61
|
+
out = rb_ca_ubrep_new(out, cx->rep_ndim, cx->rep_dim);
|
62
62
|
}
|
63
63
|
|
64
64
|
return out;
|
@@ -84,6 +84,29 @@ rb_ca_call_monop_bang (VALUE self, ca_monop_func_t func[])
|
|
84
84
|
return self;
|
85
85
|
}
|
86
86
|
|
87
|
+
int
|
88
|
+
rb_ca_test_castable (VALUE other)
|
89
|
+
{
|
90
|
+
volatile VALUE retval;
|
91
|
+
if ( rb_respond_to(other, rb_intern("castable_to_carray?")) ) {
|
92
|
+
retval = rb_funcall(other, rb_intern("castable_to_carray?"), 0);
|
93
|
+
return RTEST(retval);
|
94
|
+
}
|
95
|
+
else {
|
96
|
+
return 1;
|
97
|
+
}
|
98
|
+
}
|
99
|
+
|
100
|
+
VALUE
|
101
|
+
rb_ca_binop_pass_to_other (VALUE self, VALUE other, ID method)
|
102
|
+
{
|
103
|
+
volatile VALUE pair;
|
104
|
+
pair = rb_funcall(other, rb_intern("coerce"), 1, self);
|
105
|
+
self = rb_ary_entry(pair, 0);
|
106
|
+
other = rb_ary_entry(pair, 1);
|
107
|
+
return rb_funcall(self, method, 1, other);
|
108
|
+
}
|
109
|
+
|
87
110
|
VALUE
|
88
111
|
rb_ca_call_binop (volatile VALUE self, volatile VALUE other,
|
89
112
|
ca_binop_func_t func[])
|
@@ -174,13 +197,13 @@ rb_ca_call_binop (volatile VALUE self, volatile VALUE other,
|
|
174
197
|
/* unresolved unbound repeat array generates unbound repeat array again */
|
175
198
|
if ( ca1->obj_type == CA_OBJ_UNBOUND_REPEAT ) {
|
176
199
|
CAUnboundRepeat *cx = (CAUnboundRepeat *) ca1;
|
177
|
-
out = rb_ca_ubrep_new(out, cx->
|
200
|
+
out = rb_ca_ubrep_new(out, cx->rep_ndim, cx->rep_dim);
|
178
201
|
}
|
179
202
|
|
180
203
|
/* unresolved unbound repeat array generates unbound repeat array again */
|
181
204
|
if ( ca2->obj_type == CA_OBJ_UNBOUND_REPEAT ) {
|
182
205
|
CAUnboundRepeat *cx = (CAUnboundRepeat *) ca2;
|
183
|
-
out = rb_ca_ubrep_new(out, cx->
|
206
|
+
out = rb_ca_ubrep_new(out, cx->rep_ndim, cx->rep_dim);
|
184
207
|
}
|
185
208
|
|
186
209
|
return out;
|
@@ -264,7 +287,7 @@ rb_ca_call_moncmp (VALUE self, ca_moncmp_func_t func[])
|
|
264
287
|
out = rb_cscalar_new(CA_BOOLEAN, 0, NULL);
|
265
288
|
}
|
266
289
|
else {
|
267
|
-
out = rb_carray_new(CA_BOOLEAN, ca1->
|
290
|
+
out = rb_carray_new(CA_BOOLEAN, ca1->ndim, ca1->dim, 0, NULL);
|
268
291
|
}
|
269
292
|
|
270
293
|
Data_Get_Struct(out, CArray, ca2);
|
@@ -279,7 +302,7 @@ rb_ca_call_moncmp (VALUE self, ca_moncmp_func_t func[])
|
|
279
302
|
/* unresolved unbound repeat array generates unbound repeat array again */
|
280
303
|
if ( ca1->obj_type == CA_OBJ_UNBOUND_REPEAT ) {
|
281
304
|
CAUnboundRepeat *cx = (CAUnboundRepeat *) ca1;
|
282
|
-
out = rb_ca_ubrep_new(out, cx->
|
305
|
+
out = rb_ca_ubrep_new(out, cx->rep_ndim, cx->rep_dim);
|
283
306
|
}
|
284
307
|
|
285
308
|
return out;
|
@@ -330,7 +353,7 @@ rb_ca_call_bincmp (volatile VALUE self, volatile VALUE other,
|
|
330
353
|
ca3->ptr, ca3->bytes, 0);
|
331
354
|
}
|
332
355
|
else { /* scalar vs array */
|
333
|
-
out = rb_carray_new(CA_BOOLEAN, ca2->
|
356
|
+
out = rb_carray_new(CA_BOOLEAN, ca2->ndim, ca2->dim, 0, NULL);
|
334
357
|
Data_Get_Struct(out, CArray, ca3);
|
335
358
|
|
336
359
|
ca_copy_mask_overlay(ca3, ca3->elements, 2, ca1, ca2);
|
@@ -342,7 +365,7 @@ rb_ca_call_bincmp (volatile VALUE self, volatile VALUE other,
|
|
342
365
|
}
|
343
366
|
else {
|
344
367
|
if ( rb_obj_is_cscalar(other) ) { /* array vs scalar */
|
345
|
-
out = rb_carray_new(CA_BOOLEAN, ca1->
|
368
|
+
out = rb_carray_new(CA_BOOLEAN, ca1->ndim, ca1->dim, 0, NULL);
|
346
369
|
Data_Get_Struct(out, CArray, ca3);
|
347
370
|
|
348
371
|
ca_copy_mask_overlay(ca3, ca3->elements, 2, ca1, ca2);
|
@@ -356,7 +379,7 @@ rb_ca_call_bincmp (volatile VALUE self, volatile VALUE other,
|
|
356
379
|
rb_raise(rb_eRuntimeError, "elements mismatch in bincmp (%lld <-> %lld)",
|
357
380
|
(ca_size_t) ca1->elements, (ca_size_t) ca2->elements);
|
358
381
|
}
|
359
|
-
out = rb_carray_new(CA_BOOLEAN, ca1->
|
382
|
+
out = rb_carray_new(CA_BOOLEAN, ca1->ndim, ca1->dim, 0, NULL);
|
360
383
|
Data_Get_Struct(out, CArray, ca3);
|
361
384
|
|
362
385
|
ca_copy_mask_overlay(ca3, ca3->elements, 2, ca1, ca2);
|
@@ -372,7 +395,7 @@ rb_ca_call_bincmp (volatile VALUE self, volatile VALUE other,
|
|
372
395
|
/* unresolved unbound repeat array generates unbound repeat array again */
|
373
396
|
if ( ca1->obj_type == CA_OBJ_UNBOUND_REPEAT ) {
|
374
397
|
CAUnboundRepeat *cx = (CAUnboundRepeat *) ca1;
|
375
|
-
out = rb_ca_ubrep_new(out, cx->
|
398
|
+
out = rb_ca_ubrep_new(out, cx->rep_ndim, cx->rep_dim);
|
376
399
|
}
|
377
400
|
|
378
401
|
return out;
|
@@ -132,7 +132,7 @@ ca_project (CArray *ca, CArray *ci, char *lfill, char *ufill)
|
|
132
132
|
|
133
133
|
ca_attach_n(2, ca, ci); /* ATTACH */
|
134
134
|
|
135
|
-
co = carray_new(ca->data_type, ci->
|
135
|
+
co = carray_new(ca->data_type, ci->ndim, ci->dim, ca->bytes, NULL);
|
136
136
|
ca_project_loop(co, ca, ci, lfill, ufill);
|
137
137
|
|
138
138
|
ca_detach_n(2, ca, ci); /* DETACH */
|
@@ -449,154 +449,6 @@ rb_ca_sorted_copy (VALUE self)
|
|
449
449
|
return rb_ca_sort_bang(out);
|
450
450
|
}
|
451
451
|
|
452
|
-
/* --------------------------------------------------------------- */
|
453
|
-
|
454
|
-
/*
|
455
|
-
Fisher-Yates method
|
456
|
-
|
457
|
-
# [ruby-list:41356]
|
458
|
-
# From: Shin-ichiro HARA <sinara blade.nagaokaut.ac.jp>
|
459
|
-
def shuffle!
|
460
|
-
array = self
|
461
|
-
array.each_index do |idx|
|
462
|
-
jdx = rand(idx + 1)
|
463
|
-
array[idx], array[jdx] = array[jdx], array[idx]
|
464
|
-
end
|
465
|
-
self
|
466
|
-
end
|
467
|
-
*/
|
468
|
-
|
469
|
-
#define proc_shuffle(type) \
|
470
|
-
{ \
|
471
|
-
ca_size_t idx, jdx; \
|
472
|
-
type *ptr, *p, *q; \
|
473
|
-
type t1; \
|
474
|
-
ptr = (type *) ca->ptr; \
|
475
|
-
if ( ca->mask ) { \
|
476
|
-
boolean8_t *mptr, *mp, *mq; \
|
477
|
-
boolean8_t mt1; \
|
478
|
-
mptr = (boolean8_t *)ca->mask->ptr; \
|
479
|
-
for (idx=0; idx<ca->elements; idx++) { \
|
480
|
-
jdx = ca_rand((double)(idx+1)); \
|
481
|
-
p = ptr + idx; \
|
482
|
-
q = ptr + jdx; \
|
483
|
-
mp = mptr + idx; \
|
484
|
-
mq = mptr + jdx; \
|
485
|
-
t1 = *p; *p = *q; *q = t1; \
|
486
|
-
mt1 = *mp; *mp = *mq; *mq = mt1; \
|
487
|
-
} \
|
488
|
-
} \
|
489
|
-
else { \
|
490
|
-
for (idx=0; idx<ca->elements; idx++) { \
|
491
|
-
jdx = ca_rand((double)(idx+1)); \
|
492
|
-
p = ptr + idx; \
|
493
|
-
q = ptr + jdx; \
|
494
|
-
t1 = *p; *p = *q; *q = t1; \
|
495
|
-
} \
|
496
|
-
} \
|
497
|
-
}
|
498
|
-
|
499
|
-
#define proc_shuffle_fixlen() \
|
500
|
-
{ \
|
501
|
-
ca_size_t idx, jdx; \
|
502
|
-
char *ptr, *p, *q; \
|
503
|
-
char *t = (char*) malloc_with_check(ca->bytes); \
|
504
|
-
ca_size_t bytes = ca->bytes; \
|
505
|
-
ptr = ca->ptr; \
|
506
|
-
if ( ca->mask ) { \
|
507
|
-
boolean8_t *mptr, *mp, *mq; \
|
508
|
-
boolean8_t mt1; \
|
509
|
-
mptr = (boolean8_t *)ca->mask->ptr; \
|
510
|
-
for (idx=0; idx<ca->elements; idx++) { \
|
511
|
-
jdx = ca_rand((double)(idx+1)); \
|
512
|
-
p = ca->ptr + idx*bytes; \
|
513
|
-
q = ca->ptr + jdx*bytes; \
|
514
|
-
mp = mptr + idx; \
|
515
|
-
mq = mptr + jdx; \
|
516
|
-
memcpy(t, p, bytes); memcpy(p, q, bytes); memcpy(q, t, bytes); \
|
517
|
-
mt1 = *mp; *mp = *mq; *mq = mt1; \
|
518
|
-
} \
|
519
|
-
free(t); \
|
520
|
-
} \
|
521
|
-
else { \
|
522
|
-
for (idx=0; idx<ca->elements; idx++) { \
|
523
|
-
jdx = ca_rand((double)(idx+1)); \
|
524
|
-
p = ca->ptr + idx*bytes; \
|
525
|
-
q = ca->ptr + jdx*bytes; \
|
526
|
-
memcpy(t, p, bytes); memcpy(p, q, bytes); memcpy(q, t, bytes); \
|
527
|
-
} \
|
528
|
-
free(t); \
|
529
|
-
} \
|
530
|
-
}
|
531
|
-
|
532
|
-
void ca_check_rand_init ();
|
533
|
-
|
534
|
-
/* rdoc:
|
535
|
-
class CArray
|
536
|
-
# shuffles the elements.
|
537
|
-
# If `self` has mask, the masked elements are also moved by shuffling.
|
538
|
-
def shuffle!
|
539
|
-
end
|
540
|
-
end
|
541
|
-
*/
|
542
|
-
|
543
|
-
static VALUE
|
544
|
-
rb_ca_shuffle_bang (VALUE self)
|
545
|
-
{
|
546
|
-
CArray *ca;
|
547
|
-
|
548
|
-
rb_ca_modify(self);
|
549
|
-
|
550
|
-
Data_Get_Struct(self, CArray, ca);
|
551
|
-
|
552
|
-
ca_check_rand_init();
|
553
|
-
|
554
|
-
ca_attach(ca);
|
555
|
-
|
556
|
-
switch ( ca->data_type ) {
|
557
|
-
case CA_BOOLEAN:
|
558
|
-
case CA_INT8: proc_shuffle(int8_t); break;
|
559
|
-
case CA_UINT8: proc_shuffle(uint8_t); break;
|
560
|
-
case CA_INT16: proc_shuffle(int16_t); break;
|
561
|
-
case CA_UINT16: proc_shuffle(uint16_t); break;
|
562
|
-
case CA_INT32: proc_shuffle(int32_t); break;
|
563
|
-
case CA_UINT32: proc_shuffle(uint32_t); break;
|
564
|
-
case CA_INT64: proc_shuffle(int64_t); break;
|
565
|
-
case CA_UINT64: proc_shuffle(uint64_t); break;
|
566
|
-
case CA_FLOAT32: proc_shuffle(float32_t); break;
|
567
|
-
case CA_FLOAT64: proc_shuffle(float64_t); break;
|
568
|
-
case CA_FLOAT128: proc_shuffle(float128_t); break;
|
569
|
-
#ifdef HAVE_COMPLEX_H
|
570
|
-
case CA_CMPLX64: proc_shuffle(cmplx64_t); break;
|
571
|
-
case CA_CMPLX128: proc_shuffle(cmplx128_t); break;
|
572
|
-
case CA_CMPLX256: proc_shuffle(cmplx256_t); break;
|
573
|
-
#endif
|
574
|
-
case CA_FIXLEN: proc_shuffle_fixlen(); break;
|
575
|
-
case CA_OBJECT: proc_shuffle(VALUE); break;
|
576
|
-
default:
|
577
|
-
rb_raise(rb_eCADataTypeError, "[BUG] array has an unknown data type");
|
578
|
-
}
|
579
|
-
|
580
|
-
ca_sync(ca);
|
581
|
-
ca_detach(ca);
|
582
|
-
|
583
|
-
return self;
|
584
|
-
}
|
585
|
-
|
586
|
-
/* rdoc:
|
587
|
-
class CArray
|
588
|
-
def shuffle
|
589
|
-
end
|
590
|
-
end
|
591
|
-
*/
|
592
|
-
|
593
|
-
static VALUE
|
594
|
-
rb_ca_shuffled_copy (VALUE self)
|
595
|
-
{
|
596
|
-
volatile VALUE out = rb_ca_copy(self);
|
597
|
-
rb_ca_data_type_inherit(out, self);
|
598
|
-
return rb_ca_shuffle_bang(out);
|
599
|
-
}
|
600
452
|
|
601
453
|
/* --------------------------------------------------------------- */
|
602
454
|
|
@@ -641,7 +493,7 @@ rb_ca_binary_search (VALUE self, volatile VALUE rval)
|
|
641
493
|
if ( ca->data_type != cv->data_type ) {
|
642
494
|
cv = ca_wrap_readonly(rval, ca->data_type);
|
643
495
|
}
|
644
|
-
co = carray_new(CA_SIZE, cv->
|
496
|
+
co = carray_new(CA_SIZE, cv->ndim, cv->dim, 0, NULL);
|
645
497
|
out = ca_wrap_struct(co);
|
646
498
|
ca_attach(cv);
|
647
499
|
if ( ca_is_fixlen_type(ca) ) {
|
@@ -1024,9 +876,6 @@ Init_carray_order ()
|
|
1024
876
|
rb_define_method(rb_cCArray, "sort!", rb_ca_sort_bang, 0);
|
1025
877
|
rb_define_method(rb_cCArray, "sort", rb_ca_sorted_copy, 0);
|
1026
878
|
|
1027
|
-
rb_define_method(rb_cCArray, "shuffle!", rb_ca_shuffle_bang, 0);
|
1028
|
-
rb_define_method(rb_cCArray, "shuffle", rb_ca_shuffled_copy, 0);
|
1029
|
-
|
1030
879
|
rb_define_method(rb_cCArray, "search", rb_ca_linear_search, -1);
|
1031
880
|
rb_define_method(rb_cCArray, "search_index", rb_ca_linear_search_index, -1);
|
1032
881
|
|
File without changes
|
@@ -293,10 +293,10 @@ rb_ca_cumprod (int argc, VALUE *argv, VALUE self)
|
|
293
293
|
Data_Get_Struct(self, CArray, ca);
|
294
294
|
|
295
295
|
if ( ca_is_complex_type(ca) ) {
|
296
|
-
co = carray_new(CA_CMPLX128, ca->
|
296
|
+
co = carray_new(CA_CMPLX128, ca->ndim, ca->dim, 0, NULL);
|
297
297
|
}
|
298
298
|
else {
|
299
|
-
co = carray_new(CA_FLOAT64, ca->
|
299
|
+
co = carray_new(CA_FLOAT64, ca->ndim, ca->dim, 0, NULL);
|
300
300
|
}
|
301
301
|
|
302
302
|
min_count = ( NIL_P(rmin_count) || ! ca_has_mask(ca) ) ?
|
@@ -504,10 +504,10 @@ rb_ca_cumwsum (int argc, VALUE *argv, VALUE self)
|
|
504
504
|
}
|
505
505
|
|
506
506
|
if ( ca_is_complex_type(ca) ) {
|
507
|
-
co = carray_new(CA_CMPLX128, ca->
|
507
|
+
co = carray_new(CA_CMPLX128, ca->ndim, ca->dim, 0, NULL);
|
508
508
|
}
|
509
509
|
else {
|
510
|
-
co = carray_new(CA_FLOAT64, ca->
|
510
|
+
co = carray_new(CA_FLOAT64, ca->ndim, ca->dim, 0, NULL);
|
511
511
|
}
|
512
512
|
|
513
513
|
min_count = ( NIL_P(rmin_count) || ( ! ca_has_mask(ca) ) ) ?
|
@@ -2029,7 +2029,7 @@ rb_ca_grade (int argc, VALUE *argv, VALUE self)
|
|
2029
2029
|
rb_raise(rb_eArgError, "bin number must be larger than 1");
|
2030
2030
|
}
|
2031
2031
|
|
2032
|
-
out = rb_carray_new_safe(CA_SIZE, ca->
|
2032
|
+
out = rb_carray_new_safe(CA_SIZE, ca->ndim, ca->dim, 0, NULL);
|
2033
2033
|
Data_Get_Struct(out, CArray, sa);
|
2034
2034
|
|
2035
2035
|
ca_attach(ca);
|