carray 1.3.5 → 1.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (195) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSES +22 -0
  3. data/README.md +18 -21
  4. data/Rakefile +31 -0
  5. data/carray.gemspec +13 -26
  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} +77 -51
  28. data/{carray_access.c → ext/carray_access.c} +133 -91
  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} +11 -13
  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} +67 -1
  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} +25 -25
  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} +32 -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} +12 -2
  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 +49 -7
  62. data/lib/carray/{base/autoload.rb → autoload.rb} +48 -6
  63. data/lib/carray/autoload/autoload_base.rb +1 -5
  64. data/lib/carray/autoload/autoload_gem_cairo.rb +9 -0
  65. data/lib/carray/autoload/autoload_gem_ffi.rb +9 -0
  66. data/lib/carray/autoload/autoload_gem_gnuplot.rb +2 -0
  67. data/lib/carray/autoload/autoload_gem_io_csv.rb +14 -0
  68. data/lib/carray/autoload/autoload_gem_io_pg.rb +6 -0
  69. data/lib/carray/autoload/autoload_gem_io_sqlite3.rb +12 -0
  70. data/lib/carray/autoload/autoload_gem_narray.rb +10 -0
  71. data/lib/carray/autoload/autoload_gem_numo_narray.rb +15 -0
  72. data/lib/carray/autoload/autoload_gem_opencv.rb +16 -0
  73. data/lib/carray/autoload/autoload_gem_random.rb +8 -0
  74. data/lib/carray/autoload/autoload_gem_rmagick.rb +23 -0
  75. data/lib/carray/autoload/{autoload_graphics_zimg.rb → autoload_gem_zimg.rb} +0 -0
  76. data/lib/carray/basic.rb +193 -0
  77. data/lib/carray/compose.rb +291 -0
  78. data/lib/carray/construct.rb +445 -0
  79. data/lib/carray/convert.rb +115 -0
  80. data/lib/carray/{base/inspect.rb → inspect.rb} +6 -6
  81. data/lib/carray/io/imagemagick.rb +1 -1
  82. data/lib/carray/{base/iterator.rb → iterator.rb} +3 -3
  83. data/lib/carray/mask.rb +91 -0
  84. data/lib/carray/{base/math.rb → math.rb} +17 -47
  85. data/lib/carray/math/histogram.rb +7 -7
  86. data/lib/carray/mkmf.rb +8 -0
  87. data/lib/carray/object/ca_obj_pack.rb +8 -8
  88. data/lib/carray/obsolete.rb +272 -0
  89. data/lib/carray/ordering.rb +157 -0
  90. data/lib/carray/{base/serialize.rb → serialize.rb} +28 -53
  91. data/lib/carray/string.rb +190 -0
  92. data/lib/carray/{base/struct.rb → struct.rb} +20 -20
  93. data/lib/carray/{io/table.rb → table.rb} +1 -9
  94. data/lib/carray/testing.rb +56 -0
  95. data/lib/carray/time.rb +78 -0
  96. data/lib/carray/transform.rb +100 -0
  97. data/misc/Methods.ja.md +182 -0
  98. data/{NOTE → misc/NOTE} +0 -0
  99. data/test/test_ALL.rb +0 -2
  100. data/test/test_order.rb +7 -7
  101. data/test/test_ref_store.rb +13 -13
  102. data/test/test_stat.rb +7 -15
  103. data/{devel → utils}/guess_shape.rb +0 -0
  104. data/utils/{diff_method.rb → monkey_patch_methods.rb} +17 -7
  105. metadata +100 -254
  106. data/COPYING +0 -56
  107. data/GPL +0 -340
  108. data/Gemfile +0 -8
  109. data/Gemfile.lock +0 -33
  110. data/LEGAL +0 -50
  111. data/TODO +0 -5
  112. data/carray_random.c +0 -531
  113. data/ext/calculus/carray_calculus.c +0 -931
  114. data/ext/calculus/carray_interp.c +0 -358
  115. data/ext/calculus/extconf.rb +0 -12
  116. data/ext/calculus/lib/autoload/autoload_math_calculus.rb +0 -2
  117. data/ext/calculus/lib/math/calculus.rb +0 -119
  118. data/ext/calculus/lib/math/interp/adapter_interp1d.rb +0 -31
  119. data/ext/fortio/extconf.rb +0 -3
  120. data/ext/fortio/lib/carray/autoload/autoload_fortran_format.rb +0 -5
  121. data/ext/fortio/lib/carray/io/fortran_format.rb +0 -43
  122. data/ext/fortio/lib/fortio.rb +0 -3
  123. data/ext/fortio/lib/fortio/fortran_format.rb +0 -605
  124. data/ext/fortio/lib/fortio/fortran_format.tab.rb +0 -536
  125. data/ext/fortio/lib/fortio/fortran_format.y +0 -215
  126. data/ext/fortio/lib/fortio/fortran_namelist.rb +0 -151
  127. data/ext/fortio/lib/fortio/fortran_namelist.tab.rb +0 -470
  128. data/ext/fortio/lib/fortio/fortran_namelist.y +0 -213
  129. data/ext/fortio/lib/fortio/fortran_sequential.rb +0 -345
  130. data/ext/fortio/ruby_fortio.c +0 -182
  131. data/ext/fortio/test/test_H.rb +0 -5
  132. data/ext/fortio/test/test_T.rb +0 -7
  133. data/ext/fortio/test/test_fortran_format.rb +0 -86
  134. data/ext/fortio/test/test_namelist.rb +0 -25
  135. data/ext/fortio/test/test_namelist_write.rb +0 -10
  136. data/ext/fortio/test/test_sequential.rb +0 -13
  137. data/ext/fortio/test/test_sequential2.rb +0 -13
  138. data/ext/fortio/work/test.rb +0 -10
  139. data/ext/fortio/work/test_e.rb +0 -19
  140. data/ext/fortio/work/test_ep.rb +0 -10
  141. data/ext/fortio/work/test_parse.rb +0 -12
  142. data/ext/imagemap/carray_imagemap.c +0 -495
  143. data/ext/imagemap/doc/call_graph.dot +0 -28
  144. data/ext/imagemap/draw.c +0 -567
  145. data/ext/imagemap/extconf.rb +0 -13
  146. data/ext/imagemap/lib/autoload/autoload_graphics_imagemap.rb +0 -1
  147. data/ext/imagemap/lib/graphics/imagemap.rb +0 -273
  148. data/ext/imagemap/lib/image_map.rb +0 -4
  149. data/ext/imagemap/test/swath_index.rb +0 -83
  150. data/ext/imagemap/test/swath_warp.rb +0 -99
  151. data/ext/imagemap/test/test.rb +0 -23
  152. data/ext/imagemap/test/test_image.rb +0 -42
  153. data/ext/imagemap/test/test_line.rb +0 -14
  154. data/ext/imagemap/test/test_rotate.rb +0 -17
  155. data/ext/imagemap/test/test_triangle.rb +0 -20
  156. data/ext/imagemap/test/test_warp.rb +0 -26
  157. data/ext/mathfunc/extconf.rb +0 -18
  158. data/ext/mathfunc/lib/autoload/autoload_math_mathfunc.rb +0 -1
  159. data/ext/mathfunc/lib/math/mathfunc.rb +0 -15
  160. data/ext/mathfunc/test/test_hypot.rb +0 -5
  161. data/ext/mathfunc/test/test_j0.rb +0 -22
  162. data/ext/mathfunc/test/test_jn.rb +0 -8
  163. data/ext/mathfunc/test/test_sph.rb +0 -9
  164. data/ext/narray/README +0 -22
  165. data/ext/narray/ca_wrap_narray.c +0 -500
  166. data/ext/narray/carray_narray.c +0 -21
  167. data/ext/narray/extconf.rb +0 -57
  168. data/ext/narray/lib/autoload/autoload_math_narray.rb +0 -1
  169. data/ext/narray/lib/autoload/autoload_math_narray_miss.rb +0 -11
  170. data/ext/narray/lib/math/narray.rb +0 -17
  171. data/ext/narray/lib/math/narray_miss.rb +0 -45
  172. data/lib/carray/autoload/autoload_graphics_gnuplot.rb +0 -2
  173. data/lib/carray/autoload/autoload_io_csv.rb +0 -14
  174. data/lib/carray/autoload/autoload_io_pg.rb +0 -6
  175. data/lib/carray/autoload/autoload_io_sqlite3.rb +0 -12
  176. data/lib/carray/autoload/autoload_io_table.rb +0 -1
  177. data/lib/carray/autoload/autoload_math_interp.rb +0 -4
  178. data/lib/carray/base/basic.rb +0 -1090
  179. data/lib/carray/base/obsolete.rb +0 -131
  180. data/lib/carray/graphics/gnuplot.rb +0 -2131
  181. data/lib/carray/graphics/zimg.rb +0 -296
  182. data/lib/carray/io/csv.rb +0 -572
  183. data/lib/carray/io/pg.rb +0 -101
  184. data/lib/carray/io/sqlite3.rb +0 -215
  185. data/lib/carray/math/interp.rb +0 -57
  186. data/lib/carray/math/interp/adapter_gsl_spline.rb +0 -47
  187. data/mt19937ar.c +0 -182
  188. data/mt19937ar.h +0 -86
  189. data/rdoc_main.rb +0 -27
  190. data/rdoc_math.rb +0 -5
  191. data/rdoc_stat.rb +0 -31
  192. data/test/test_narray.rb +0 -64
  193. data/test/test_random.rb +0 -15
  194. data/utils/create_rdoc.sh +0 -9
  195. data/utils/make_tgz.sh +0 -3
