carray 1.5.2 → 1.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.yardopts +32 -0
- data/NEWS.md +26 -3
- data/Rakefile +1 -1
- data/TODO.md +5 -4
- data/carray.gemspec +7 -5
- data/ext/ca_obj_bitarray.c +4 -7
- data/ext/ca_obj_bitfield.c +3 -5
- data/ext/ca_obj_block.c +1 -6
- data/ext/ca_obj_unbound_repeat.c +21 -52
- data/ext/carray_attribute.c +16 -1
- data/ext/carray_core.c +22 -16
- data/ext/carray_math.rb +20 -2
- data/ext/carray_numeric.c +32 -51
- data/ext/carray_test.c +9 -0
- data/ext/carray_undef.c +0 -8
- data/ext/version.h +4 -4
- data/lib/carray.rb +1 -3
- data/lib/carray/autoload.rb +0 -2
- data/lib/carray/basic.rb +1 -3
- data/lib/carray/broadcast.rb +58 -21
- data/lib/carray/compose.rb +34 -10
- data/lib/carray/construct.rb +1 -3
- data/lib/carray/info.rb +1 -3
- data/lib/carray/inspect.rb +3 -5
- data/lib/carray/io/imagemagick.rb +1 -3
- data/lib/carray/iterator.rb +2 -3
- data/lib/carray/mask.rb +18 -7
- data/lib/carray/math.rb +4 -6
- data/lib/carray/math/histogram.rb +1 -3
- data/lib/carray/math/recurrence.rb +1 -3
- data/lib/carray/mkmf.rb +1 -3
- data/lib/carray/object/ca_obj_iterator.rb +1 -3
- data/lib/carray/object/ca_obj_link.rb +1 -3
- data/lib/carray/object/ca_obj_pack.rb +1 -3
- data/lib/carray/obsolete.rb +1 -3
- data/lib/carray/ordering.rb +1 -3
- data/lib/carray/serialize.rb +22 -13
- data/lib/carray/string.rb +1 -3
- data/lib/carray/struct.rb +3 -5
- data/lib/carray/testing.rb +5 -10
- data/lib/carray/time.rb +1 -3
- data/lib/carray/transform.rb +1 -3
- data/spec/Classes/CAUnboudRepeat_spec.rb +24 -0
- data/spec/Features/feature_boolean_spec.rb +15 -14
- data/spec/Features/feature_broadcast.rb +16 -0
- data/spec/Features/feature_mask_spec.rb +6 -0
- metadata +12 -10
data/ext/carray_math.rb
CHANGED
@@ -155,6 +155,10 @@ monfunc("exp", "exp",
|
|
155
155
|
FLOAT_TYPES => "(#2) = exp(#1);",
|
156
156
|
CMPLX_TYPES => HAVE_COMPLEX ? "(#2) = cexp(#1);" : nil,
|
157
157
|
OBJ_TYPES => '(#2) = rb_funcall((#1), rb_intern("exp"), 0);')
|
158
|
+
monfunc("exp2", "exp2",
|
159
|
+
FLOAT_TYPES => "(#2) = exp2(#1);",
|
160
|
+
CMPLX_TYPES => HAVE_COMPLEX ? "(#2) = cpow(2, (#1));" : nil,
|
161
|
+
OBJ_TYPES => '(#2) = rb_funcall((#1), rb_intern("exp2"), 0);')
|
158
162
|
monfunc("exp10", "exp10",
|
159
163
|
FLOAT_TYPES => "(#2) = pow(10, (#1));",
|
160
164
|
CMPLX_TYPES => HAVE_COMPLEX ? "(#2) = cpow(10, (#1));" : nil,
|
@@ -166,6 +170,12 @@ monfunc("log", "log",
|
|
166
170
|
monfunc("log10", "log10",
|
167
171
|
FLOAT_TYPES => "(#2) = log10(#1);",
|
168
172
|
OBJ_TYPES => '(#2) = rb_funcall((#1), rb_intern("log10"), 0);')
|
173
|
+
monfunc("log2", "log2",
|
174
|
+
FLOAT_TYPES => "(#2) = log2(#1);",
|
175
|
+
OBJ_TYPES => '(#2) = rb_funcall((#1), rb_intern("log2"), 0);')
|
176
|
+
monfunc("logb", "logb",
|
177
|
+
FLOAT_TYPES => "(#2) = logb(#1);",
|
178
|
+
OBJ_TYPES => '(#2) = rb_funcall((#1), rb_intern("logb"), 0);')
|
169
179
|
monfunc("sin", "sin",
|
170
180
|
FLOAT_TYPES => "(#2) = sin(#1);",
|
171
181
|
CMPLX_TYPES => HAVE_COMPLEX ? "(#2) = csin(#1);" : nil,
|
@@ -217,12 +227,14 @@ monfunc("atanh", "atanh",
|
|
217
227
|
|
218
228
|
|
219
229
|
binop("pmax", "pmax",
|
220
|
-
|
230
|
+
INT_TYPES =>"(#3) = (#1) > (#2) ? (#1) : (#2);",
|
231
|
+
FLOAT_TYPES =>"(#3) = fmax(#1, #2);",
|
221
232
|
CMPLX_TYPES => nil,
|
222
233
|
OBJ_TYPES =>'(#3) = rb_funcall(rb_assoc_new((#1),(#2)), rb_intern("max"), 0);')
|
223
234
|
|
224
235
|
binop("pmin", "pmin",
|
225
|
-
|
236
|
+
INT_TYPES =>"(#3) = (#1) < (#2) ? (#1) : (#2);",
|
237
|
+
FLOAT_TYPES =>"(#3) = fmin(#1, #2);",
|
226
238
|
CMPLX_TYPES => nil,
|
227
239
|
OBJ_TYPES =>'(#3) = rb_funcall(rb_assoc_new((#1),(#2)), rb_intern("min"), 0);')
|
228
240
|
|
@@ -258,6 +270,12 @@ binop("rcp_mul", "rcp_mul",
|
|
258
270
|
|
259
271
|
binop("%", "mod",
|
260
272
|
INT_TYPES => "if ((#2)==0) {ca_zerodiv();}; (#3) = (#1) % (#2);",
|
273
|
+
FLOAT_TYPES => "(#3) = fmod(#1, #2);",
|
274
|
+
OBJ_TYPES => '(#3) = rb_funcall((#1), id_percent, 1, (#2));')
|
275
|
+
|
276
|
+
binop("reminder", "reminder",
|
277
|
+
INT_TYPES => "if ((#2)==0) {ca_zerodiv();}; (#3) = (#1) % (#2);",
|
278
|
+
FLOAT_TYPES => "(#3) = remainder(#1, #2);",
|
261
279
|
OBJ_TYPES => '(#3) = rb_funcall((#1), id_percent, 1, (#2));')
|
262
280
|
|
263
281
|
binop("&", "bit_and_i",
|
data/ext/carray_numeric.c
CHANGED
@@ -11,11 +11,6 @@
|
|
11
11
|
#include "ruby.h"
|
12
12
|
#include "carray.h"
|
13
13
|
|
14
|
-
#if RUBY_VERSION_CODE >= 240
|
15
|
-
# define rb_cFixnum rb_cInteger
|
16
|
-
# define rb_cBignum rb_cInteger
|
17
|
-
#endif
|
18
|
-
|
19
14
|
VALUE CA_NAN, CA_INF;
|
20
15
|
|
21
16
|
static ID id___or__;
|
@@ -24,24 +19,18 @@ static ID id___xor__;
|
|
24
19
|
static ID id___rshift__;
|
25
20
|
static ID id___lshift__;
|
26
21
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
VALUE
|
34
|
-
rb_num_inf (VALUE self)
|
35
|
-
{
|
36
|
-
return CA_INF;
|
37
|
-
}
|
22
|
+
static ID id_bit_or;
|
23
|
+
static ID id_bit_and;
|
24
|
+
static ID id_bit_xor;
|
25
|
+
static ID id_lshift;
|
26
|
+
static ID id_rshift;
|
38
27
|
|
39
28
|
static VALUE
|
40
29
|
rb_hack_or(VALUE x, VALUE y)
|
41
30
|
{
|
42
31
|
if ( rb_obj_is_carray(y) ) {
|
43
32
|
if ( rb_ca_is_boolean_type(y) ) {
|
44
|
-
return rb_funcall(y,
|
33
|
+
return rb_funcall(y, id_bit_or, 1, x);
|
45
34
|
}
|
46
35
|
else {
|
47
36
|
#if RUBY_VERSION_CODE >= 190
|
@@ -61,7 +50,7 @@ rb_hack_and (VALUE x, VALUE y)
|
|
61
50
|
{
|
62
51
|
if ( rb_obj_is_carray(y) ) {
|
63
52
|
if ( rb_ca_is_boolean_type(y) ) {
|
64
|
-
return rb_funcall(y,
|
53
|
+
return rb_funcall(y, id_bit_and, 1, x);
|
65
54
|
}
|
66
55
|
else {
|
67
56
|
#if RUBY_VERSION_CODE >= 190
|
@@ -81,7 +70,7 @@ rb_hack_xor (VALUE x, VALUE y)
|
|
81
70
|
{
|
82
71
|
if ( rb_obj_is_carray(y) ) {
|
83
72
|
if ( rb_ca_is_boolean_type(y) ) {
|
84
|
-
return rb_funcall(y,
|
73
|
+
return rb_funcall(y, id_bit_xor, 1, x);
|
85
74
|
}
|
86
75
|
else {
|
87
76
|
#if RUBY_VERSION_CODE >= 190
|
@@ -101,7 +90,7 @@ rb_hack_lshift (VALUE x, VALUE y)
|
|
101
90
|
{
|
102
91
|
if ( rb_obj_is_carray(y) ) {
|
103
92
|
#if RUBY_VERSION_CODE >= 190
|
104
|
-
return rb_num_coerce_bin(x, y,
|
93
|
+
return rb_num_coerce_bin(x, y, id_lshift);
|
105
94
|
#else
|
106
95
|
return rb_num_coerce_bin(x, y);
|
107
96
|
#endif
|
@@ -116,7 +105,7 @@ rb_hack_rshift (VALUE x, VALUE y)
|
|
116
105
|
{
|
117
106
|
if ( rb_obj_is_carray(y) ) {
|
118
107
|
#if RUBY_VERSION_CODE >= 190
|
119
|
-
return rb_num_coerce_bin(x, y,
|
108
|
+
return rb_num_coerce_bin(x, y, id_rshift);
|
120
109
|
#else
|
121
110
|
return rb_num_coerce_bin(x, y);
|
122
111
|
#endif
|
@@ -126,12 +115,6 @@ rb_hack_rshift (VALUE x, VALUE y)
|
|
126
115
|
}
|
127
116
|
}
|
128
117
|
|
129
|
-
static VALUE
|
130
|
-
rb_hack_star (VALUE x, VALUE y)
|
131
|
-
{
|
132
|
-
return rb_funcall(y, rb_intern("*"), 1, x);
|
133
|
-
}
|
134
|
-
|
135
118
|
/* ------------------------------------------------------------------- */
|
136
119
|
|
137
120
|
#ifdef HAVE_COMPLEX_H
|
@@ -197,35 +180,51 @@ Init_carray_numeric ()
|
|
197
180
|
{
|
198
181
|
/* hack Fixnum and Bignum's "|", "&", "^", "<<", ">>" */
|
199
182
|
|
200
|
-
id___or__
|
201
|
-
id___and__
|
202
|
-
id___xor__
|
183
|
+
id___or__ = rb_intern("__or__");
|
184
|
+
id___and__ = rb_intern("__and__");
|
185
|
+
id___xor__ = rb_intern("__xor__");
|
203
186
|
id___rshift__ = rb_intern("__rshift__");
|
204
187
|
id___lshift__ = rb_intern("__lshift__");
|
205
188
|
|
189
|
+
id_bit_or = rb_intern("bit_or");
|
190
|
+
id_bit_and = rb_intern("bit_and");
|
191
|
+
id_bit_xor = rb_intern("bit_xor");
|
192
|
+
id_lshift = rb_intern("<<");
|
193
|
+
id_rshift = rb_intern(">>");
|
194
|
+
|
206
195
|
CA_NAN = rb_float_new(0.0/0.0);
|
207
196
|
CA_INF = rb_float_new(1.0/0.0);
|
208
197
|
rb_define_const(rb_cObject, "CA_NAN", CA_NAN);
|
209
198
|
rb_define_const(rb_cObject, "CA_INF", CA_INF);
|
210
|
-
rb_define_global_function("nan", rb_num_nan, 0);
|
211
|
-
rb_define_global_function("inf", rb_num_inf, 0);
|
212
199
|
|
213
200
|
rb_define_alias(rb_cTrueClass, "__or__", "|");
|
214
201
|
rb_define_alias(rb_cTrueClass, "__and__", "&");
|
215
202
|
rb_define_alias(rb_cTrueClass, "__xor__", "^");
|
216
203
|
|
204
|
+
rb_define_method(rb_cTrueClass, "|", rb_hack_or, 1);
|
205
|
+
rb_define_method(rb_cTrueClass, "&", rb_hack_and, 1);
|
206
|
+
rb_define_method(rb_cTrueClass, "^", rb_hack_xor, 1);
|
207
|
+
|
217
208
|
rb_define_alias(rb_cFalseClass, "__or__", "|");
|
218
209
|
rb_define_alias(rb_cFalseClass, "__and__", "&");
|
219
210
|
rb_define_alias(rb_cFalseClass, "__xor__", "^");
|
220
211
|
|
221
|
-
|
212
|
+
rb_define_method(rb_cFalseClass, "|", rb_hack_or, 1);
|
213
|
+
rb_define_method(rb_cFalseClass, "&", rb_hack_and, 1);
|
214
|
+
rb_define_method(rb_cFalseClass, "^", rb_hack_xor, 1);
|
222
215
|
|
216
|
+
#if RUBY_VERSION_CODE >= 240
|
223
217
|
rb_define_alias(rb_cInteger, "__or__", "|");
|
224
218
|
rb_define_alias(rb_cInteger, "__and__", "&");
|
225
219
|
rb_define_alias(rb_cInteger, "__xor__", "^");
|
226
220
|
rb_define_alias(rb_cInteger, "__lshift__", "<<");
|
227
221
|
rb_define_alias(rb_cInteger, "__rshift__", ">>");
|
228
222
|
|
223
|
+
rb_define_method(rb_cInteger, "|", rb_hack_or, 1);
|
224
|
+
rb_define_method(rb_cInteger, "&", rb_hack_and, 1);
|
225
|
+
rb_define_method(rb_cInteger, "^", rb_hack_xor, 1);
|
226
|
+
rb_define_method(rb_cInteger, "<<", rb_hack_lshift, 1);
|
227
|
+
rb_define_method(rb_cInteger, ">>", rb_hack_rshift, 1);
|
229
228
|
#else
|
230
229
|
rb_define_alias(rb_cFixnum, "__or__", "|");
|
231
230
|
rb_define_alias(rb_cFixnum, "__and__", "&");
|
@@ -238,25 +237,7 @@ Init_carray_numeric ()
|
|
238
237
|
rb_define_alias(rb_cBignum, "__xor__", "^");
|
239
238
|
rb_define_alias(rb_cBignum, "__lshift__", "<<");
|
240
239
|
rb_define_alias(rb_cBignum, "__rshift__", ">>");
|
241
|
-
#endif
|
242
240
|
|
243
|
-
rb_define_method(rb_cTrueClass, "|", rb_hack_or, 1);
|
244
|
-
rb_define_method(rb_cTrueClass, "&", rb_hack_and, 1);
|
245
|
-
rb_define_method(rb_cTrueClass, "^", rb_hack_xor, 1);
|
246
|
-
rb_define_method(rb_cTrueClass, "*", rb_hack_star, 1);
|
247
|
-
|
248
|
-
rb_define_method(rb_cFalseClass, "|", rb_hack_or, 1);
|
249
|
-
rb_define_method(rb_cFalseClass, "&", rb_hack_and, 1);
|
250
|
-
rb_define_method(rb_cFalseClass, "^", rb_hack_xor, 1);
|
251
|
-
rb_define_method(rb_cFalseClass, "*", rb_hack_star, 1);
|
252
|
-
|
253
|
-
#if RUBY_VERSION_CODE >= 240
|
254
|
-
rb_define_method(rb_cInteger, "|", rb_hack_or, 1);
|
255
|
-
rb_define_method(rb_cInteger, "&", rb_hack_and, 1);
|
256
|
-
rb_define_method(rb_cInteger, "^", rb_hack_xor, 1);
|
257
|
-
rb_define_method(rb_cInteger, "<<", rb_hack_lshift, 1);
|
258
|
-
rb_define_method(rb_cInteger, ">>", rb_hack_rshift, 1);
|
259
|
-
#else
|
260
241
|
rb_define_method(rb_cFixnum, "|", rb_hack_or, 1);
|
261
242
|
rb_define_method(rb_cFixnum, "&", rb_hack_and, 1);
|
262
243
|
rb_define_method(rb_cFixnum, "^", rb_hack_xor, 1);
|
data/ext/carray_test.c
CHANGED
@@ -216,6 +216,12 @@ rb_obj_is_data_class (VALUE rtype)
|
|
216
216
|
return Qfalse;
|
217
217
|
}
|
218
218
|
|
219
|
+
static VALUE
|
220
|
+
rb_ca_s_is_data_class (VALUE self, VALUE rklass)
|
221
|
+
{
|
222
|
+
return rb_obj_is_data_class(rklass);
|
223
|
+
}
|
224
|
+
|
219
225
|
/* ------------------------------------------------------------- */
|
220
226
|
|
221
227
|
/* @overload valid_index? (*idx)
|
@@ -598,4 +604,7 @@ Init_carray_test ()
|
|
598
604
|
rb_define_method(rb_cCArray, "==", rb_ca_equal, 1);
|
599
605
|
rb_define_alias(rb_cCArray, "eql?", "==");
|
600
606
|
rb_define_method(rb_cCArray, "hash", rb_ca_hash, 0);
|
607
|
+
|
608
|
+
rb_define_singleton_method(rb_cCArray, "data_class?", rb_ca_s_is_data_class, 1);
|
609
|
+
|
601
610
|
}
|
data/ext/carray_undef.c
CHANGED
@@ -41,12 +41,6 @@ static VALUE rb_ud_equal (VALUE self, VALUE other)
|
|
41
41
|
return ( self == other ) ? Qtrue : Qfalse;
|
42
42
|
}
|
43
43
|
|
44
|
-
|
45
|
-
static VALUE rb_obj_is_undef (VALUE self)
|
46
|
-
{
|
47
|
-
return ( self == CA_UNDEF ) ? Qtrue : Qfalse;
|
48
|
-
}
|
49
|
-
|
50
44
|
void
|
51
45
|
Init_carray_undef ()
|
52
46
|
{
|
@@ -61,7 +55,5 @@ Init_carray_undef ()
|
|
61
55
|
CA_UNDEF = rb_funcall(rb_cUNDEF, rb_intern("new"), 0);
|
62
56
|
rb_undef_method(CLASS_OF(rb_cUNDEF), "new");
|
63
57
|
rb_const_set(rb_cObject, rb_intern("UNDEF"), CA_UNDEF);
|
64
|
-
|
65
|
-
rb_define_method(rb_cObject, "undef?", rb_obj_is_undef, 0);
|
66
58
|
}
|
67
59
|
|
data/ext/version.h
CHANGED
@@ -8,9 +8,9 @@
|
|
8
8
|
|
9
9
|
---------------------------------------------------------------------------- */
|
10
10
|
|
11
|
-
#define CA_VERSION "1.5.
|
12
|
-
#define CA_VERSION_CODE
|
11
|
+
#define CA_VERSION "1.5.3"
|
12
|
+
#define CA_VERSION_CODE 153
|
13
13
|
#define CA_VERSION_MAJOR 1
|
14
14
|
#define CA_VERSION_MINOR 5
|
15
|
-
#define CA_VERSION_TEENY
|
16
|
-
#define CA_VERSION_DATE "2020/07/
|
15
|
+
#define CA_VERSION_TEENY 3
|
16
|
+
#define CA_VERSION_DATE "2020/07/31"
|
data/lib/carray.rb
CHANGED
@@ -3,10 +3,8 @@
|
|
3
3
|
# lib/carray.rb
|
4
4
|
#
|
5
5
|
# This file is part of Ruby/CArray extension library.
|
6
|
-
# You can redistribute it and/or modify it under the terms of
|
7
|
-
# the Ruby Licence.
|
8
6
|
#
|
9
|
-
# Copyright (C) 2005 Hiroki Motoyoshi
|
7
|
+
# Copyright (C) 2005-2020 Hiroki Motoyoshi
|
10
8
|
#
|
11
9
|
# ----------------------------------------------------------------------------
|
12
10
|
|
data/lib/carray/autoload.rb
CHANGED
data/lib/carray/basic.rb
CHANGED
@@ -3,10 +3,8 @@
|
|
3
3
|
# carray/basic.rb
|
4
4
|
#
|
5
5
|
# This file is part of Ruby/CArray extension library.
|
6
|
-
# You can redistribute it and/or modify it under the terms of
|
7
|
-
# the Ruby Licence.
|
8
6
|
#
|
9
|
-
# Copyright (C) 2005 Hiroki Motoyoshi
|
7
|
+
# Copyright (C) 2005-2020 Hiroki Motoyoshi
|
10
8
|
#
|
11
9
|
# ----------------------------------------------------------------------------
|
12
10
|
|
data/lib/carray/broadcast.rb
CHANGED
@@ -1,45 +1,82 @@
|
|
1
|
+
# ----------------------------------------------------------------------------
|
2
|
+
#
|
3
|
+
# carray/broadcast.rb
|
4
|
+
#
|
5
|
+
# This file is part of Ruby/CArray extension library.
|
6
|
+
#
|
7
|
+
# Copyright (C) 2005-2020 Hiroki Motoyoshi
|
8
|
+
#
|
9
|
+
# ----------------------------------------------------------------------------
|
1
10
|
|
2
11
|
class CArray
|
3
|
-
|
4
|
-
|
5
|
-
|
12
|
+
|
13
|
+
def broadcast_to (*newdim)
|
14
|
+
|
15
|
+
if newdim.size < ndim
|
16
|
+
raise "(Broadcasting) can't broadcast to #{newdim.inspect} because too small rank is specified"
|
6
17
|
end
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
18
|
+
|
19
|
+
#
|
20
|
+
# Try to build unbound repeat index (includes :*)
|
21
|
+
# with broadcasting rule in Numpy.
|
22
|
+
#
|
23
|
+
repdim = []
|
24
|
+
shape = []
|
25
|
+
|
26
|
+
srcdim = dim.dup
|
27
|
+
dstdim = newdim.dup
|
28
|
+
sd = srcdim.pop
|
29
|
+
dd = dstdim.pop
|
30
|
+
while dd
|
31
|
+
if sd == dd
|
32
|
+
repdim.unshift nil
|
33
|
+
shape.unshift(dd)
|
34
|
+
sd = srcdim.pop
|
35
|
+
elsif dd == 1
|
36
|
+
repdim.unshift :*
|
37
|
+
elsif sd == 1
|
38
|
+
repdim.unshift :*
|
39
|
+
sd = srcdim.pop
|
17
40
|
else
|
18
|
-
|
41
|
+
raise "(Broadcasting) can't broadcast to #{newdim.inspect} "
|
19
42
|
end
|
43
|
+
dd = dstdim.pop
|
20
44
|
end
|
21
|
-
|
22
|
-
|
45
|
+
|
46
|
+
#
|
47
|
+
# Call Unbound repeat's bind
|
48
|
+
#
|
49
|
+
return self.reshape(*shape)[*repdim].bind(*newdim) if repdim.include?(:*)
|
50
|
+
|
51
|
+
self
|
23
52
|
end
|
53
|
+
|
24
54
|
end
|
25
55
|
|
26
56
|
class CScalar
|
27
|
-
|
28
|
-
|
57
|
+
|
58
|
+
def broadcast_to (*newdim)
|
59
|
+
self
|
29
60
|
end
|
61
|
+
|
30
62
|
end
|
31
63
|
|
32
64
|
class CAUnboundRepeat
|
65
|
+
|
33
66
|
alias broadcast_to bind
|
67
|
+
|
34
68
|
end
|
35
69
|
|
36
70
|
def CArray.broadcast (*argv)
|
37
|
-
sel = argv.select {|arg| arg.is_a?(CArray) }
|
71
|
+
sel = argv.select { |arg| arg.is_a?(CArray) }
|
38
72
|
return argv if sel.empty?
|
73
|
+
|
39
74
|
dim = []
|
40
75
|
ndim = sel.map(&:ndim).max
|
41
76
|
ndim.times do |k|
|
42
|
-
dim[k] = sel.map{|arg| arg.dim[k] || 1 }.max
|
77
|
+
dim[k] = sel.map { |arg| arg.dim[k] || 1 }.max
|
43
78
|
end
|
44
|
-
|
79
|
+
|
80
|
+
argv.map { |arg| arg.is_a?(CArray) ? arg.broadcast_to(*dim) : arg }
|
45
81
|
end
|
82
|
+
|
data/lib/carray/compose.rb
CHANGED
@@ -3,10 +3,8 @@
|
|
3
3
|
# carray/composition.rb
|
4
4
|
#
|
5
5
|
# This file is part of Ruby/CArray extension library.
|
6
|
-
# You can redistribute it and/or modify it under the terms of
|
7
|
-
# the Ruby Licence.
|
8
6
|
#
|
9
|
-
# Copyright (C) 2005 Hiroki Motoyoshi
|
7
|
+
# Copyright (C) 2005-2020 Hiroki Motoyoshi
|
10
8
|
#
|
11
9
|
# ----------------------------------------------------------------------------
|
12
10
|
|
@@ -34,6 +32,7 @@ class CArray
|
|
34
32
|
end
|
35
33
|
end
|
36
34
|
out = CArray.new(data_type, newdim, &block)
|
35
|
+
out.data_class = data_class if has_data_class?
|
37
36
|
if out.has_mask?
|
38
37
|
out.mask.paste(offset, self.false)
|
39
38
|
end
|
@@ -63,6 +62,7 @@ class CArray
|
|
63
62
|
grids[i][offset[i]..-1].seq!(offset[i]+bsize[i])
|
64
63
|
end
|
65
64
|
out = CArray.new(data_type, newdim)
|
65
|
+
out.data_class = data_class if has_data_class?
|
66
66
|
if block_given?
|
67
67
|
sel = out.true
|
68
68
|
sel[*grids] = 0
|
@@ -114,7 +114,14 @@ class CArray
|
|
114
114
|
return self[*grids].to_ca
|
115
115
|
end
|
116
116
|
|
117
|
-
def self.combine (data_type, tdim, list, at = 0)
|
117
|
+
def self.combine (data_type, tdim, list, at = 0, bytes: nil)
|
118
|
+
if CArray.data_class?(data_type)
|
119
|
+
data_class = data_type
|
120
|
+
data_type = :fixlen
|
121
|
+
bytes = data_class::DATA_SIZE
|
122
|
+
else
|
123
|
+
data_class = nil
|
124
|
+
end
|
118
125
|
has_fill_value = false
|
119
126
|
if block_given?
|
120
127
|
fill_value = yield
|
@@ -168,6 +175,7 @@ class CArray
|
|
168
175
|
else
|
169
176
|
obj = CArray.new(data_type, newdim)
|
170
177
|
end
|
178
|
+
out.data_class = data_class if data_class
|
171
179
|
idx = newdim.map{0}
|
172
180
|
block.each_with_index do |item, tidx|
|
173
181
|
(at...at+tndim).each_with_index do |d,i|
|
@@ -178,11 +186,18 @@ class CArray
|
|
178
186
|
obj
|
179
187
|
end
|
180
188
|
|
181
|
-
def self.bind (data_type, list, at = 0)
|
182
|
-
return CArray.combine(data_type, [list.size], list, at)
|
189
|
+
def self.bind (data_type, list, at = 0, bytes: nil)
|
190
|
+
return CArray.combine(data_type, [list.size], list, at, bytes: bytes)
|
183
191
|
end
|
184
192
|
|
185
|
-
def self.composite (data_type, tdim, list, at = 0)
|
193
|
+
def self.composite (data_type, tdim, list, at = 0, bytes: nil)
|
194
|
+
if CArray.data_class?(data_type)
|
195
|
+
data_class = data_type
|
196
|
+
data_type = :fixlen
|
197
|
+
bytes = data_class::DATA_SIZE
|
198
|
+
else
|
199
|
+
data_class = nil
|
200
|
+
end
|
186
201
|
if not tdim.is_a?(Array) or tdim.size == 0
|
187
202
|
raise "invalid tiling dimension"
|
188
203
|
end
|
@@ -213,7 +228,8 @@ class CArray
|
|
213
228
|
end
|
214
229
|
newdim = dim.clone
|
215
230
|
newdim[at,0] = tdim
|
216
|
-
obj = CArray.new(data_type, newdim)
|
231
|
+
obj = CArray.new(data_type, newdim, bytes: bytes)
|
232
|
+
out.data_class = data_class if data_class
|
217
233
|
idx = Array.new(ndim+tndim) { nil }
|
218
234
|
CArray.each_index(*tdim) do |*tidx|
|
219
235
|
idx[at,tndim] = tidx
|
@@ -222,13 +238,21 @@ class CArray
|
|
222
238
|
obj
|
223
239
|
end
|
224
240
|
|
225
|
-
def self.merge (data_type, list, at = -1)
|
226
|
-
return CArray.composite(data_type, [list.size], list, at)
|
241
|
+
def self.merge (data_type, list, at = -1, bytes: nil)
|
242
|
+
return CArray.composite(data_type, [list.size], list, at, bytes: bytes)
|
227
243
|
end
|
228
244
|
|
229
245
|
def self.join (*argv)
|
230
246
|
# get options
|
231
247
|
case argv.first
|
248
|
+
when Class
|
249
|
+
if CArray.data_class?(argv.first)
|
250
|
+
data_class = argv.shift
|
251
|
+
data_type = "fixlen"
|
252
|
+
bytes = data_class::DATA_SIZE
|
253
|
+
else
|
254
|
+
raise "#{argv.first} can not to be a data_class for CArray"
|
255
|
+
end
|
232
256
|
when Integer, Symbol, String
|
233
257
|
type, = *CArray.guess_type_and_bytes(argv.shift, 0)
|
234
258
|
else
|