carray 1.4.0 → 1.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (126) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSES +22 -0
  3. data/README.md +18 -14
  4. data/Rakefile +1 -1
  5. data/carray.gemspec +5 -13
  6. data/{ca_iter_block.c → ext/ca_iter_block.c} +13 -13
  7. data/{ca_iter_dimension.c → ext/ca_iter_dimension.c} +16 -16
  8. data/{ca_iter_window.c → ext/ca_iter_window.c} +10 -10
  9. data/{ca_obj_array.c → ext/ca_obj_array.c} +60 -55
  10. data/{ca_obj_bitarray.c → ext/ca_obj_bitarray.c} +12 -12
  11. data/{ca_obj_bitfield.c → ext/ca_obj_bitfield.c} +7 -7
  12. data/{ca_obj_block.c → ext/ca_obj_block.c} +42 -42
  13. data/{ca_obj_fake.c → ext/ca_obj_fake.c} +7 -7
  14. data/{ca_obj_farray.c → ext/ca_obj_farray.c} +18 -18
  15. data/{ca_obj_field.c → ext/ca_obj_field.c} +15 -15
  16. data/{ca_obj_grid.c → ext/ca_obj_grid.c} +27 -27
  17. data/{ca_obj_mapping.c → ext/ca_obj_mapping.c} +9 -9
  18. data/{ca_obj_object.c → ext/ca_obj_object.c} +37 -37
  19. data/{ca_obj_reduce.c → ext/ca_obj_reduce.c} +1 -1
  20. data/{ca_obj_refer.c → ext/ca_obj_refer.c} +33 -33
  21. data/{ca_obj_repeat.c → ext/ca_obj_repeat.c} +43 -43
  22. data/{ca_obj_select.c → ext/ca_obj_select.c} +2 -2
  23. data/{ca_obj_shift.c → ext/ca_obj_shift.c} +23 -23
  24. data/{ca_obj_transpose.c → ext/ca_obj_transpose.c} +23 -23
  25. data/{ca_obj_unbound_repeat.c → ext/ca_obj_unbound_repeat.c} +55 -55
  26. data/{ca_obj_window.c → ext/ca_obj_window.c} +26 -26
  27. data/{carray.h → ext/carray.h} +73 -51
  28. data/{carray_access.c → ext/carray_access.c} +83 -83
  29. data/{carray_attribute.c → ext/carray_attribute.c} +12 -12
  30. data/{carray_call_cfunc.c → ext/carray_call_cfunc.c} +0 -0
  31. data/{carray_cast.c → ext/carray_cast.c} +6 -6
  32. data/{carray_cast_func.rb → ext/carray_cast_func.rb} +0 -0
  33. data/{carray_class.c → ext/carray_class.c} +0 -0
  34. data/{carray_conversion.c → ext/carray_conversion.c} +8 -10
  35. data/{carray_copy.c → ext/carray_copy.c} +19 -19
  36. data/{carray_core.c → ext/carray_core.c} +2 -2
  37. data/ext/carray_data_type.c +66 -0
  38. data/{carray_element.c → ext/carray_element.c} +9 -9
  39. data/{carray_generate.c → ext/carray_generate.c} +0 -0
  40. data/{carray_iterator.c → ext/carray_iterator.c} +40 -38
  41. data/{carray_loop.c → ext/carray_loop.c} +24 -24
  42. data/{carray_mask.c → ext/carray_mask.c} +17 -6
  43. data/{carray_math.rb → ext/carray_math.rb} +3 -3
  44. data/ext/{mathfunc/carray_mathfunc.c → carray_mathfunc.c} +0 -0
  45. data/{carray_numeric.c → ext/carray_numeric.c} +1 -1
  46. data/{carray_operator.c → ext/carray_operator.c} +9 -9
  47. data/{carray_order.c → ext/carray_order.c} +2 -153
  48. data/{carray_sort_addr.c → ext/carray_sort_addr.c} +0 -0
  49. data/{carray_stat.c → ext/carray_stat.c} +5 -5
  50. data/{carray_stat_proc.rb → ext/carray_stat_proc.rb} +23 -23
  51. data/{carray_test.c → ext/carray_test.c} +22 -21
  52. data/{carray_undef.c → ext/carray_undef.c} +0 -0
  53. data/{carray_utils.c → ext/carray_utils.c} +0 -0
  54. data/{extconf.rb → ext/extconf.rb} +0 -5
  55. data/{mkmath.rb → ext/mkmath.rb} +0 -0
  56. data/{ruby_carray.c → ext/ruby_carray.c} +9 -2
  57. data/{ruby_ccomplex.c → ext/ruby_ccomplex.c} +0 -0
  58. data/{ruby_float_func.c → ext/ruby_float_func.c} +0 -0
  59. data/{version.h → ext/version.h} +5 -5
  60. data/{version.rb → ext/version.rb} +0 -0
  61. data/lib/carray.rb +48 -37
  62. data/lib/carray/{base/autoload.rb → autoload.rb} +1 -1
  63. data/lib/carray/autoload/autoload_base.rb +1 -1
  64. data/lib/carray/autoload/autoload_gem_numo_narray.rb +4 -3
  65. data/lib/carray/autoload/autoload_gem_random.rb +8 -0
  66. data/lib/carray/basic.rb +193 -0
  67. data/lib/carray/compose.rb +291 -0
  68. data/lib/carray/construct.rb +445 -0
  69. data/lib/carray/convert.rb +115 -0
  70. data/lib/carray/{base/inspect.rb → inspect.rb} +6 -6
  71. data/lib/carray/io/imagemagick.rb +1 -1
  72. data/lib/carray/{base/iterator.rb → iterator.rb} +3 -3
  73. data/lib/carray/mask.rb +91 -0
  74. data/lib/carray/{base/math.rb → math.rb} +16 -46
  75. data/lib/carray/math/histogram.rb +7 -7
  76. data/lib/carray/mkmf.rb +8 -0
  77. data/lib/carray/object/ca_obj_pack.rb +8 -8
  78. data/lib/carray/obsolete.rb +272 -0
  79. data/lib/carray/ordering.rb +157 -0
  80. data/lib/carray/{base/serialize.rb → serialize.rb} +28 -53
  81. data/lib/carray/{base/string.rb → string.rb} +12 -64
  82. data/lib/carray/{base/struct.rb → struct.rb} +16 -16
  83. data/lib/carray/{io/table.rb → table.rb} +1 -10
  84. data/lib/carray/testing.rb +56 -0
  85. data/lib/carray/time.rb +78 -0
  86. data/lib/carray/transform.rb +100 -0
  87. data/misc/Methods.ja.md +182 -0
  88. data/{NOTE → misc/NOTE} +0 -0
  89. data/test/test_ALL.rb +0 -2
  90. data/test/test_order.rb +7 -7
  91. data/test/test_ref_store.rb +13 -13
  92. data/test/test_stat.rb +7 -15
  93. data/{devel → utils}/guess_shape.rb +0 -0
  94. data/utils/{diff_method.rb → monkey_patch_methods.rb} +17 -7
  95. metadata +88 -151
  96. data/COPYING +0 -56
  97. data/GPL +0 -340
  98. data/LEGAL +0 -50
  99. data/TODO +0 -5
  100. data/carray_random.c +0 -531
  101. data/devel/im2col.rb +0 -17
  102. data/ext/calculus/carray_calculus.c +0 -931
  103. data/ext/calculus/carray_interp.c +0 -358
  104. data/ext/calculus/extconf.rb +0 -12
  105. data/ext/calculus/lib/math/calculus.rb +0 -119
  106. data/ext/calculus/lib/math/interp/adapter_interp1d.rb +0 -31
  107. data/ext/mathfunc/extconf.rb +0 -18
  108. data/ext/mathfunc/test/test_hypot.rb +0 -5
  109. data/ext/mathfunc/test/test_j0.rb +0 -22
  110. data/ext/mathfunc/test/test_jn.rb +0 -8
  111. data/ext/mathfunc/test/test_sph.rb +0 -9
  112. data/lib/carray/autoload/autoload_io_table.rb +0 -1
  113. data/lib/carray/autoload/autoload_math_interp.rb +0 -4
  114. data/lib/carray/base/basic.rb +0 -1146
  115. data/lib/carray/base/obsolete.rb +0 -131
  116. data/lib/carray/math/interp.rb +0 -57
  117. data/lib/carray/math/interp/adapter_gsl_spline.rb +0 -47
  118. data/mt19937ar.c +0 -182
  119. data/mt19937ar.h +0 -86
  120. data/rdoc_main.rb +0 -27
  121. data/rdoc_math.rb +0 -5
  122. data/rdoc_stat.rb +0 -31
  123. data/test/test_narray.rb +0 -64
  124. data/test/test_random.rb +0 -15
  125. data/utils/create_rdoc.sh +0 -9
  126. data/utils/make_tgz.sh +0 -3
