carray 1.4.0 → 1.5.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (239) hide show
  1. checksums.yaml +4 -4
  2. data/.yardopts +32 -0
  3. data/LICENSE +22 -0
  4. data/NEWS.md +83 -0
  5. data/README.md +38 -18
  6. data/Rakefile +2 -2
  7. data/TODO.md +17 -0
  8. data/carray.gemspec +13 -18
  9. data/{ca_iter_block.c → ext/ca_iter_block.c} +16 -18
  10. data/{ca_iter_dimension.c → ext/ca_iter_dimension.c} +20 -21
  11. data/{ca_iter_window.c → ext/ca_iter_window.c} +12 -14
  12. data/{ca_obj_array.c → ext/ca_obj_array.c} +451 -176
  13. data/{ca_obj_bitarray.c → ext/ca_obj_bitarray.c} +18 -23
  14. data/{ca_obj_bitfield.c → ext/ca_obj_bitfield.c} +12 -16
  15. data/{ca_obj_block.c → ext/ca_obj_block.c} +47 -54
  16. data/{ca_obj_fake.c → ext/ca_obj_fake.c} +10 -12
  17. data/{ca_obj_farray.c → ext/ca_obj_farray.c} +21 -23
  18. data/{ca_obj_field.c → ext/ca_obj_field.c} +30 -32
  19. data/{ca_obj_grid.c → ext/ca_obj_grid.c} +32 -33
  20. data/{ca_obj_mapping.c → ext/ca_obj_mapping.c} +11 -13
  21. data/{ca_obj_object.c → ext/ca_obj_object.c} +40 -42
  22. data/{ca_obj_reduce.c → ext/ca_obj_reduce.c} +3 -5
  23. data/{ca_obj_refer.c → ext/ca_obj_refer.c} +44 -48
  24. data/{ca_obj_repeat.c → ext/ca_obj_repeat.c} +45 -47
  25. data/{ca_obj_select.c → ext/ca_obj_select.c} +4 -6
  26. data/{ca_obj_shift.c → ext/ca_obj_shift.c} +26 -28
  27. data/{ca_obj_transpose.c → ext/ca_obj_transpose.c} +26 -28
  28. data/{ca_obj_unbound_repeat.c → ext/ca_obj_unbound_repeat.c} +106 -160
  29. data/{ca_obj_window.c → ext/ca_obj_window.c} +33 -35
  30. data/{carray.h → ext/carray.h} +86 -59
  31. data/{carray_access.c → ext/carray_access.c} +194 -101
  32. data/{carray_attribute.c → ext/carray_attribute.c} +161 -207
  33. data/{carray_call_cfunc.c → ext/carray_call_cfunc.c} +1 -3
  34. data/{carray_cast.c → ext/carray_cast.c} +351 -150
  35. data/{carray_cast_func.rb → ext/carray_cast_func.rb} +1 -2
  36. data/{carray_class.c → ext/carray_class.c} +28 -36
  37. data/{carray_conversion.c → ext/carray_conversion.c} +63 -68
  38. data/{carray_copy.c → ext/carray_copy.c} +34 -50
  39. data/{carray_core.c → ext/carray_core.c} +75 -62
  40. data/ext/carray_data_type.c +66 -0
  41. data/{carray_element.c → ext/carray_element.c} +34 -53
  42. data/{carray_generate.c → ext/carray_generate.c} +71 -50
  43. data/{carray_iterator.c → ext/carray_iterator.c} +53 -53
  44. data/{carray_loop.c → ext/carray_loop.c} +77 -106
  45. data/{carray_mask.c → ext/carray_mask.c} +105 -114
  46. data/{carray_math.rb → ext/carray_math.rb} +29 -13
  47. data/ext/{mathfunc/carray_mathfunc.c → carray_mathfunc.c} +1 -3
  48. data/{carray_numeric.c → ext/carray_numeric.c} +43 -46
  49. data/{carray_operator.c → ext/carray_operator.c} +49 -36
  50. data/{carray_order.c → ext/carray_order.c} +232 -217
  51. data/{carray_sort_addr.c → ext/carray_sort_addr.c} +14 -21
  52. data/{carray_stat.c → ext/carray_stat.c} +6 -8
  53. data/{carray_stat_proc.rb → ext/carray_stat_proc.rb} +25 -27
  54. data/{carray_test.c → ext/carray_test.c} +63 -51
  55. data/{carray_undef.c → ext/carray_undef.c} +1 -11
  56. data/{carray_utils.c → ext/carray_utils.c} +12 -4
  57. data/{extconf.rb → ext/extconf.rb} +10 -7
  58. data/{mkmath.rb → ext/mkmath.rb} +2 -2
  59. data/{ruby_carray.c → ext/ruby_carray.c} +20 -8
  60. data/{ruby_ccomplex.c → ext/ruby_ccomplex.c} +2 -4
  61. data/{ruby_float_func.c → ext/ruby_float_func.c} +1 -3
  62. data/ext/version.h +16 -0
  63. data/{version.rb → ext/version.rb} +0 -0
  64. data/lib/carray.rb +51 -40
  65. data/lib/carray/{base/autoload.rb → autoload.rb} +1 -3
  66. data/lib/carray/autoload/autoload_base.rb +1 -1
  67. data/lib/carray/autoload/autoload_gem_numo_narray.rb +7 -6
  68. data/lib/carray/autoload/autoload_gem_random.rb +8 -0
  69. data/lib/carray/basic.rb +191 -0
  70. data/lib/carray/broadcast.rb +101 -0
  71. data/lib/carray/compose.rb +315 -0
  72. data/lib/carray/construct.rb +484 -0
  73. data/lib/carray/convert.rb +115 -0
  74. data/lib/carray/info.rb +1 -3
  75. data/lib/carray/{base/inspect.rb → inspect.rb} +9 -11
  76. data/lib/carray/io/imagemagick.rb +2 -4
  77. data/lib/carray/{base/iterator.rb → iterator.rb} +6 -6
  78. data/lib/carray/mask.rb +102 -0
  79. data/lib/carray/{base/math.rb → math.rb} +20 -52
  80. data/lib/carray/math/histogram.rb +8 -10
  81. data/lib/carray/math/recurrence.rb +1 -3
  82. data/lib/carray/mkmf.rb +9 -3
  83. data/lib/carray/object/ca_obj_iterator.rb +1 -3
  84. data/lib/carray/object/ca_obj_link.rb +1 -3
  85. data/lib/carray/object/ca_obj_pack.rb +9 -11
  86. data/lib/carray/obsolete.rb +256 -0
  87. data/lib/carray/ordering.rb +181 -0
  88. data/lib/carray/{base/serialize.rb → serialize.rb} +60 -76
  89. data/lib/carray/{base/string.rb → string.rb} +10 -64
  90. data/lib/carray/{base/struct.rb → struct.rb} +19 -21
  91. data/lib/carray/{io/table.rb → table.rb} +1 -10
  92. data/lib/carray/testing.rb +51 -0
  93. data/lib/carray/time.rb +76 -0
  94. data/lib/carray/transform.rb +109 -0
  95. data/misc/Methods.ja.md +182 -0
  96. data/{NOTE → misc/NOTE} +16 -38
  97. data/spec/Classes/CABitfield_spec.rb +58 -0
  98. data/spec/Classes/CABlockIterator_spec.rb +114 -0
  99. data/spec/Classes/CABlock_spec.rb +205 -0
  100. data/spec/Classes/CAField_spec.rb +39 -0
  101. data/spec/Classes/CAGrid_spec.rb +75 -0
  102. data/spec/Classes/CAMap_spec.rb +0 -0
  103. data/{test/test_CAMapping.rb → spec/Classes/CAMapping_spec.rb} +35 -36
  104. data/spec/Classes/CAObject_attribute_spec.rb +33 -0
  105. data/spec/Classes/CAObject_spec.rb +33 -0
  106. data/spec/Classes/CARefer_spec.rb +93 -0
  107. data/spec/Classes/CARepeat_spec.rb +65 -0
  108. data/spec/Classes/CASelect_spec.rb +22 -0
  109. data/spec/Classes/CAShift_spec.rb +16 -0
  110. data/spec/Classes/CAStruct_spec.rb +71 -0
  111. data/{test/test_CATranspose.rb → spec/Classes/CATranspose_spec.rb} +20 -21
  112. data/spec/Classes/CAUnboudRepeat_spec.rb +102 -0
  113. data/spec/Classes/CAWindow_spec.rb +54 -0
  114. data/spec/Classes/CAWrap_spec.rb +8 -0
  115. data/{test/test_CArray.rb → spec/Classes/CArray_spec.rb} +48 -92
  116. data/spec/Classes/CScalar_spec.rb +55 -0
  117. data/spec/Features/feature_130_spec.rb +19 -0
  118. data/spec/Features/feature_attributes_spec.rb +280 -0
  119. data/spec/Features/feature_boolean_spec.rb +98 -0
  120. data/spec/Features/feature_broadcast.rb +116 -0
  121. data/spec/Features/feature_cast_function.rb +19 -0
  122. data/spec/Features/feature_cast_spec.rb +33 -0
  123. data/spec/Features/feature_class_spec.rb +84 -0
  124. data/spec/Features/feature_complex_spec.rb +42 -0
  125. data/{test/test_composite.rb → spec/Features/feature_composite_spec.rb} +17 -18
  126. data/spec/Features/feature_convert_spec.rb +46 -0
  127. data/spec/Features/feature_copy_spec.rb +123 -0
  128. data/spec/Features/feature_creation_spec.rb +84 -0
  129. data/spec/Features/feature_element_spec.rb +144 -0
  130. data/spec/Features/feature_extream_spec.rb +54 -0
  131. data/spec/Features/feature_generate_spec.rb +74 -0
  132. data/spec/Features/feature_index_spec.rb +69 -0
  133. data/spec/Features/feature_mask_spec.rb +580 -0
  134. data/spec/Features/feature_math_spec.rb +97 -0
  135. data/spec/Features/feature_order_spec.rb +146 -0
  136. data/spec/Features/feature_ref_store_spec.rb +209 -0
  137. data/spec/Features/feature_serialization_spec.rb +125 -0
  138. data/spec/Features/feature_stat_spec.rb +397 -0
  139. data/spec/Features/feature_virtual_spec.rb +48 -0
  140. data/spec/Features/method_eq_spec.rb +81 -0
  141. data/spec/Features/method_is_nan_spec.rb +12 -0
  142. data/spec/Features/method_map_spec.rb +54 -0
  143. data/spec/Features/method_max_with.rb +20 -0
  144. data/spec/Features/method_min_with.rb +19 -0
  145. data/spec/Features/method_ne_spec.rb +18 -0
  146. data/spec/Features/method_project_spec.rb +188 -0
  147. data/spec/Features/method_ref_spec.rb +27 -0
  148. data/spec/Features/method_round_spec.rb +11 -0
  149. data/spec/Features/method_s_linspace_spec.rb +48 -0
  150. data/spec/Features/method_s_span_spec.rb +14 -0
  151. data/spec/Features/method_seq_spec.rb +47 -0
  152. data/spec/Features/method_sort_with.rb +43 -0
  153. data/spec/Features/method_sorted_with.rb +29 -0
  154. data/spec/Features/method_span_spec.rb +42 -0
  155. data/spec/Features/method_wrap_readonly_spec.rb +43 -0
  156. data/{test → spec/UnitTest}/test_CAVirtual.rb +0 -0
  157. data/spec/spec_all.rb +0 -1
  158. data/utils/convert_test.rb +73 -0
  159. data/utils/{extract_rdoc.rb → extract_yard.rb} +7 -12
  160. data/{devel → utils}/guess_shape.rb +0 -0
  161. data/utils/{diff_method.rb → monkey_patch_methods.rb} +17 -7
  162. metadata +159 -206
  163. data/COPYING +0 -56
  164. data/GPL +0 -340
  165. data/LEGAL +0 -50
  166. data/TODO +0 -5
  167. data/carray_random.c +0 -531
  168. data/devel/im2col.rb +0 -17
  169. data/ext/calculus/carray_calculus.c +0 -931
  170. data/ext/calculus/carray_interp.c +0 -358
  171. data/ext/calculus/extconf.rb +0 -12
  172. data/ext/calculus/lib/math/calculus.rb +0 -119
  173. data/ext/calculus/lib/math/interp/adapter_interp1d.rb +0 -31
  174. data/ext/mathfunc/extconf.rb +0 -18
  175. data/ext/mathfunc/test/test_hypot.rb +0 -5
  176. data/ext/mathfunc/test/test_j0.rb +0 -22
  177. data/ext/mathfunc/test/test_jn.rb +0 -8
  178. data/ext/mathfunc/test/test_sph.rb +0 -9
  179. data/lib/carray/autoload/autoload_io_table.rb +0 -1
  180. data/lib/carray/autoload/autoload_math_interp.rb +0 -4
  181. data/lib/carray/base/basic.rb +0 -1146
  182. data/lib/carray/base/obsolete.rb +0 -131
  183. data/lib/carray/math/interp.rb +0 -57
  184. data/lib/carray/math/interp/adapter_gsl_spline.rb +0 -47
  185. data/mt19937ar.c +0 -182
  186. data/mt19937ar.h +0 -86
  187. data/rdoc_main.rb +0 -27
  188. data/rdoc_math.rb +0 -5
  189. data/rdoc_stat.rb +0 -31
  190. data/spec/CABlockIterator/CABlockIterator_spec.rb +0 -113
  191. data/spec/CArray/bug/store_spec.rb +0 -27
  192. data/spec/CArray/index/repeat_spec.rb +0 -10
  193. data/spec/CArray/method/eq_spec.rb +0 -80
  194. data/spec/CArray/method/is_nan_spec.rb +0 -12
  195. data/spec/CArray/method/ne_spec.rb +0 -18
  196. data/spec/CArray/method/round_spec.rb +0 -11
  197. data/spec/CArray/object/_attribute_spec.rb +0 -32
  198. data/spec/CArray/object/s_new_spec.rb +0 -31
  199. data/spec/CArray/serialize/Serialization_spec.rb +0 -89
  200. data/test/test_130.rb +0 -23
  201. data/test/test_ALL.rb +0 -51
  202. data/test/test_CABitfield.rb +0 -59
  203. data/test/test_CABlock.rb +0 -208
  204. data/test/test_CAField.rb +0 -40
  205. data/test/test_CAGrid.rb +0 -76
  206. data/test/test_CAMmap.rb +0 -11
  207. data/test/test_CARefer.rb +0 -94
  208. data/test/test_CARepeat.rb +0 -66
  209. data/test/test_CASelect.rb +0 -23
  210. data/test/test_CAShift.rb +0 -17
  211. data/test/test_CAWindow.rb +0 -55
  212. data/test/test_CAWrap.rb +0 -9
  213. data/test/test_CComplex.rb +0 -83
  214. data/test/test_CScalar.rb +0 -91
  215. data/test/test_attribute.rb +0 -281
  216. data/test/test_block_iterator.rb +0 -17
  217. data/test/test_boolean.rb +0 -99
  218. data/test/test_cast.rb +0 -33
  219. data/test/test_class.rb +0 -85
  220. data/test/test_complex.rb +0 -43
  221. data/test/test_convert.rb +0 -79
  222. data/test/test_copy.rb +0 -141
  223. data/test/test_creation.rb +0 -85
  224. data/test/test_element.rb +0 -146
  225. data/test/test_extream.rb +0 -55
  226. data/test/test_generate.rb +0 -75
  227. data/test/test_index.rb +0 -71
  228. data/test/test_mask.rb +0 -578
  229. data/test/test_math.rb +0 -98
  230. data/test/test_narray.rb +0 -64
  231. data/test/test_order.rb +0 -147
  232. data/test/test_random.rb +0 -15
  233. data/test/test_ref_store.rb +0 -211
  234. data/test/test_stat.rb +0 -414
  235. data/test/test_struct.rb +0 -72
  236. data/test/test_virtual.rb +0 -49
  237. data/utils/create_rdoc.sh +0 -9
  238. data/utils/make_tgz.sh +0 -3
  239. data/version.h +0 -18