@@ -1,21 +0,0 @@
1
- /* ---------------------------------------------------------------------------
2
-
3
- carray/carray_narray.c
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
- #include "ruby.h"
14
-
15
- void Init_ca_wrap_narray();
16
-
17
- void
18
- Init_carray_narray ()
19
- {
20
- Init_ca_wrap_narray();
21
- }
@@ -1,57 +0,0 @@
1
- require 'mkmf'
2
- require 'rbconfig'
3
- require_relative '../../lib/carray/mkmf'
4
-
5
- dir_config("carray", "../..", "../..")
6
-
7
- have_header("carray.h")
8
-
9
- if /cygwin|mingw/ =~ RUBY_PLATFORM
10
- have_library("carray")
11
- end
12
-
13
- # ---
14
-
15
- dir_config("narray", $sitearchdir, $sitearchdir)
16
-
17
- if defined? Gem
18
- if Gem::VERSION >= "1.7.0"
19
- begin
20
- Gem::Specification.find_all_by_name("narray").each do |spec|
21
- dir = spec.full_gem_path
22
- dir_config("narray", dir, dir)
23
- dir_config("narray", File.join(dir,"src"), File.join(dir,"src"))
24
- end
25
- rescue Gem::LoadError
26
- end
27
- else
28
- Gem.all_load_paths.grep(/narray/).each do |dir|
29
- dir_config("narray", dir, dir)
30
- dir_config("narray", File.join(dir,"src"), File.join(dir,"src"))
31
- end
32
- end
33
- end
34
-
35
- if have_header("narray.h")
36
- if /cygwin|mingw/ =~ RUBY_PLATFORM
37
- unless have_library("narray")
38
- open("Makefile", "w") { |io|
39
- io << "all:" << "\n"
40
- io << "install:" << "\n"
41
- io << "clean:" << "\n"
42
- io << "distclean:" << "\n"
43
- io << "\trm -rf mkmf.log Makefile" << "\n"
44
- }
45
- end
46
- end
47
- create_makefile("carray/carray_narray")
48
- else
49
- open("Makefile", "w") { |io|
50
- io << "all:" << "\n"
51
- io << "install:" << "\n"
52
- io << "clean:" << "\n"
53
- io << "distclean:" << "\n"
54
- io << "\trm -rf mkmf.log Makefile" << "\n"
55
- }
56
- end
57
-
@@ -1 +0,0 @@
1
- require "carray/math/narray"
@@ -1,11 +0,0 @@
1
-
2
- class CArray
3
- nam_rb = "carray/math/narray_miss"
4
- autoload_method :to_nam, nam_rb
5
- autoload_method :to_nam!, nam_rb
6
- end
7
-
8
- class NArrayMiss
9
- nam_rb = "carray/math/narray_miss"
10
- autoload_method :to_ca, nam_rb
11
- end
@@ -1,17 +0,0 @@
1
- # ----------------------------------------------------------------------------
2
- #
3
- # carray/math/narray.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
- begin
14
- require "narray"
15
- require "carray/carray_narray"
16
- rescue LoadError, TypeError
17
- end
@@ -1,45 +0,0 @@
1
- # ----------------------------------------------------------------------------
2
- #
3
- # carray/math/narray_miss.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 "narray_miss"
14
-
15
- class CArray
16
-
17
- def to_nam
18
- if has_mask?
19
- return NArrayMiss.to_nam_no_dup(to_na, mask.bit_neg.na)
20
- else
21
- return NArrayMiss.to_nam_no_dup(to_na)
22
- end
23
- end
24
-
25
- def to_nam!
26
- if has_mask?
27
- return NArrayMiss.to_nam_no_dup(to_na!, mask.bit_neg.to_na!)
28
- else
29
- return NArrayMiss.to_nam_no_dup(to_na!)
30
- end
31
- end
32
-
33
- end
34
-
35
- class NArrayMiss
36
-
37
- def to_ca
38
- ca = @array.to_ca
39
- ca.mask = @mask.ca
40
- ca.mask.bit_neg!
41
- return ca
42
- end
43
-
44
- end
45
-
@@ -1,2 +0,0 @@
1
- autoload_method "CA.gnuplot", "carray/graphics/gnuplot"
2
-
@@ -1,14 +0,0 @@
1
- autoload_method "CArray.load_csv", "carray/io/csv"
2
- autoload_method "CArray.from_csv", "carray/io/csv"
3
-
4
- class CArray
5
- autoload_method "save_csv", "carray/io/csv"
6
- autoload_method "to_csv", "carray/io/csv"
7
- autoload_method "to_tabular", "carray/io/csv"
8
- end
9
-
10
- module CA
11
- autoload :CSVReader, "carray/io/csv"
12
- autoload :CSVWriter, "carray/io/csv"
13
- end
14
-
@@ -1,6 +0,0 @@
1
- autoload_method "CArray.load_pg", "carray/io/pg"
2
-
3
- class CArray
4
- autoload_method "unescape_bytea", "carray/io/pg"
5
- autoload_method "escape_bytea", "carray/io/pg"
6
- end
@@ -1,12 +0,0 @@
1
- autoload_method "CArray.load_sqlite3", "carray/io/sqlite3"
2
-
3
- class CArray
4
- autoload_method "unblob", "carray/io/sqlite3"
5
- autoload_method "to_sqlite3", "carray/io/sqlite3"
6
- end
7
-
8
- if Object.const_defined?(:SQLite3)
9
- require "carray/io/sqlite3"
10
- else
11
- autoload :SQLite3, "carray/io/sqlite3"
12
- end
@@ -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,1090 +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
- # Returns (1,n) array from 1-dimensional array
433
- def to_row
434
- if rank != 1
435
- raise "rank should be 1"
436
- end
437
- return self[1,:%]
438
- end
439
-
440
- # Returns (n,1) array from 1-dimensional array
441
- def to_column
442
- if rank != 1
443
- raise "rank should be 1"
444
- end
445
- return self[:%,1]
446
- end
447
-
448
- # Returns the array resized to the dimension given as `newdim`.
449
- # The new area is filled by the value returned by the block.
450
- def resize (*newdim, &block)
451
- if newdim.size != rank
452
- raise "rank mismatch"
453
- end
454
- offset = Array.new(rank){0}
455
- rank.times do |i|
456
- d = newdim[i]
457
- case d
458
- when nil
459
- newdim[i] = dim[i]
460
- when Integer
461
- if d < 0
462
- newdim[i] *= -1
463
- offset[i] = newdim[i] - dim[i]
464
- end
465
- else
466
- raise "invalid dimension size"
467
- end
468
- end
469
- out = CArray.new(data_type, newdim, &block)
470
- if out.has_mask?
471
- out.mask.paste(offset, self.false)
472
- end
473
- out.paste(offset, self)
474
- return out
475
- end
476
-
477
- # insert
478
- def insert_block (offset, bsize, &block)
479
- if offset.size != rank or
480
- bsize.size != rank
481
- raise "rank mismatch"
482
- end
483
- newdim = dim
484
- grids = dim.map{|d| CArray.int32(d) }
485
- rank.times do |i|
486
- if offset[i] < 0
487
- offset[i] += dim[i]
488
- end
489
- if offset[i] < 0 or offset[i] >= dim[i] or bsize[i] < 0
490
- raise "invalid offset or size"
491
- end
492
- if bsize[i] > 0
493
- newdim[i] += bsize[i]
494
- end
495
- grids[i][0...offset[i]].seq!
496
- grids[i][offset[i]..-1].seq!(offset[i]+bsize[i])
497
- end
498
- out = CArray.new(data_type, newdim)
499
- if block_given?
500
- sel = out.true
501
- sel[*grids] = 0
502
- out[sel] = block.call
503
- end
504
- out[*grids] = self
505
- return out
506
- end
507
-
508
- def delete_block (offset, bsize)
509
- if offset.size != rank or
510
- bsize.size != rank
511
- raise "rank mismatch"
512
- end
513
- newdim = dim
514
- grids = []
515
- rank.times do |i|
516
- if offset[i] < 0
517
- offset[i] += dim[i]
518
- end
519
- if bsize[i] >= 0
520
- if offset[i] < 0 or offset[i] >= dim[i]
521
- raise "invalid offset or size"
522
- end
523
- newdim[i] -= bsize[i]
524
- else
525
- if offset[i] + bsize[i] + 1 < 0 or offset[i] + bsize[i] > dim[i]
526
- raise "invalid offset or size"
527
- end
528
- newdim[i] += bsize[i]
529
- end
530
- grids[i] = CArray.int32(newdim[i])
531
- if bsize[i] >= 0
532
- if offset[i] > 0
533
- grids[i][0...offset[i]].seq!
534
- end
535
- if offset[i] + bsize[i] < dim[i]
536
- grids[i][offset[i]..-1].seq!(offset[i]+bsize[i])
537
- end
538
- else
539
- if offset[i]+bsize[i] > 0
540
- grids[i][0..offset[i]+bsize[i]].seq!
541
- end
542
- if offset[i]+bsize[i]+1 < dim[i]-1
543
- grids[i][offset[i]+bsize[i]+1..-1].seq!(offset[i]+1)
544
- end
545
- end
546
- end
547
- return self[*grids].to_ca
548
- end
549
-
550
- def where_range
551
- w = where
552
- x = (w - w.shifted(1){-2}).sub!(1).where
553
- y = (w - w.shifted(-1){-2}).add!(1).where
554
- list = []
555
- x.each_addr do |i|
556
- list.push(w[x[i]]..w[y[i]])
557
- end
558
- return list
559
- end
560
-
561
- def order (dir = 1)
562
- if dir >= 0 ### ascending order
563
- if has_mask?
564
- obj = template(:int32) { UNDEF }
565
- sel = is_not_masked
566
- obj[sel][self[sel].sort_addr].seq!
567
- return obj
568
- else
569
- obj = template(:int32)
570
- obj[sort_addr].seq!
571
- return obj
572
- end
573
- else ### descending order
574
- if has_mask?
575
- obj = template(:int32) { UNDEF}
576
- sel = is_not_masked
577
- obj[sel][self[sel].sort_addr.reversed].seq!
578
- return obj
579
- else
580
- obj = template(:int32)
581
- obj[sort_addr.reversed].seq!
582
- return obj
583
- end
584
- end
585
- end
586
-
587
- # Returns the array eliminated all the duplicated elements.
588
- def uniq
589
- ary = to_a.uniq
590
- if has_mask?
591
- ary.delete(UNDEF)
592
- end
593
- if has_data_class?
594
- return CArray.new(data_class, [ary.length]) { ary }
595
- else
596
- return CArray.new(data_type, [ary.length], :bytes=>bytes) { ary }
597
- end
598
- end
599
-
600
- # Returns the array eliminated all the duplicated elements.
601
- def duplicated_values
602
- if uniq.size == size
603
- return []
604
- else
605
- hash = {}
606
- list = []
607
- each_with_addr do |v, addr|
608
- if v == UNDEF
609
- next
610
- elsif hash[v]
611
- list << [v, addr, hash[v]]
612
- hash[v] += 1
613
- else
614
- hash[v] = 0
615
- end
616
- end
617
- return list
618
- end
619
- end
620
-
621
- #
622
- # CArray.span(data_type, range[, step])
623
- # CArray.span(range[, step]) -> data_type guessed by range.first type
624
- #
625
-
626
- def self.span (*argv)
627
- if argv.first.is_a?(Range)
628
- type = nil
629
- else
630
- type, = *CArray.guess_type_and_bytes(argv.shift, nil)
631
- end
632
- range, step = argv[0], argv[1]
633
- start, stop = range.begin, range.end
634
- if step == 0
635
- raise "step should not be 0"
636
- end
637
- if not type
638
- case start
639
- when Integer
640
- type = CA_INT32
641
- when Float
642
- type = CA_FLOAT64
643
- else
644
- type = CA_OBJECT
645
- end
646
- end
647
- if type == CA_OBJECT and not step
648
- return CA_OBJECT(range.to_a)
649
- else
650
- step ||= 1
651
- if range.exclude_end?
652
- n = ((stop - start).abs/step).floor
653
- else
654
- n = ((stop - start).abs/step).floor + 1
655
- end
656
- if start <= stop
657
- return CArray.new(type, [n]).seq(start, step)
658
- else
659
- return CArray.new(type, [n]).seq(start, -step.abs)
660
- end
661
- end
662
- end
663
-
664
- def span! (range)
665
- first = range.begin.to_r
666
- last = range.end.to_r
667
- if range.exclude_end?
668
- seq!(first, (last-first)/elements)
669
- else
670
- seq!(first, (last-first)/(elements-1))
671
- end
672
- return self
673
- end
674
-
675
- def span (range)
676
- return template.span!(range)
677
- end
678
-
679
- #
680
- #
681
- #
682
-
683
- def scale! (xa, xb)
684
- xa = xa.to_f
685
- xb = xb.to_f
686
- seq!(xa, (xb-xa)/(elements-1))
687
- end
688
-
689
- def scale (xa, xb)
690
- template.scale!(xa, xb)
691
- end
692
-
693
- # index / indices / axes
694
-
695
- def address ()
696
- return CArray.int32(*dim).seq!
697
- end
698
-
699
- def index (n)
700
- unless n.is_a?(Integer)
701
- raise ArgumentError, "argument should be an integer"
702
- end
703
- if n.between?(0, rank-1)
704
- return CArray.int32(dim[n]).seq!
705
- else
706
- raise ArgumentError,
707
- "invalid dimension specifier #{n} (0..#{self.rank-1})"
708
- end
709
- end
710
-
711
- #
712
- #
713
- #
714
-
715
- def indices
716
- list = Array.new(rank) {|i|
717
- rpt = self.dim
718
- rpt[i] = :%
719
- index(i)[*rpt]
720
- }
721
- if block_given?
722
- return yield(*list)
723
- else
724
- return list
725
- end
726
- end
727
-
728
- #
729
- # Returns the 8-bit integer CArray object filled with 0 which
730
- # dimension size is same as +self+. The resulted array represents
731
- # the logical array which has +false+ for its all elements.
732
- #
733
- def false ()
734
- return template(:boolean)
735
- end
736
-
737
- #
738
- # Returns the 8-bit integer CArray object filled with 1 which
739
- # dimension size is same as +self+. The resulted array represents
740
- # the logical array which has +true+ for its all elements.
741
- #
742
- def true ()
743
- return template(:boolean) { 1 }
744
- end
745
-
746
- # Returns map
747
- def map (&block)
748
- return self.convert(CA_OBJECT, &block).to_a
749
- end
750
-
751
- # Array#join like method
752
- #
753
- # > a = CArray.object(3,3).seq("a",:succ)
754
- # => <CArray.object(3,3): elem=9 mem=72b
755
- # [ [ "a", "b", "c" ],
756
- # [ "d", "e", "f" ],
757
- # [ "g", "h", "i" ] ]>
758
- #
759
- # > a.join("\n",",")
760
- # => "a,b,c\nd,e,f\ng,h,i"
761
- #
762
-
763
- def join (*argv)
764
- case argv.size
765
- when 0
766
- return to_a.join()
767
- when 1
768
- sep = argv.shift
769
- return to_a.join(sep)
770
- else
771
- sep = argv.shift
772
- return self[:i, false].map { |s|
773
- s[0, false].join(*argv)
774
- }.join(sep)
775
- end
776
- end
777
-
778
- #
779
- def to_bit_string (nb)
780
- hex = CArray.uint8(((nb*elements)/8.0).ceil)
781
- hex.bits[nil].paste([0], self.bits[false,[(nb-1)..0]].flatten)
782
- hex.bits[] = hex.bits[nil,[-1..0]]
783
- return hex.to_s
784
- end
785
-
786
- def from_bit_string (bstr, nb)
787
- hex = CArray.uint8(bstr.length).load_binary(bstr)
788
- hex.bits[] = hex.bits[nil,[-1..0]]
789
- bits = hex.bits.flatten
790
- self.bits[false,[(nb-1)..0]][nil].paste([0], bits)
791
- return self
792
- end
793
-
794
- def self.from_bit_string (bstr, nb, data_type=CA_INT32, dim=nil)
795
- if dim
796
- obj = CArray.new(data_type, dim)
797
- else
798
- dim0 = ((bstr.length*8)/nb.to_f).floor
799
- obj = CArray.new(data_type, [dim0])
800
- end
801
- obj.from_bit_string(bstr, nb)
802
- return obj
803
- end
804
-
805
- end
806
-
807
-
808
- class CArray
809
-
810
- #
811
- # ref = CA_INT([[0,1,2],[1,2,0],[2,0,1]])
812
- # a = CArray.int(3,3).seq(1)
813
- # b = CArray.int(3,3).seq(11)
814
- # c = CArray.int(3,3).seq(21)
815
- #
816
- # CArray.pickup(CA_OBJECT, ref, [a,b,c])
817
- # => <CArray.object(3,3): elem=9 mem=72b
818
- # [ [ 1, 12, 23 ],
819
- # [ 14, 25, 6 ],
820
- # [ 27, 8, 19 ] ]>
821
- #
822
- # CArray.pickup(CA_OBJECT, ref, ["a","b","c"])
823
- # => <CArray.object(3,3): elem=9 mem=36b
824
- # [ [ "a", "b", "c" ],
825
- # [ "b", "c", "a" ],
826
- # [ "c", "a", "b" ] ]>
827
- #
828
- def self.pickup (data_type, ref, args)
829
- out = ref.template(data_type)
830
- args.each_with_index do |v, i|
831
- s = ref.eq(i)
832
- case v
833
- when CArray
834
- out[s] = v[s]
835
- else
836
- out[s] = v
837
- end
838
- end
839
- return out
840
- end
841
-
842
- def self.combine (data_type, tdim, list, at = 0)
843
- has_fill_value = false
844
- if block_given?
845
- fill_value = yield
846
- has_fill_value = true
847
- end
848
- if not tdim.is_a?(Array) or tdim.size == 0
849
- raise "invalid binding dimension"
850
- end
851
- if not list.is_a?(Array) or list.size == 0
852
- raise "invalid list"
853
- end
854
- list = list.map{|x| CArray.wrap_readonly(x, data_type) }
855
- ref = list.detect{|x| x.is_a?(CArray) or not x.scalar? }
856
- unless ref
857
- raise "at least one element in list should be a carray"
858
- end
859
- dim = ref.dim
860
- rank = ref.rank
861
- trank = tdim.size
862
- if at < 0
863
- at += rank - trank + 1
864
- end
865
- unless at.between?(0, rank - trank)
866
- raise "concatnating position out of range"
867
- end
868
- list.map! do |x|
869
- if x.scalar?
870
- rdim = dim.clone
871
- rdim[at] = :%
872
- x = x[*rdim] # convert CScalar to CARepeat
873
- end
874
- x
875
- end
876
- block = CArray.object(*tdim){ list }
877
- edim = tdim.clone
878
- idx = Array.new(tdim)
879
- offset = Array.new(tdim.size) { [] }
880
- tdim.each_with_index do |td, i|
881
- edim[i] = 0
882
- idx.map!{0}
883
- idx[i] = nil
884
- block[*idx].each do |e|
885
- offset[i] << edim[i]
886
- edim[i] += e.dim[at+i] # extended dimension size
887
- end
888
- end
889
- newdim = dim.clone
890
- newdim[at,trank] = edim # extended dimension size
891
- if has_fill_value
892
- obj = CArray.new(data_type, newdim) { fill_value }
893
- else
894
- obj = CArray.new(data_type, newdim)
895
- end
896
- idx = newdim.map{0}
897
- block.each_with_index do |item, tidx|
898
- (at...at+trank).each_with_index do |d,i|
899
- idx[d] = offset[i][tidx[i]]
900
- end
901
- obj.paste(idx, item)
902
- end
903
- obj
904
- end
905
-
906
- def self.bind (data_type, list, at = 0)
907
- return CArray.combine(data_type, [list.size], list, at)
908
- end
909
-
910
- def self.composite (data_type, tdim, list, at = 0)
911
- if not tdim.is_a?(Array) or tdim.size == 0
912
- raise "invalid tiling dimension"
913
- end
914
- if not list.is_a?(Array) or list.size == 0
915
- raise "invalid carray list"
916
- end
917
- list = list.map{|x| CArray.wrap_readonly(x, data_type) }
918
- ref = list.detect{|x| x.is_a?(CArray) or not x.scalar? }
919
- unless ref
920
- raise "at least one element in list should be a carray"
921
- end
922
- dim = ref.dim
923
- rank = ref.rank
924
- if at < 0
925
- at += rank + 1 # "+ 1" is needed here
926
- end
927
- unless at.between?(0,rank)
928
- raise "tiling position is out of range"
929
- end
930
- trank = tdim.size
931
- list.map! do |x|
932
- if x.scalar?
933
- rdim = dim.clone
934
- rdim[at] = :%
935
- x = x[*rdim] # convert CScalar to CARepeat
936
- end
937
- x
938
- end
939
- newdim = dim.clone
940
- newdim[at,0] = tdim
941
- obj = CArray.new(data_type, newdim)
942
- idx = Array.new(rank+trank) { nil }
943
- CArray.each_index(*tdim) do |*tidx|
944
- idx[at,trank] = tidx
945
- obj[*idx] = list.shift
946
- end
947
- obj
948
- end
949
-
950
- def self.merge (data_type, list, at = -1)
951
- return CArray.composite(data_type, [list.size], list, at)
952
- end
953
-
954
- def self.join (*argv)
955
- # get options
956
- case argv.first
957
- when Integer, Symbol, String
958
- type, = *CArray.guess_type_and_bytes(argv.shift, 0)
959
- else
960
- type = argv.flatten.first.data_type
961
- end
962
- # process
963
- conc = argv.map do |list|
964
- case list
965
- when CArray
966
- if list.rank == 1
967
- list[:%,1]
968
- else
969
- list
970
- end
971
- when Array
972
- x0 = list.first
973
- if list.size == 1 and
974
- x0.is_a?(CArray) and
975
- x0.rank == 1
976
- list = [x0[:%,1]]
977
- else
978
- list = list.map { |x|
979
- case x
980
- when CArray
981
- if x.rank == 1
982
- x[:%,1]
983
- else
984
- x
985
- end
986
- when Array
987
- y = x.first
988
- if x.size == 1 and
989
- y.is_a?(CArray) and
990
- y.rank == 1
991
- y[1,:%]
992
- else
993
- CArray.join(*x)
994
- end
995
- else
996
- x
997
- end
998
- }
999
- end
1000
- if block_given?
1001
- CArray.bind(type, list, 1, &block)
1002
- else
1003
- CArray.bind(type, list, 1)
1004
- end
1005
- else
1006
- list
1007
- end
1008
- end
1009
- if conc.size > 1
1010
- return CArray.bind(type, conc)
1011
- else
1012
- return conc.first
1013
- end
1014
- end
1015
-
1016
- # Returns object carray has elements of splitted carray at dimensions
1017
- # which is given by arguments
1018
- #
1019
- # a = CA_INT([[1,2,3], [4,5,6], [7,8,9]])
1020
- #
1021
- # a.split(0)
1022
- # [1,2,3], [4,5,6], [7,8,9]
1023
- #
1024
- # a.split(1)
1025
- # [1,4,7], [2,5,8], [3,6,9]
1026
- #
1027
-
1028
- def split (*argv)
1029
- odim = dim.values_at(*argv)
1030
- out = CArray.object(*odim)
1031
- idx = [nil] * rank
1032
- attach {
1033
- out.map_with_index! do |o, v|
1034
- argv.each_with_index do |r, i|
1035
- idx[r] = v[i]
1036
- end
1037
- self[*idx].to_ca
1038
- end
1039
- }
1040
- return out
1041
- end
1042
-
1043
- end
1044
-
1045
- class CAUnboundRepeat
1046
-
1047
- def template (*argv, &block)
1048
- return parent.template(*argv,&block)[*spec.map{|x| x != :* ? nil : x}]
1049
- end
1050
-
1051
- end
1052
-
1053
- class Numeric
1054
-
1055
- def eq (other)
1056
- case other
1057
- when CArray
1058
- return other.eq(self)
1059
- else
1060
- return send(:eq, *other.coerce(self))
1061
- end
1062
- end
1063
-
1064
- def ne (other)
1065
- case other
1066
- when CArray
1067
- return other.ne(self)
1068
- else
1069
- return send(:ne, *other.coerce(self))
1070
- end
1071
- end
1072
-
1073
- end
1074
-
1075
- module CA
1076
-
1077
- def self.meshgrid (*args)
1078
- dim = args.map(&:size)
1079
- out = []
1080
- args.each_with_index do |arg, i|
1081
- newdim = dim.dup
1082
- newdim[i] = :%
1083
- out[i] = arg[*newdim].to_ca
1084
- end
1085
- return *out
1086
- end
1087
-
1088
- end
1089
-
1090
-