File without changes
File without changes
@@ -189,11 +189,6 @@ if ( not File.exist?("carray_stat_proc.c") ) or
189
189
  system("ruby carray_stat_proc.rb > carray_stat_proc.c")
190
190
  end
191
191
 
192
- puts "creating rdoc_ext.rb"
193
- system %{
194
- ruby utils/extract_rdoc.rb > rdoc_ext.rb
195
- }
196
-
197
192
  # --- create Makefile
198
193
 
199
194
  create_makefile("carray_ext")
File without changes
@@ -24,6 +24,7 @@ void Init_numeric_float_function ();
24
24
  void Init_carray_core ();
25
25
  void Init_carray_undef ();
26
26
  void Init_carray_class ();
27
+ void Init_carray_data_type ();
27
28
  void Init_carray_test ();
28
29
  void Init_carray_attribute ();
29
30
  void Init_carray_loop ();
@@ -34,7 +35,6 @@ void Init_carray_iterator ();
34
35
  void Init_carray_operator ();
35
36
  void Init_carray_numeric ();
36
37
  void Init_carray_math ();
37
- void Init_carray_random ();
38
38
  void Init_carray_utils ();
39
39
  void Init_carray_order ();
40
40
  void Init_carray_sort_addr ();
@@ -70,6 +70,9 @@ void Init_ca_iter_dimension ();
70
70
  void Init_ca_iter_block ();