@@ -1,31 +0,0 @@
1
- # ----------------------------------------------------------------------------
2
- #
3
- # carray/math/interp/adapter_interp1d.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
- require "carray/math/interp"
14
-
15
- class CA::Interp::CAInterp1D < CA::Interp::Adapter
16
-
17
- install_adapter "interp1d"
18
-
19
- def initialize (scales, value, options={})
20
- @y = value
21
- @x = scales
22
- end
23
-
24
- def evaluate (x0)
25
- @y.interpolate(@x, x0)
26
- end
27
-
28
- alias grid evaluate
29
-
30
- end
31
-
@@ -1,18 +0,0 @@
1
- require "mkmf"
2
-
3
- dir_config("carray", "../..", "../..")
4
-
5
- have_header("carray.h")
6
-
7
- if /cygwin|mingw/ =~ RUBY_PLATFORM
8
- have_library("carray")
9
- end
10
-
11
- have_header("tgmath.h")
12
-
13
- have_func("atan2", "math.h")
14
- have_func("hypot", "math.h")
15
- have_func("lgamma", "math.h")
16
- have_func("expm1", "math.h")
17
-
18
- create_makefile("carray/carray_mathfunc")
@@ -1,5 +0,0 @@
1
- require 'carray'
2
-
3
- p x = CArray.object(101).span(0..1)
4
-
5
- p CAMath.hypot(x[:*,nil], x[nil,:*])
@@ -1,22 +0,0 @@
1
- require 'carray'
2
-
3
- x = CArray.float(101).span(0..10)
4
-
5
- CA.gnuplot { |g|
6
- g.plot2d(
7
- [x, x.erf],
8
- [x, x.erfc]
9
- )
10
- g.plot2d(
11
- [x, x.j0],
12
- [x, x.j1],
13
- [x, x.jn(2)],
14
- [x, x.jn(3)],
15
- [x, x.jn(4)],
16
- [x, x.jn(5)]
17
- )
18
- g.plot2d(
19
- [x, x.y0],
20
- [x, x.y1]
21
- )
22
- }
@@ -1,8 +0,0 @@
1
- require "carray"
2
-
3
- p x = CAMath.yn(1, CA_FLOAT(0..100))
4
-
5
- CA.gnuplot { |g|
6
- g.plot2d([x], :with=>"lines")
7
- }
8
-
@@ -1,9 +0,0 @@
1
- require "carray"
2
-
3
- r = CA_DOUBLE(1)
4
- theta = CA_DOUBLE(30).rad
5
- phi = CA_DOUBLE(45).rad
6
-
7
- x,y,z = CAMath.spherical_to_xyz(r, theta, phi)
8
- p CAMath.xyz_to_spherical(x,y,z)
9
- p [r, theta, phi]
@@ -1 +0,0 @@
1
- autoload_method "CArray.extend_as_table", "carray/io/table"
@@ -1,4 +0,0 @@
1
- module CA
2
- autoload :Interp, "carray/math/interp"
3
- autoload_method "self.interp", "carray/math/interp"
4
- end
@@ -1,1146 +0,0 @@
1
- # ----------------------------------------------------------------------------
2
- #
3
- # carray/base/base.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
- def nan
18
- 0.0/0.0
19
- end
20
-
21
- class Array # :nodoc:
22
- def +@
23
- return CA_SIZE(self)
24
- end
25
- def to_ca
26
- return CA_OBJECT(self)
27
- end
28
- end
29
-
30
- class Range # :nodoc:
31
- def +@
32
- return CA_SIZE(self)
33
- end
34
- def to_ca
35
- return CA_OBJECT(self)
36
- end
37
- end
38
-
39
- # Create new CArray object from the return value of the block
40
- # with data type +type+. The dimensional size and the initialization value
41
- # are guessed from the return value of the block.
42
- # The block should return one of the following objects.
43
- #
44
- # * Numeric
45
- # * Array
46
- # * CArray
47
- # * an object that has either method +to_ca+ or +to_a+ or +map+
48
- #
49
- # When the return value of the block is a Numeric or CScalar object,
50
- # CScalar object is returned.
51
- #
52
- def CArray.__new__ (type, *args) # :nodoc:
53
- case v = args.first
54
- when CArray
55
- return ( v.data_type == type ) ? v.to_ca : v.to_type(type)
56
- when Array
57
- return CArray.new(type, CArray.guess_array_shape(v)) { v }
58
- when Range
59
- return CArray.span(type, *args)
60
- when String
61
- if type == CA_OBJECT
62
- return CScalar.new(CA_OBJECT) { v }
63
- elsif type == CA_BOOLEAN
64
- v = v.dup
65
- v.tr!('^01',"1")
66
- v.tr!('01',"\x0\x1")
67
- return CArray.boolean(v.length).load_binary(v)
68
- else
69
- case v
70
- when /;/
71
- v = v.strip.split(/\s*;\s*/).
72
- map{|s| s.split(/\s+|\s*,\s*/).map{|x| x=='_' ? UNDEF : x} }
73
- else
74
- v = v.strip.split(/\s+|\s*,\s*/).map{|x| x=='_' ? UNDEF : x}
75
- end
76
- return CArray.new(type, CArray.guess_array_shape(v)) { v }
77
- end
78
- when NilClass
79
- return CArray.new(type, [0])
80
- else
81
- if v.respond_to?(:to_ca)
82
- ca = v.to_ca
83
- return ( ca.data_type == type ) ? ca : ca.to_type(type)
84
- else
85
- return CScalar.new(type) { v }
86
- end
87
- end
88
- end
89
-
90
- def CArray.__new_fixlen__ (bytes, v) # :nodoc:
91
- case v
92
- when CArray
93
- return ( v.data_type == :fixlen ) ? v.to_ca : v.to_type(:fixlen, :bytes=>bytes)
94
- when Array
95
- unless bytes
96
- bytes = v.map{|s| s.length}.max
97
- end
98
- return CArray.new(:fixlen, CArray.guess_array_shape(v), :bytes=>bytes) { v }
99
- when NilClass
100
- return CArray.new(type, [0])
101
- else
102
- if v.respond_to?(:to_ca)
103
- ca = v.to_ca
104
- return ( ca.data_type == :fixlen ) ? ca : ca.to_type(:fixlen, :bytes=>bytes)
105
- else
106
- return CScalar.new(:fixlen, :bytes=>bytes) { v }
107
- end
108
- end
109
- end
110
-
111
- #
112
- # CA_INT8(data)
113
- # :
114
- # CA_CMPLX256(data)
115
- #
116
- # Create new CArray object from +data+ with data type
117
- # which is guessed from the method name. +data+ should be one of the following
118
- # objects.
119
- #
120
- # * Numeric
121
- # * Array
122
- # * CArray
123
- # * an object that has either method +to_ca+ or +to_a+ or +map+
124
- #
125
- # When the block returns a Numeric or CScalar object,
126
- # the resulted array is a CScalar object.
127
-
128
- [
129
- "CA_BOOLEAN",
130
- "CA_INT8",
131
- "CA_UINT8",
132
- "CA_INT16",
133
- "CA_UINT16",
134
- "CA_INT32",
135
- "CA_UINT32",
136
- "CA_INT64",
137
- "CA_UINT64",
138
- "CA_FLOAT32",
139
- "CA_FLOAT64",
140
- "CA_FLOAT128",
141
- "CA_CMPLX64",
142
- "CA_CMPLX128",
143
- "CA_CMPLX256",
144
- "CA_OBJECT",
145
- "CA_BYTE",
146
- "CA_SHORT",
147
- "CA_INT",
148
- "CA_FLOAT",
149
- "CA_DOUBLE",
150
- "CA_COMPLEX",
151
- "CA_DCOMPLEX",
152
- "CA_SIZE",
153
- ].each do |name|
154
- eval %{
155
- def #{name} (*val)
156
- CArray.__new__(#{name}, *val)
157
- end
158
- }
159
- end
160
-
161
- def CA_FIXLEN (val, options = {})
162
- CArray.__new_fixlen__(options[:bytes], val)
163
- end
164
-
165
- class CArray
166
-
167
- def has_attribute?
168
- if ( not @attribute ) or @attribute.empty?
169
- return false
170
- else
171
- return true
172
- end
173
- end
174
-
175
- def attribute= (obj)
176
- unless obj.is_a?(Hash)
177
- raise "attribute should be a hash object"
178
- end
179
- @attribute = obj
180
- end
181
-
182
- def attribute
183
- @attribute ||= {}
184
- return @attribute
185
- end
186
-
187
- def first
188
- self[0]
189
- end
190
-
191
- def last
192
- self[-1]
193
- end
194
-
195
- def range
196
- return (self.min)..(self.max)
197
- end
198
-
199
- def asign (*idx)
200
- self[*idx] = yield
201
- return self
202
- end
203
-
204
- # mask
205
-
206
- #
207
- # Returns the number of masked elements.
208
- #
209
-
210
- def count_masked (*argv)
211
- if has_mask?
212
- return mask.int32.accumulate(*argv)
213
- else
214
- return 0
215
- end
216
- end
217
-
218
- #
219
- # Returns the number of not-masked elements.
220
- #
221
- def count_not_masked (*argv)
222
- if has_mask?
223
- return mask.not.int32.accumulate(*argv)
224
- else
225
- return elements
226
- end
227
- end
228
-
229
- def maskout! (*argv)
230
- if argv.size == 1
231
- val = argv.first
232
- case val
233
- when CArray, Symbol
234
- self[val] = UNDEF
235
- else
236
- self[:eq, val] = UNDEF
237
- end
238
- else
239
- self[*argv] = UNDEF
240
- end
241
- return self
242
- end
243
-
244
- def maskout (*argv)
245
- obj = self.to_ca
246
- if argv.size == 1
247
- val = argv.first
248
- case val
249
- when CArray, Symbol
250
- obj[val] = UNDEF
251
- else
252
- obj[:eq, val] = UNDEF
253
- end
254
- else
255
- obj[*argv] = UNDEF
256
- end
257
- return obj
258
- end
259
-
260
- # matchup
261
-
262
- def matchup (ref)
263
- ri = ref.sort_addr
264
- rs = ref[ri].to_ca
265
- si = rs.bsearch(self)
266
- return ri.project(si)
267
- end
268
-
269
- def matchup_nearest (ref)
270
- ri = ref.sort_addr
271
- rs = ref[ri].to_ca
272
- si = rs.section(self).round.int32
273
- si.trim!(0,si.size)
274
- return ri[si].to_ca
275
- end
276
-
277
- # replace
278
- #
279
- #
280
- def replace (from, to)
281
- self[:eq, from] = to
282
- return self
283
- end
284
-
285
- # reshape
286
-
287
- def reshape (*newdim)
288
- ifalse = nil
289
- i = 0
290
- 0.upto(newdim.size-1) do |i|
291
- if newdim[i].nil?
292
- newdim[i] = dim[i]
293
- elsif newdim[i] == false
294
- ifalse = i
295
- break
296
- end
297
- end
298
- k = 0
299
- (newdim.size-1).downto(i+1) do |j|
300
- if newdim[j].nil?
301
- newdim[j] = dim[rank-1-k]
302
- end
303
- k += 1
304
- end
305
- if ifalse
306
- newdim[ifalse] =
307
- elements/newdim.select{|x| x!=false}.inject(1){|s,x| s*x}
308
- end
309
- return refer(data_type, newdim, :bytes=>bytes)
310
- end
311
-
312
- # flatten
313
-
314
- def flattened
315
- return reshape(elements)
316
- end
317
-
318
- def flatten
319
- return reshape(elements).to_ca
320
- end
321
-
322
- # pulled
323
-
324
- def pulled (*args)
325
- idx = args.map{|s| s.nil? ? :% : s}
326
- return self[*idx]
327
- end
328
-
329
- def pull (*args)
330
- idx = args.map{|s| s.nil? ? :% : s}
331
- return self[*idx].to_ca
332
- end
333
-
334
- # reversed
335
-
336
- def reversed
337
- return self[*([-1..0]*rank)]
338
- end
339
-
340
- # roll / shift
341
-
342
- def shift! (*argv, &block)
343
- self[] = self.shifted(*argv, &block)
344
- return self
345
- end
346
-
347
- def shift (*argv, &block)
348
- return self.shifted(*argv, &block).to_ca
349
- end
350
-
351
- def rolled (*argv)
352
- argv.push({:roll => Array.new(rank){1} })
353
- return shifted(*argv)
354
- end
355
-
356
- def roll! (*argv)
357
- self[] = self.rolled(*argv)
358
- return self
359
- end
360
-
361
- def roll (*argv)
362
- return self.rolled(*argv).to_ca
363
- end
364
-
365
- def transpose! (*argv)
366
- self[] = self.transposed(*argv)
367
- return self
368
- end
369
-
370
- def transpose (*argv)
371
- return self.transposed(*argv).to_ca
372
- end
373
-
374
- # Reutrns the reference which rank is reduced
375
- # by eliminating the dimensions which size == 1
376
- def compacted
377
- if rank == 1
378
- return self[]
379
- else
380
- newdim = dim.reject{|x| x == 1 }
381
- return ( rank != newdim.size ) ? reshape(*newdim) : self[]
382
- end
383
- end
384
-
385
- # Returns the array which rank is reduced
386
- # by eliminating the dimensions which size == 1
387
- def compact
388
- if rank == 1
389
- return self.to_ca
390
- else
391
- newdim = dim.reject{|x| x == 1 }
392
- return ( rank != newdim.size ) ? reshape(*newdim).to_ca : self.to_ca
393
- end
394
- end
395
-
396
- # Returns the reference which elements are sorted by the comparison method
397
- # given as block
398
- def sorted_by (type=nil, opt={}, &block)
399
- type, bytes =
400
- CArray.guess_type_and_bytes(type||data_type, opt[:bytes]||bytes)
401
- cmpary = convert(type, :bytes=>bytes, &block)
402
- return self[cmpary.sort_addr]
403
- end
404
-
405
- # Returns the array which elements are sorted by the comparison method
406
- # given as block
407
- def sort_by (type=nil, opt={}, &block)
408
- type, bytes =
409
- CArray.guess_type_and_bytes(type||data_type, opt[:bytes]||bytes)
410
- cmpary = convert(type, :bytes=>bytes, &block)
411
- return self[cmpary.sort_addr].to_ca
412
- end
413
-
414
- def max_by (&block)
415
- if empty?
416
- return UNDEF
417
- else
418
- addr = convert(:object, &block).max_addr
419
- return self[addr]
420
- end
421
- end
422
-
423
- def min_by (&block)
424
- if empty?
425
- return UNDEF
426
- else
427
- addr = convert(:object, &block).min_addr
428
- return self[addr]
429
- end
430
- end
431
-
432
- def nlargest (n)
433
- obj = self.to_ca
434
- list = []
435
- n.times do |i|
436
- k = obj.max_addr
437
- list << obj[k]
438
- obj[k] = UNDEF
439
- end
440
- list.to_ca.to_type(data_type)
441
- end
442
-
443
- def nlargest_addr (n)
444
- obj = self.to_ca
445
- list = []
446
- n.times do |i|
447
- k = obj.max_addr
448
- list << k
449
- obj[k] = UNDEF
450
- end
451
- CA_INT64(list)
452
- end
453
-
454
- def nsmallest (n)
455
- obj = self.to_ca
456
- list = []
457
- n.times do |i|
458
- k = obj.min_addr
459
- list << obj[k]
460
- obj[k] = UNDEF
461
- end
462
- list.to_ca.to_type(data_type)
463
- end
464
-
465
- def nsmallest_addr (n)
466
- obj = self.to_ca
467
- list = []
468
- n.times do |i|
469
- k = obj.min_addr
470
- list << k
471
- obj[k] = UNDEF
472
- end
473
- CA_INT64(list)
474
- end
475
-
476
- # Returns (1,n) array from 1-dimensional array
477
- def to_row
478
- if rank != 1
479
- raise "rank should be 1"
480
- end
481
- return self[1,:%]
482
- end
483
-
484
- # Returns (n,1) array from 1-dimensional array
485
- def to_column
486
- if rank != 1
487
- raise "rank should be 1"
488
- end
489
- return self[:%,1]
490
- end
491
-
492
- # Returns the array resized to the dimension given as `newdim`.
493
- # The new area is filled by the value returned by the block.
494
- def resize (*newdim, &block)
495
- if newdim.size != rank
496
- raise "rank mismatch"
497
- end
498
- offset = Array.new(rank){0}
499
- rank.times do |i|
500
- d = newdim[i]
501
- case d
502
- when nil
503
- newdim[i] = dim[i]
504
- when Integer
505
- if d < 0
506
- newdim[i] *= -1
507
- offset[i] = newdim[i] - dim[i]
508
- end
509
- else
510
- raise "invalid dimension size"
511
- end
512
- end
513
- out = CArray.new(data_type, newdim, &block)
514
- if out.has_mask?
515
- out.mask.paste(offset, self.false)
516
- end
517
- out.paste(offset, self)
518
- return out
519
- end
520
-
521
- # insert
522
- def insert_block (offset, bsize, &block)
523
- if offset.size != rank or
524
- bsize.size != rank
525
- raise "rank mismatch"
526
- end
527
- newdim = dim
528
- grids = dim.map{|d| CArray.int32(d) }
529
- rank.times do |i|
530
- if offset[i] < 0
531
- offset[i] += dim[i]
532
- end
533
- if offset[i] < 0 or offset[i] >= dim[i] or bsize[i] < 0
534
- raise "invalid offset or size"
535
- end
536
- if bsize[i] > 0
537
- newdim[i] += bsize[i]
538
- end
539
- grids[i][0...offset[i]].seq!
540
- grids[i][offset[i]..-1].seq!(offset[i]+bsize[i])
541
- end
542
- out = CArray.new(data_type, newdim)
543
- if block_given?
544
- sel = out.true
545
- sel[*grids] = 0
546
- out[sel] = block.call
547
- end
548
- out[*grids] = self
549
- return out
550
- end
551
-
552
- def delete_block (offset, bsize)
553
- if offset.size != rank or
554
- bsize.size != rank
555
- raise "rank mismatch"
556
- end
557
- newdim = dim
558
- grids = []
559
- rank.times do |i|
560
- if offset[i] < 0
561
- offset[i] += dim[i]
562
- end
563
- if bsize[i] >= 0
564
- if offset[i] < 0 or offset[i] >= dim[i]
565
- raise "invalid offset or size"
566
- end
567
- newdim[i] -= bsize[i]
568
- else
569
- if offset[i] + bsize[i] + 1 < 0 or offset[i] + bsize[i] > dim[i]
570
- raise "invalid offset or size"
571
- end
572
- newdim[i] += bsize[i]
573
- end
574
- grids[i] = CArray.int32(newdim[i])
575
- if bsize[i] >= 0
576
- if offset[i] > 0
577
- grids[i][0...offset[i]].seq!
578
- end
579
- if offset[i] + bsize[i] < dim[i]
580
- grids[i][offset[i]..-1].seq!(offset[i]+bsize[i])
581
- end
582
- else
583
- if offset[i]+bsize[i] > 0
584
- grids[i][0..offset[i]+bsize[i]].seq!
585
- end
586
- if offset[i]+bsize[i]+1 < dim[i]-1
587
- grids[i][offset[i]+bsize[i]+1..-1].seq!(offset[i]+1)
588
- end
589
- end
590
- end
591
- return self[*grids].to_ca
592
- end
593
-
594
- def where_range
595
- w = where
596
- x = (w - w.shifted(1){-2}).sub!(1).where
597
- y = (w - w.shifted(-1){-2}).add!(1).where
598
- list = []
599
- x.each_addr do |i|
600
- list.push(w[x[i]]..w[y[i]])
601
- end
602
- return list
603
- end
604
-
605
- def order (dir = 1)
606
- if dir >= 0 ### ascending order
607
- if has_mask?
608
- obj = template(:int32) { UNDEF }
609
- sel = is_not_masked
610
- obj[sel][self[sel].sort_addr].seq!
611
- return obj
612
- else
613
- obj = template(:int32)
614
- obj[sort_addr].seq!
615
- return obj
616
- end
617
- else ### descending order
618
- if has_mask?
619
- obj = template(:int32) { UNDEF}
620
- sel = is_not_masked
621
- obj[sel][self[sel].sort_addr.reversed].seq!
622
- return obj
623
- else
624
- obj = template(:int32)
625
- obj[sort_addr.reversed].seq!
626
- return obj
627
- end
628
- end
629
- end
630
-
631
- # Returns the array eliminated all the duplicated elements.
632
- def uniq
633
- ary = to_a.uniq
634
- if has_mask?
635
- ary.delete(UNDEF)
636
- end
637
- if has_data_class?
638
- return CArray.new(data_class, [ary.length]) { ary }
639
- else
640
- return CArray.new(data_type, [ary.length], :bytes=>bytes) { ary }
641
- end
642
- end
643
-
644
- # Returns the array eliminated all the duplicated elements.
645
- def duplicated_values
646
- if uniq.size == size
647
- return []
648
- else
649
- hash = {}
650
- list = []
651
- each_with_addr do |v, addr|
652
- if v == UNDEF
653
- next
654
- elsif hash[v]
655
- list << [v, addr, hash[v]]
656
- hash[v] += 1
657
- else
658
- hash[v] = 0
659
- end
660
- end
661
- return list
662
- end
663
- end
664
-
665
- #
666
- # CArray.span(data_type, range[, step])
667
- # CArray.span(range[, step]) -> data_type guessed by range.first type
668
- #
669
-
670
- def self.span (*argv)
671
- if argv.first.is_a?(Range)
672
- type = nil
673
- else
674
- type, = *CArray.guess_type_and_bytes(argv.shift, nil)
675
- end
676
- range, step = argv[0], argv[1]
677
- start, stop = range.begin, range.end
678
- if step == 0
679
- raise "step should not be 0"
680
- end
681
- if not type
682
- case start
683
- when Integer
684
- type = CA_INT32
685
- when Float
686
- type = CA_FLOAT64
687
- else
688
- type = CA_OBJECT
689
- end
690
- end
691
- if type == CA_OBJECT and not step
692
- return CA_OBJECT(range.to_a)
693
- else
694
- step ||= 1
695
- if range.exclude_end?
696
- n = ((stop - start).abs/step).floor
697
- else
698
- n = ((stop - start).abs/step).floor + 1
699
- end
700
- if start <= stop
701
- return CArray.new(type, [n]).seq(start, step)
702
- else
703
- return CArray.new(type, [n]).seq(start, -step.abs)
704
- end
705
- end
706
- end
707
-
708
- def span! (range)
709
- first = range.begin.to_r
710
- last = range.end.to_r
711
- if range.exclude_end?
712
- seq!(first, (last-first)/elements)
713
- else
714
- seq!(first, (last-first)/(elements-1))
715
- end
716
- return self
717
- end
718
-
719
- def span (range)
720
- return template.span!(range)
721
- end
722
-
723
- #
724
- #
725
- #
726
-
727
- def scale! (xa, xb)
728
- xa = xa.to_f
729
- xb = xb.to_f
730
- seq!(xa, (xb-xa)/(elements-1))
731
- end
732
-
733
- def scale (xa, xb)
734
- template.scale!(xa, xb)
735
- end
736
-
737
- # index / indices / axes
738
-
739
- def address ()
740
- return CArray.int32(*dim).seq!
741
- end
742
-
743
- def index (n = 0)
744
- unless n.is_a?(Integer)
745
- raise ArgumentError, "argument should be an integer"
746
- end
747
- if n.between?(0, rank-1)
748
- return CArray.int32(dim[n]).seq!
749
- else
750
- raise ArgumentError,
751
- "invalid dimension specifier #{n} (0..#{self.rank-1})"
752
- end
753
- end
754
-
755
- #
756
- #
757
- #
758
-
759
- def indices
760
- list = Array.new(rank) {|i|
761
- rpt = self.dim
762
- rpt[i] = :%
763
- index(i)[*rpt]
764
- }
765
- if block_given?
766
- return yield(*list)
767
- else
768
- return list
769
- end
770
- end
771
-
772
- #
773
- # Returns the 8-bit integer CArray object filled with 0 which
774
- # dimension size is same as +self+. The resulted array represents
775
- # the logical array which has +false+ for its all elements.
776
- #
777
- def false ()
778
- return template(:boolean)
779
- end
780
-
781
- #
782
- # Returns the 8-bit integer CArray object filled with 1 which
783
- # dimension size is same as +self+. The resulted array represents
784
- # the logical array which has +true+ for its all elements.
785
- #
786
- def true ()
787
- return template(:boolean) { 1 }
788
- end
789
-
790
- def contains (*list)
791
- result = self.false()
792
- list.each do |item|
793
- result = result | self.eq(item)
794
- end
795
- return result
796
- end
797
-
798
- def between (a, b)
799
- return (self >= a) & (self <= b)
800
- end
801
-
802
- # Returns map
803
- def map (&block)
804
- return self.convert(CA_OBJECT, &block).to_a
805
- end
806
-
807
- # Array#join like method
808
- #
809
- # > a = CArray.object(3,3).seq("a",:succ)
810
- # => <CArray.object(3,3): elem=9 mem=72b
811
- # [ [ "a", "b", "c" ],
812
- # [ "d", "e", "f" ],
813
- # [ "g", "h", "i" ] ]>
814
- #
815
- # > a.join("\n",",")
816
- # => "a,b,c\nd,e,f\ng,h,i"
817
- #
818
-
819
- def join (*argv)
820
- case argv.size
821
- when 0
822
- return to_a.join()
823
- when 1
824
- sep = argv.shift
825
- return to_a.join(sep)
826
- else
827
- sep = argv.shift
828
- return self[:i, false].map { |s|
829
- s[0, false].join(*argv)
830
- }.join(sep)
831
- end
832
- end
833
-
834
- #
835
- def to_bit_string (nb)
836
- hex = CArray.uint8(((nb*elements)/8.0).ceil)
837
- hex.bits[nil].paste([0], self.bits[false,[(nb-1)..0]].flatten)
838
- hex.bits[] = hex.bits[nil,[-1..0]]
839
- return hex.to_s
840
- end
841
-
842
- def from_bit_string (bstr, nb)
843
- hex = CArray.uint8(bstr.length).load_binary(bstr)
844
- hex.bits[] = hex.bits[nil,[-1..0]]
845
- bits = hex.bits.flatten
846
- self.bits[false,[(nb-1)..0]][nil].paste([0], bits)
847
- return self
848
- end
849
-
850
- def self.from_bit_string (bstr, nb, data_type=CA_INT32, dim=nil)
851
- if dim
852
- obj = CArray.new(data_type, dim)
853
- else
854
- dim0 = ((bstr.length*8)/nb.to_f).floor
855
- obj = CArray.new(data_type, [dim0])
856
- end
857
- obj.from_bit_string(bstr, nb)
858
- return obj
859
- end
860
-
861
-
862
- end
863
-
864
- class CArray
865
-
866
- #
867
- # ref = CA_INT([[0,1,2],[1,2,0],[2,0,1]])
868
- # a = CArray.int(3,3).seq(1)
869
- # b = CArray.int(3,3).seq(11)
870
- # c = CArray.int(3,3).seq(21)
871
- #
872
- # CArray.pickup(CA_OBJECT, ref, [a,b,c])
873
- # => <CArray.object(3,3): elem=9 mem=72b
874
- # [ [ 1, 12, 23 ],
875
- # [ 14, 25, 6 ],
876
- # [ 27, 8, 19 ] ]>
877
- #
878
- # CArray.pickup(CA_OBJECT, ref, ["a","b","c"])
879
- # => <CArray.object(3,3): elem=9 mem=36b
880
- # [ [ "a", "b", "c" ],
881
- # [ "b", "c", "a" ],
882
- # [ "c", "a", "b" ] ]>
883
- #
884
- def self.pickup (data_type, ref, args)
885
- out = ref.template(data_type)
886
- args.each_with_index do |v, i|
887
- s = ref.eq(i)
888
- case v
889
- when CArray
890
- out[s] = v[s]
891
- else
892
- out[s] = v
893
- end
894
- end
895
- return out
896
- end
897
-
898
- def self.combine (data_type, tdim, list, at = 0)
899
- has_fill_value = false
900
- if block_given?
901
- fill_value = yield
902
- has_fill_value = true
903
- end
904
- if not tdim.is_a?(Array) or tdim.size == 0
905
- raise "invalid binding dimension"
906
- end
907
- if not list.is_a?(Array) or list.size == 0
908
- raise "invalid list"
909
- end
910
- list = list.map{|x| CArray.wrap_readonly(x, data_type) }
911
- ref = list.detect{|x| x.is_a?(CArray) or not x.scalar? }
912
- unless ref
913
- raise "at least one element in list should be a carray"
914
- end
915
- dim = ref.dim
916
- rank = ref.rank
917
- trank = tdim.size
918
- if at < 0
919
- at += rank - trank + 1
920
- end
921
- unless at.between?(0, rank - trank)
922
- raise "concatnating position out of range"
923
- end
924
- list.map! do |x|
925
- if x.scalar?
926
- rdim = dim.clone
927
- rdim[at] = :%
928
- x = x[*rdim] # convert CScalar to CARepeat
929
- end
930
- x
931
- end
932
- block = CArray.object(*tdim){ list }
933
- edim = tdim.clone
934
- idx = Array.new(tdim)
935
- offset = Array.new(tdim.size) { [] }
936
- tdim.each_with_index do |td, i|
937
- edim[i] = 0
938
- idx.map!{0}
939
- idx[i] = nil
940
- block[*idx].each do |e|
941
- offset[i] << edim[i]
942
- edim[i] += e.dim[at+i] # extended dimension size
943
- end
944
- end
945
- newdim = dim.clone
946
- newdim[at,trank] = edim # extended dimension size
947
- if has_fill_value
948
- obj = CArray.new(data_type, newdim) { fill_value }
949
- else
950
- obj = CArray.new(data_type, newdim)
951
- end
952
- idx = newdim.map{0}
953
- block.each_with_index do |item, tidx|
954
- (at...at+trank).each_with_index do |d,i|
955
- idx[d] = offset[i][tidx[i]]
956
- end
957
- obj.paste(idx, item)
958
- end
959
- obj
960
- end
961
-
962
- def self.bind (data_type, list, at = 0)
963
- return CArray.combine(data_type, [list.size], list, at)
964
- end
965
-
966
- def self.composite (data_type, tdim, list, at = 0)
967
- if not tdim.is_a?(Array) or tdim.size == 0
968
- raise "invalid tiling dimension"
969
- end
970
- if not list.is_a?(Array) or list.size == 0
971
- raise "invalid carray list"
972
- end
973
- list = list.map{|x| CArray.wrap_readonly(x, data_type) }
974
- ref = list.detect{|x| x.is_a?(CArray) or not x.scalar? }
975
- unless ref
976
- raise "at least one element in list should be a carray"
977
- end
978
- dim = ref.dim
979
- rank = ref.rank
980
- if at < 0
981
- at += rank + 1 # "+ 1" is needed here
982
- end
983
- unless at.between?(0,rank)
984
- raise "tiling position is out of range"
985
- end
986
- trank = tdim.size
987
- list.map! do |x|
988
- if x.scalar?
989
- rdim = dim.clone
990
- rdim[at] = :%
991
- x = x[*rdim] # convert CScalar to CARepeat
992
- end
993
- x
994
- end
995
- newdim = dim.clone
996
- newdim[at,0] = tdim
997
- obj = CArray.new(data_type, newdim)
998
- idx = Array.new(rank+trank) { nil }
999
- CArray.each_index(*tdim) do |*tidx|
1000
- idx[at,trank] = tidx
1001
- obj[*idx] = list.shift
1002
- end
1003
- obj
1004
- end
1005
-
1006
- def self.merge (data_type, list, at = -1)
1007
- return CArray.composite(data_type, [list.size], list, at)
1008
- end
1009
-
1010
- def self.join (*argv)
1011
- # get options
1012
- case argv.first
1013
- when Integer, Symbol, String
1014
- type, = *CArray.guess_type_and_bytes(argv.shift, 0)
1015
- else
1016
- type = argv.flatten.first.data_type
1017
- end
1018
- # process
1019
- conc = argv.map do |list|
1020
- case list
1021
- when CArray
1022
- if list.rank == 1
1023
- list[:%,1]
1024
- else
1025
- list
1026
- end
1027
- when Array
1028
- x0 = list.first
1029
- if list.size == 1 and
1030
- x0.is_a?(CArray) and
1031
- x0.rank == 1
1032
- list = [x0[:%,1]]
1033
- else
1034
- list = list.map { |x|
1035
- case x
1036
- when CArray
1037
- if x.rank == 1
1038
- x[:%,1]
1039
- else
1040
- x
1041
- end
1042
- when Array
1043
- y = x.first
1044
- if x.size == 1 and
1045
- y.is_a?(CArray) and
1046
- y.rank == 1
1047
- y[1,:%]
1048
- else
1049
- CArray.join(*x)
1050
- end
1051
- else
1052
- x
1053
- end
1054
- }
1055
- end
1056
- if block_given?
1057
- CArray.bind(type, list, 1, &block)
1058
- else
1059
- CArray.bind(type, list, 1)
1060
- end
1061
- else
1062
- list
1063
- end
1064
- end
1065
- if conc.size > 1
1066
- return CArray.bind(type, conc)
1067
- else
1068
- return conc.first
1069
- end
1070
- end
1071
-
1072
- # Returns object carray has elements of splitted carray at dimensions
1073
- # which is given by arguments
1074
- #
1075
- # a = CA_INT([[1,2,3], [4,5,6], [7,8,9]])
1076
- #
1077
- # a.split(0)
1078
- # [1,2,3], [4,5,6], [7,8,9]
1079
- #
1080
- # a.split(1)
1081
- # [1,4,7], [2,5,8], [3,6,9]
1082
- #
1083
-
1084
- def split (*argv)
1085
- odim = dim.values_at(*argv)
1086
- out = CArray.object(*odim)
1087
- idx = [nil] * rank
1088
- attach {
1089
- out.map_with_index! do |o, v|
1090
- argv.each_with_index do |r, i|
1091
- idx[r] = v[i]
1092
- end
1093
- self[*idx].to_ca
1094
- end
1095
- }
1096
- return out
1097
- end
1098
-
1099
- end
1100
-
1101
- class CAUnboundRepeat
1102
-
1103
- def template (*argv, &block)
1104
- return parent.template(*argv,&block)[*spec.map{|x| x != :* ? nil : x}]
1105
- end
1106
-
1107
- end
1108
-
1109
- class Numeric
1110
-
1111
- def eq (other)
1112
- case other
1113
- when CArray
1114
- return other.eq(self)
1115
- else
1116
- return send(:eq, *other.coerce(self))
1117
- end
1118
- end
1119
-
1120
- def ne (other)
1121
- case other
1122
- when CArray
1123
- return other.ne(self)
1124
- else
1125
- return send(:ne, *other.coerce(self))
1126
- end
1127
- end
1128
-
1129
- end
1130
-
1131
- module CA
1132
-
1133
- def self.meshgrid (*args)
1134
- dim = args.map(&:size)
1135
- out = []
1136
- args.each_with_index do |arg, i|
1137
- newdim = dim.dup
1138
- newdim[i] = :%
1139
- out[i] = arg[*newdim].to_ca
1140
- end
1141
- return *out
1142
- end
1143
-
1144
- end
1145
-
1146
-