carray 1.5.2 → 1.5.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +32 -0
  3. data/NEWS.md +26 -3
  4. data/Rakefile +1 -1
  5. data/TODO.md +5 -4
  6. data/carray.gemspec +7 -5
  7. data/ext/ca_obj_bitarray.c +4 -7
  8. data/ext/ca_obj_bitfield.c +3 -5
  9. data/ext/ca_obj_block.c +1 -6
  10. data/ext/ca_obj_unbound_repeat.c +21 -52
  11. data/ext/carray_attribute.c +16 -1
  12. data/ext/carray_core.c +22 -16
  13. data/ext/carray_math.rb +20 -2
  14. data/ext/carray_numeric.c +32 -51
  15. data/ext/carray_test.c +9 -0
  16. data/ext/carray_undef.c +0 -8
  17. data/ext/version.h +4 -4
  18. data/lib/carray.rb +1 -3
  19. data/lib/carray/autoload.rb +0 -2
  20. data/lib/carray/basic.rb +1 -3
  21. data/lib/carray/broadcast.rb +58 -21
  22. data/lib/carray/compose.rb +34 -10
  23. data/lib/carray/construct.rb +1 -3
  24. data/lib/carray/info.rb +1 -3
  25. data/lib/carray/inspect.rb +3 -5
  26. data/lib/carray/io/imagemagick.rb +1 -3
  27. data/lib/carray/iterator.rb +2 -3
  28. data/lib/carray/mask.rb +18 -7
  29. data/lib/carray/math.rb +4 -6
  30. data/lib/carray/math/histogram.rb +1 -3
  31. data/lib/carray/math/recurrence.rb +1 -3
  32. data/lib/carray/mkmf.rb +1 -3
  33. data/lib/carray/object/ca_obj_iterator.rb +1 -3
  34. data/lib/carray/object/ca_obj_link.rb +1 -3
  35. data/lib/carray/object/ca_obj_pack.rb +1 -3
  36. data/lib/carray/obsolete.rb +1 -3
  37. data/lib/carray/ordering.rb +1 -3
  38. data/lib/carray/serialize.rb +22 -13
  39. data/lib/carray/string.rb +1 -3
  40. data/lib/carray/struct.rb +3 -5
  41. data/lib/carray/testing.rb +5 -10
  42. data/lib/carray/time.rb +1 -3
  43. data/lib/carray/transform.rb +1 -3
  44. data/spec/Classes/CAUnboudRepeat_spec.rb +24 -0
  45. data/spec/Features/feature_boolean_spec.rb +15 -14
  46. data/spec/Features/feature_broadcast.rb +16 -0
  47. data/spec/Features/feature_mask_spec.rb +6 -0
  48. metadata +12 -10
@@ -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
- ALL_TYPES =>"(#3) = (#1) > (#2) ? (#1) : (#2);",
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
- ALL_TYPES =>"(#3) = (#1) < (#2) ? (#1) : (#2);",
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",
@@ -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
- VALUE
28
- rb_num_nan (VALUE self)
29
- {
30
- return CA_NAN;
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, rb_intern("bit_or"), 1, x);
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, rb_intern("bit_and"), 1, x);
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, rb_intern("bit_xor"), 1, x);
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, rb_intern("<<"));
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, rb_intern(">>"));
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__ = rb_intern("__or__");
201
- id___and__ = rb_intern("__and__");
202
- id___xor__ = rb_intern("__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
- #if RUBY_VERSION_CODE >= 240
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);
@@ -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
  }
@@ -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
 
@@ -8,9 +8,9 @@
8
8
 
9
9
  ---------------------------------------------------------------------------- */
10
10
 
11
- #define CA_VERSION "1.5.2"
12
- #define CA_VERSION_CODE 152
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 2
16
- #define CA_VERSION_DATE "2020/07/22"
15
+ #define CA_VERSION_TEENY 3
16
+ #define CA_VERSION_DATE "2020/07/31"
@@ -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
 
@@ -3,8 +3,6 @@
3
3
  # carray/autoload.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
7
  # Copyright (C) 2005-2010 Hiroki Motoyoshi
10
8
  #
@@ -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
 
@@ -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
- def broadcast_to (*new_dim)
4
- if new_dim.size < ndim
5
- raise "can't broadcast to #{new_dim.inspect} because of mismatch in rank"
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
- flag_unbound_repeat = false
8
- sdim = []
9
- ([1]*(new_dim.size-ndim) + dim).each_with_index do |d, k|
10
- if new_dim[k] == 1
11
- sdim << 1
12
- elsif d == 1
13
- flag_unbound_repeat = true
14
- sdim << :*
15
- elsif d != new_dim[k]
16
- raise "can't broadcast to #{new_dim.inspect} because of mismatch in #{d} for #{new_dim[k]} in #{k}th dim"
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
- sdim << nil
41
+ raise "(Broadcasting) can't broadcast to #{newdim.inspect} "
19
42
  end
43
+ dd = dstdim.pop
20
44
  end
21
- return self[*sdim].bind(*new_dim) if flag_unbound_repeat
22
- return self
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
- def broadcast_to (*new_dim)
28
- return self
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
- return argv.map{|arg| arg.is_a?(CArray) ? arg.broadcast_to(*dim) : arg }
79
+
80
+ argv.map { |arg| arg.is_a?(CArray) ? arg.broadcast_to(*dim) : arg }
45
81
  end
82
+
@@ -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