71
71
  void Init_ca_iter_window ();
72
72
 
73
+ void Init_carray_mathfunc ();
74
+
75
+
73
76
  void
74
77
  Init_carray_ext ()
75
78
  {
@@ -193,6 +196,7 @@ Init_carray_ext ()
193
196
  Init_numeric_float_function();
194
197
 
195
198
  Init_carray_class();
199
+ Init_carray_data_type();
196
200
  Init_carray_test();
197
201
  Init_carray_attribute();
198
202
  Init_carray_undef();
@@ -203,7 +207,6 @@ Init_carray_ext ()
203
207
  Init_carray_operator();
204
208
  Init_carray_math(); /* order of math, numeric should not be changed */
205
209
  Init_carray_numeric(); /* order of math, numeric should not be changed */
206
- Init_carray_random();
207
210
  Init_carray_order();
208
211
  Init_carray_sort_addr();
209
212
  Init_carray_stat();
@@ -240,5 +243,9 @@ Init_carray_ext ()
240
243
  Init_ca_iter_dimension();
241
244
  Init_ca_iter_block();
242
245
  Init_ca_iter_window();
246
+
247
+ Init_carray_mathfunc();
248
+
249
+
243
250
  }
244
251
 
File without changes
@@ -10,9 +10,9 @@
10
10
 
11
11
  ---------------------------------------------------------------------------- */
12
12
 
13
- #define CA_VERSION "1.4.0"
14
- #define CA_VERSION_CODE 140
13
+ #define CA_VERSION "1.5.1"
14
+ #define CA_VERSION_CODE 151
15
15
  #define CA_VERSION_MAJOR 1
16
- #define CA_VERSION_MINOR 4
17
- #define CA_VERSION_TEENY 0
18
- #define CA_VERSION_DATE "2020/06/15"
16
+ #define CA_VERSION_MINOR 5
17
+ #define CA_VERSION_TEENY 1
18
+ #define CA_VERSION_DATE "2020/07/01"
File without changes
@@ -14,46 +14,57 @@ major = RbConfig::CONFIG['MAJOR'].to_i
14
14
  minor = RbConfig::CONFIG['MINOR'].to_i
