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,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
@@ -13,7 +13,11 @@
13
13
  def autoload_method (method, library)
14
14
  eval %{
15
15
  def #{method} (*argv, &block)
16
- require "#{library}"
16
+ begin
17
+ require "#{library}"
18
+ rescue LoadError
19
+ raise "error in autoloading '#{library}' hooked by method '#{method}', check gem installation."
20
+ end
17
21
  #{method}(*argv, &block)
18
22
  end
19
23
  }
@@ -23,7 +27,11 @@ class Class
23
27
  def autoload_method (method, library)
24
28
  class_eval %{
25
29
  def #{method} (*argv, &block)
26
- require "#{library}"
30
+ begin
31
+ require "#{library}"
32
+ rescue LoadError
33
+ raise "error in autoloading '#{library}' hooked by method '#{method}', check gem installation."
34
+ end
27
35
  #{method}(*argv, &block)
28
36
  end
29
37
  }
@@ -34,7 +42,11 @@ class Module
34
42
  def autoload_method (method, library)
35
43
  class_eval %{
36
44
  def #{method} (*argv, &block)
37
- require "#{library}"
45
+ begin
46
+ require "#{library}"
47
+ rescue LoadError
48
+ raise "error in autoloading '#{library}' hooked by method '#{method}', check gem installation."
49
+ end
38
50
  #{method}(*argv, &block)
39
51
  end
40
52
  }
@@ -46,7 +58,11 @@ class Module
46
58
  class_eval %{
47
59
  module_function
48
60
  def #{method} (*argv, &block)
49
- require "#{library}"
61
+ begin
62
+ require "#{library}"
63
+ rescue LoadError
64
+ raise "error in autoloading '#{library}' hooked by method '#{method}', check gem installation."
65
+ end
50
66
  #{method}(*argv, &block)
51
67
  end
52
68
  }
@@ -87,6 +103,33 @@ module CA
87
103
 
88
104
  end
89
105
 
106
+ __END__
107
+ names = {"carray" => true}
108
+ Gem.path.each do |path|
109
+ gems = File.join(path, "gems")
110
+ if File.directory?(gems)
111
+ Dir.chdir(gems) {
112
+ Dir["carray-*"].sort.reverse.each do |dir|
113
+ name = dir.sub(/\-\d+\.\d+\.\d+\z/, '')
114
+ next if names[name]
115
+ lib = File.join(dir, "lib")
116
+ if File.directory?(lib)
117
+ Dir.chdir(lib) {
118
+ Dir["carray/autoload/autoload_*"].each do |loader|
119
+ begin
120
+ load File.expand_path(File.join(gems, dir, lib, loader.sub(/\.rb\z/, "")))
121
+ rescue LoadError
122
+ end
123
+ end
124
+ }
125
+ end
126
+ names[name] = true
127
+ end
128
+ }
129
+ end
130
+ end
131
+
132
+ __END__
90
133
  CA.each_load_path("carray/autoload") {
91
134
  Dir["autoload_*.rb"].each do |basename|
92
135
  if basename =~ /\A(autoload_.+)\.rb\Z/
@@ -98,4 +141,3 @@ CA.each_load_path("carray/autoload") {
98
141
  end
99
142
  }
100
143
 
101
- undef autoload_method
@@ -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
@@ -17,7 +17,3 @@ end
17
17
  class Rational < Numeric
18
18
  include FloatFunction
19
19
  end
20
-
21
- module CA
22
- autoload :NumPy, "carray/base/numpysh.rb"
23
- end
@@ -0,0 +1,9 @@
1
+
2
+ module Cairo
3
+ class Surface
4
+ end
5
+ class ImageSurface < Surface
6
+ autoload_method "self.new_from_ca", "carray-cairo"
7
+ autoload_method "ca", "carray-cairo"
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ class CArray
2
+ autoload_method "mp", "carray-ffi"
3
+ end
4
+
5
+ module FFI
6
+ class MemoryPointer
7
+ autoload_method "ca", "carray-ffi"
8
+ end
9
+ end
@@ -0,0 +1,2 @@
1
+ autoload_method "CA.gnuplot", "carray-gnuplot"
2
+
@@ -0,0 +1,14 @@
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
+
@@ -0,0 +1,6 @@
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
@@ -0,0 +1,12 @@
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
@@ -0,0 +1,10 @@
1
+ class CArray
2
+ autoload_method :na, "carray-narray"
3
+ autoload_method :to_na, "carray-narray"
4
+ end
5
+
6
+ class NArray
7
+ autoload_method :ca, "carray-narray"
8
+ autoload_method :to_ca, "carray-narray"
9
+ end
10
+
@@ -0,0 +1,15 @@
1
+ class CArray
2
+ autoload_method :to_numo, "carray-numo-narray"
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"
8
+ end
9
+
10
+ module Numo
11
+ class NArray
12
+ autoload_method :to_ca, "carray-numo-narray"
13
+ autoload_method :ca, "carray-numo-narray"
14
+ end
15
+ end
@@ -0,0 +1,16 @@
1
+ module OpenCV
2
+ class CvMat
3
+ autoload_method "ca", "carray-opencv"
4
+ autoload_method "to_ca", "carray-opencv"
5
+ autoload_method "from_ca", "carray-opencv"
6
+ autoload_method "image", "carray-opencv"
7
+ end
8
+ class IplImage < CvMat
9
+ autoload_method "ca", "carray-opencv"
10
+ end
11
+ end
12
+
13
+ class CArray
14
+ autoload_method "to_cvmat", "carray-opencv"
15
+ autoload_method "to_iplimage", "carray-opencv"
16
+ end
@@ -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,23 @@
1
+ module Magick
2
+ class Image
3
+ autoload_method "export_pixels_to_ca", "carray-rmagick"
4
+ autoload_method "import_pixels_from_ca", "carray-rmagick"
5
+ end
6
+ end
7
+
8
+ class CArray
9
+ autoload_method "self.load_image", "carray-rmagick"
10
+ autoload_method "save_image", "carray-rmagick"
11
+ autoload_method "display_image", "carray-rmagick"
12
+ autoload_method "to_image", "carray-rmagick"
13
+ end
14
+
15
+ autoload :CAMagickImage, "carray-rmagick"
16
+
17
+ module Magick
18
+ class Image
19
+ autoload_method "ca", "carray-rmagick"
20
+ autoload_method "to_ca", "carray-rmagick"
21
+ end
22
+ end
23
+
@@ -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
+