15
15
  teeny = RbConfig::CONFIG['TEENY'].to_i
16
16
  ruby_version_code = major * 100 + minor * 10 + teeny
17
+
17
18
  if ruby_version_code < 190
18
19
  require 'complex'
19
20
  end
20
21
 
22
+ # main
23
+
21
24
  require 'carray_ext'
22
- require 'carray/base/basic'
23
- require 'carray/base/math'
24
- require 'carray/base/iterator'
25
- require 'carray/base/struct'
26
- require 'carray/base/inspect'
27
- require 'carray/base/obsolete'
28
- require 'carray/base/string'
29
-
30
- require "carray/carray_mathfunc"
31
- require "carray/carray_calculus"
32
- require "carray/math/calculus"
33
-
34
- require 'carray/base/autoload'
35
- require 'carray/autoload/autoload_base'
36
- require 'carray/autoload/autoload_io_imagemagick'
37
- require 'carray/autoload/autoload_io_table'
38
- require 'carray/autoload/autoload_math_histogram'
39
- require 'carray/autoload/autoload_math_interp'
40
- require 'carray/autoload/autoload_math_recurrence'
41
- require 'carray/autoload/autoload_object_iterator'
42
- require 'carray/autoload/autoload_object_link'
43
- require 'carray/autoload/autoload_object_pack'
44
-
45
- require 'carray/autoload/autoload_gem_gnuplot'
46
- require 'carray/autoload/autoload_gem_narray'
47
- require 'carray/autoload/autoload_gem_numo_narray'
48
- require 'carray/autoload/autoload_gem_io_csv'
49
- require 'carray/autoload/autoload_gem_io_sqlite3'
50
- require 'carray/autoload/autoload_gem_rmagick'
51
- require 'carray/autoload/autoload_gem_cairo'
52
- require 'carray/autoload/autoload_gem_opencv'
53
- require 'carray/autoload/autoload_gem_ffi'
54
-
55
- #require 'carray/autoload/autoload_gem_io_pg'
56
- #require 'carray/autoload/autoload_gem_zimg'
57
-
58
- undef autoload_method
59
25
 
26
+ require 'carray/inspect'
27
+ require 'carray/basic'
28
+ require 'carray/construct'
29
+ require 'carray/mask'
30
+ require 'carray/compose'
31
+ require 'carray/transform'
32
+ require 'carray/convert'
33
+ require 'carray/testing'
34
+ require 'carray/ordering'
35
+
36
+ require 'carray/math'
37
+ require 'carray/iterator'
38
+ require 'carray/struct'
39
+ require 'carray/table'
40
+ require 'carray/string'
41
+
42
+ # obsolete methods
43
+
44
+ require 'carray/obsolete'
45
+
46
+ # autoload
47
+
48
+ unless $CARRAY_NO_AUTOLOAD
49
+ require 'carray/autoload'
50
+ require 'carray/autoload/autoload_base'
51
+ require 'carray/autoload/autoload_io_imagemagick'
52
+ require 'carray/autoload/autoload_math_histogram'
53
+ require 'carray/autoload/autoload_math_recurrence'
54
+ require 'carray/autoload/autoload_object_iterator'
55
+ require 'carray/autoload/autoload_object_link'
56
+ require 'carray/autoload/autoload_object_pack'
57
+
58
+ require 'carray/autoload/autoload_gem_random'
59
+ require 'carray/autoload/autoload_gem_gnuplot'
60
+ require 'carray/autoload/autoload_gem_narray'
61
+ require 'carray/autoload/autoload_gem_numo_narray'
62
+ require 'carray/autoload/autoload_gem_io_csv'
63
+ require 'carray/autoload/autoload_gem_io_sqlite3'
64
+ require 'carray/autoload/autoload_gem_rmagick'
65
+ require 'carray/autoload/autoload_gem_cairo'
66
+ require 'carray/autoload/autoload_gem_opencv'
67
+ require 'carray/autoload/autoload_gem_ffi'
68
+
69
+ undef autoload_method
70
+ end
@@ -1,6 +1,6 @@
1
1
  # ----------------------------------------------------------------------------
2
2
  #
3
- # carray/base/autoload.rb
3
+ # carray/autoload.rb
4
4
  #
5
5
  # This file is part of Ruby/CArray extension library.
6
6
  # You can redistribute it and/or modify it under the terms of
@@ -1,5 +1,5 @@
1
1
  class CArray
2
- serialize_rb = "carray/base/serialize"
2
+ serialize_rb = "carray/serialize"
3
3
  autoload :Serializer, serialize_rb
4
4
  autoload_method "self.save", serialize_rb
5
5
  autoload_method "self.load", serialize_rb
@@ -1,8 +1,10 @@
1
- #autoload :Numo, "carray-numo-narray"
2
-
3
1
  class CArray
4
2
  autoload_method :to_numo, "carray-numo-narray"
5
3
  autoload_method :numo, "carray-numo-narray"
4
+ autoload_method "self.as_numo", "carray-numo-narray"
5
+ autoload_method "self.as_numo!", "carray-numo-narray"
6
+ autoload_method :as_numo, "carray-numo-narray"
7
+ autoload_method :as_numo!, "carray-numo-narray"
6
8
  end
7
9
 
8
10
  module Numo
@@ -11,4 +13,3 @@ module Numo
11
13
  autoload_method :ca, "carray-numo-narray"
12
14
  end
13
15
  end
14
-
@@ -0,0 +1,8 @@
1
+ class CArray
2
+ class << self
3
+ autoload_method :srand, "carray-random"
4
+ end
5
+ autoload_method :random!, "carray-random"
6
+ autoload_method :shuffle, "carray-random"
7
+ autoload_method :shuffle!, "carray-random"
8
+ end
@@ -0,0 +1,193 @@
1
+ # ----------------------------------------------------------------------------
2
+ #
3
+ # carray/basic.rb
4
+ #
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
+ #
9
+ # Copyright (C) 2005 Hiroki Motoyoshi
10
+ #
11
+ # ----------------------------------------------------------------------------
12
+
13
+ module CAMath
14
+ include Math
15
+ end
16
+
17
+ #
18
+ # monkey patch
19
+ #
20
+
21
+ def nan
22
+ 0.0/0.0
23
+ end
24
+
25
+ class Array # :nodoc:
26
+ def +@
27
+ return CA_SIZE(self)
28
+ end
29
+ def to_ca
30
+ return CA_OBJECT(self)
31
+ end
32
+ end
33
+
34
+ class Range # :nodoc:
35
+ def +@
36
+ return CA_SIZE(self)
37
+ end
38
+ def to_ca
39
+ return CA_OBJECT(self)
40
+ end
41
+ end
42
+
43
+ class Numeric
44
+
45
+ def eq (other)
46
+ case other
47
+ when CArray
48
+ return other.eq(self)
49
+ else
50
+ return send(:eq, *other.coerce(self))
51
+ end
52
+ end
53
+
54
+ def ne (other)
55
+ case other
56
+ when CArray
57
+ return other.ne(self)
58
+ else
59
+ return send(:ne, *other.coerce(self))
60
+ end
61
+ end
62
+
63
+ end
64
+
65
+ class CArray
66
+
67
+ def has_attribute?
68
+ if ( not @attribute ) or @attribute.empty?
69
+ return false
70
+ else
71
+ return true
72
+ end
73
+ end
74
+
75
+ def attribute= (obj)
76
+ unless obj.is_a?(Hash)
77
+ raise "attribute should be a hash object"
78
+ end
79
+ @attribute = obj
80
+ end
81
+
82
+ def attribute
83
+ @attribute ||= {}
84
+ return @attribute
85
+ end
86
+
87
+ def first
88
+ self[0]
89
+ end
90
+
91
+ def last
92
+ self[-1]
93
+ end
94
+
95
+ # matchup
96
+
97
+ def matchup (ref)
98
+ ri = ref.sort_addr
99
+ rs = ref[ri].to_ca
100
+ si = rs.bsearch(self)
101
+ return ri.project(si)
102
+ end
103
+
104
+ def matchup_nearest (ref, direction: "round")
105
+ ri = ref.sort_addr
106
+ rs = ref[ri].to_ca
107
+ si = rs.section(self).send(direction.intern).int64
108
+ si.trim!(0,si.size)
109
+ return ri[si].to_ca
110
+ end
111
+
112
+
113
+ # index / indices / axes
114
+
115
+ def address ()
116
+ return CArray.int32(*dim).seq!
117
+ end
118
+
119
+ def index (n = 0)
120
+ unless n.is_a?(Integer)
121
+ raise ArgumentError, "argument should be an integer"
122
+ end
123
+ if n.between?(0, ndim-1)
124
+ return CArray.int32(dim[n]).seq!
125
+ else
126
+ raise ArgumentError,
127
+ "invalid dimension specifier #{n} (0..#{self.ndim-1})"
128
+ end
129
+ end
130
+
131
+ #
132
+ #
133
+ #
134
+
135
+ def indices
136
+ list = Array.new(ndim) {|i|
137
+ rpt = self.dim
138
+ rpt[i] = :%
139
+ index(i)[*rpt]
140
+ }
141
+ if block_given?
142
+ return yield(*list)
143
+ else
144
+ return list
145
+ end
146
+ end
147
+
148
+
149
+
150
+ end
151
+
152
+ class CArray
153
+
154
+ # Returns object carray has elements of splitted carray at dimensions
155
+ # which is given by arguments
156
+ #
157
+ # a = CA_INT([[1,2,3], [4,5,6], [7,8,9]])
158
+ #
159
+ # a.split(0)
160
+ # [1,2,3], [4,5,6], [7,8,9]
161
+ #
162
+ # a.split(1)
163
+ # [1,4,7], [2,5,8], [3,6,9]
164
+ #
165
+
166
+ def split (*argv)
167
+ odim = dim.values_at(*argv)
168
+ out = CArray.object(*odim)
169
+ idx = [nil] * ndim
170
+ attach {
171
+ out.map_with_index! do |o, v|
172
+ argv.each_with_index do |r, i|
173
+ idx[r] = v[i]
174
+ end
175
+ self[*idx].to_ca
176
+ end
177
+ }
178
+ return out
179
+ end
180
+
181
+ end
182
+
183
+ class CAUnboundRepeat
184
+
185
+ def template (*argv, &block)
186
+ return parent.template(*argv,&block)[*spec.map{|x| x != :* ? nil : x}]
187
+ end
188
+
189
+ end
190
+
191
+
192
+
193
+
@@ -0,0 +1,291 @@
1
+ # ----------------------------------------------------------------------------
2
+ #
3
+ # carray/composition.rb
4
+ #
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
+ #
9
+ # Copyright (C) 2005 Hiroki Motoyoshi
10
+ #
11
+ # ----------------------------------------------------------------------------
12
+
13
+ class CArray
14
+
15
+ # Returns the array resized to the dimension given as `newdim`.
16
+ # The new area is filled by the value returned by the block.
17
+ def resize (*newdim, &block)
18
+ if newdim.size != ndim
19
+ raise "ndim mismatch"
20
+ end
21
+ offset = Array.new(ndim){0}
22
+ ndim.times do |i|
23
+ d = newdim[i]
24
+ case d
25
+ when nil
26
+ newdim[i] = dim[i]
27
+ when Integer
28
+ if d < 0
29
+ newdim[i] *= -1
30
+ offset[i] = newdim[i] - dim[i]
31
+ end
32
+ else
33
+ raise "invalid dimension size"
34
+ end
35
+ end
36
+ out = CArray.new(data_type, newdim, &block)
37
+ if out.has_mask?
38
+ out.mask.paste(offset, self.false)
39
+ end
40
+ out.paste(offset, self)
41
+ return out
42
+ end
43
+
44
+ # insert
45
+ def insert_block (offset, bsize, &block)
46
+ if offset.size != ndim or
47
+ bsize.size != ndim
48
+ raise "ndim mismatch"
49
+ end
50
+ newdim = dim
51
+ grids = dim.map{|d| CArray.int32(d) }
52
+ ndim.times do |i|
53
+ if offset[i] < 0
54
+ offset[i] += dim[i]
55
+ end
56
+ if offset[i] < 0 or offset[i] >= dim[i] or bsize[i] < 0
57
+ raise "invalid offset or size"
58
+ end
59
+ if bsize[i] > 0
60
+ newdim[i] += bsize[i]
61
+ end
62
+ grids[i][0...offset[i]].seq!
63
+ grids[i][offset[i]..-1].seq!(offset[i]+bsize[i])
64
+ end
65
+ out = CArray.new(data_type, newdim)
66
+ if block_given?
67
+ sel = out.true
68
+ sel[*grids] = 0
69
+ out[sel] = block.call
70
+ end
71
+ out[*grids] = self
72
+ return out
73
+ end
74
+
75
+ def delete_block (offset, bsize)
76
+ if offset.size != ndim or
77
+ bsize.size != ndim
78
+ raise "ndim mismatch"
79
+ end
80
+ newdim = dim
81
+ grids = []
82
+ ndim.times do |i|
83
+ if offset[i] < 0
84
+ offset[i] += dim[i]
85
+ end
86
+ if bsize[i] >= 0
87
+ if offset[i] < 0 or offset[i] >= dim[i]
88
+ raise "invalid offset or size"
89
+ end
90
+ newdim[i] -= bsize[i]
91
+ else
92
+ if offset[i] + bsize[i] + 1 < 0 or offset[i] + bsize[i] > dim[i]
93
+ raise "invalid offset or size"
94
+ end
95
+ newdim[i] += bsize[i]
96
+ end
97
+ grids[i] = CArray.int32(newdim[i])
98
+ if bsize[i] >= 0
99
+ if offset[i] > 0
100
+ grids[i][0...offset[i]].seq!
101
+ end
102
+ if offset[i] + bsize[i] < dim[i]
103
+ grids[i][offset[i]..-1].seq!(offset[i]+bsize[i])
104
+ end
105
+ else
106
+ if offset[i]+bsize[i] > 0
107
+ grids[i][0..offset[i]+bsize[i]].seq!
108
+ end
109
+ if offset[i]+bsize[i]+1 < dim[i]-1
110
+ grids[i][offset[i]+bsize[i]+1..-1].seq!(offset[i]+1)
111
+ end
112
+ end
113
+ end
114
+ return self[*grids].to_ca
115
+ end
116
+
117
+ def self.combine (data_type, tdim, list, at = 0)
118
+ has_fill_value = false
119
+ if block_given?
120
+ fill_value = yield
121
+ has_fill_value = true
122
+ end
123
+ if not tdim.is_a?(Array) or tdim.size == 0
124
+ raise "invalid binding dimension"
125
+ end
126
+ if not list.is_a?(Array) or list.size == 0
127
+ raise "invalid list"
128
+ end
129
+ list = list.map{|x| CArray.wrap_readonly(x, data_type) }
130
+ ref = list.detect{|x| x.is_a?(CArray) or not x.scalar? }
131
+ unless ref
132
+ raise "at least one element in list should be a carray"
133
+ end
134
+ dim = ref.dim
135
+ ndim = ref.ndim
136
+ tndim = tdim.size
137
+ if at < 0
138
+ at += ndim - tndim + 1
139
+ end
140
+ unless at.between?(0, ndim - tndim)
141
+ raise "concatnating position out of range"
142
+ end
143
+ list.map! do |x|
144
+ if x.scalar?
145
+ rdim = dim.clone
146
+ rdim[at] = :%
147
+ x = x[*rdim] # convert CScalar to CARepeat
148
+ end
149
+ x
150
+ end
151
+ block = CArray.object(*tdim){ list }
152
+ edim = tdim.clone
153
+ idx = Array.new(tdim)
154
+ offset = Array.new(tdim.size) { [] }
155
+ tdim.each_with_index do |td, i|
156
+ edim[i] = 0
157
+ idx.map!{0}
158
+ idx[i] = nil
159
+ block[*idx].each do |e|
160
+ offset[i] << edim[i]
161
+ edim[i] += e.dim[at+i] # extended dimension size
162
+ end
163
+ end
164
+ newdim = dim.clone
165
+ newdim[at,tndim] = edim # extended dimension size
166
+ if has_fill_value
167
+ obj = CArray.new(data_type, newdim) { fill_value }
168
+ else
169
+ obj = CArray.new(data_type, newdim)
170
+ end
171
+ idx = newdim.map{0}
172
+ block.each_with_index do |item, tidx|
173
+ (at...at+tndim).each_with_index do |d,i|
174
+ idx[d] = offset[i][tidx[i]]
175
+ end
176
+ obj.paste(idx, item)
177
+ end
178
+ obj
179
+ end
180
+
181
+ def self.bind (data_type, list, at = 0)
182
+ return CArray.combine(data_type, [list.size], list, at)
183
+ end
184
+
185
+ def self.composite (data_type, tdim, list, at = 0)
186
+ if not tdim.is_a?(Array) or tdim.size == 0
187
+ raise "invalid tiling dimension"
188
+ end
189
+ if not list.is_a?(Array) or list.size == 0
190
+ raise "invalid carray list"
191
+ end
192
+ list = list.map{|x| CArray.wrap_readonly(x, data_type) }
193
+ ref = list.detect{|x| x.is_a?(CArray) or not x.scalar? }
194
+ unless ref
195
+ raise "at least one element in list should be a carray"
196
+ end
197
+ dim = ref.dim
198
+ ndim = ref.ndim
199
+ if at < 0
200
+ at += ndim + 1 # "+ 1" is needed here
201
+ end
202
+ unless at.between?(0,ndim)
203
+ raise "tiling position is out of range"
204
+ end
205
+ tndim = tdim.size
206
+ list.map! do |x|
207
+ if x.scalar?
208
+ rdim = dim.clone
209
+ rdim[at] = :%
210
+ x = x[*rdim] # convert CScalar to CARepeat
211
+ end
212
+ x
213
+ end
214
+ newdim = dim.clone
215
+ newdim[at,0] = tdim
216
+ obj = CArray.new(data_type, newdim)
217
+ idx = Array.new(ndim+tndim) { nil }
218
+ CArray.each_index(*tdim) do |*tidx|
219
+ idx[at,tndim] = tidx
220
+ obj[*idx] = list.shift
221
+ end
222
+ obj
223
+ end
224
+
225
+ def self.merge (data_type, list, at = -1)
226
+ return CArray.composite(data_type, [list.size], list, at)
227
+ end
228
+
229
+ def self.join (*argv)
230
+ # get options
231
+ case argv.first
232
+ when Integer, Symbol, String
233
+ type, = *CArray.guess_type_and_bytes(argv.shift, 0)
234
+ else
235
+ type = argv.flatten.first.data_type
236
+ end
237
+ # process
238
+ conc = argv.map do |list|
239
+ case list
240
+ when CArray
241
+ if list.ndim == 1
242
+ list[:%,1]
243
+ else
244
+ list
245
+ end
246
+ when Array
247
+ x0 = list.first
248
+ if list.size == 1 and
249
+ x0.is_a?(CArray) and
250
+ x0.ndim == 1
251
+ list = [x0[:%,1]]
252
+ else
253
+ list = list.map { |x|
254
+ case x
255
+ when CArray
256
+ if x.ndim == 1
257
+ x[:%,1]
258
+ else
259
+ x
260
+ end
261
+ when Array
262
+ y = x.first
263
+ if x.size == 1 and
264
+ y.is_a?(CArray) and
265
+ y.ndim == 1
266
+ y[1,:%]
267
+ else
268
+ CArray.join(*x)
269
+ end
270
+ else
271
+ x
272
+ end
273
+ }
274
+ end
275
+ if block_given?
276
+ CArray.bind(type, list, 1, &block)
277
+ else
278
+ CArray.bind(type, list, 1)
279
+ end
280
+ else
281
+ list
282
+ end
283
+ end
284
+ if conc.size > 1
285
+ return CArray.bind(type, conc)
286
+ else
287
+ return conc.first
288
+ end
289
+ end
290
+
291
+ end