carray 1.3.5 → 1.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSES +22 -0
- data/README.md +18 -21
- data/Rakefile +31 -0
- data/carray.gemspec +13 -26
- data/{ca_iter_block.c → ext/ca_iter_block.c} +13 -13
- data/{ca_iter_dimension.c → ext/ca_iter_dimension.c} +16 -16
- data/{ca_iter_window.c → ext/ca_iter_window.c} +10 -10
- data/{ca_obj_array.c → ext/ca_obj_array.c} +60 -55
- data/{ca_obj_bitarray.c → ext/ca_obj_bitarray.c} +12 -12
- data/{ca_obj_bitfield.c → ext/ca_obj_bitfield.c} +7 -7
- data/{ca_obj_block.c → ext/ca_obj_block.c} +42 -42
- data/{ca_obj_fake.c → ext/ca_obj_fake.c} +7 -7
- data/{ca_obj_farray.c → ext/ca_obj_farray.c} +18 -18
- data/{ca_obj_field.c → ext/ca_obj_field.c} +15 -15
- data/{ca_obj_grid.c → ext/ca_obj_grid.c} +27 -27
- data/{ca_obj_mapping.c → ext/ca_obj_mapping.c} +9 -9
- data/{ca_obj_object.c → ext/ca_obj_object.c} +37 -37
- data/{ca_obj_reduce.c → ext/ca_obj_reduce.c} +1 -1
- data/{ca_obj_refer.c → ext/ca_obj_refer.c} +33 -33
- data/{ca_obj_repeat.c → ext/ca_obj_repeat.c} +43 -43
- data/{ca_obj_select.c → ext/ca_obj_select.c} +2 -2
- data/{ca_obj_shift.c → ext/ca_obj_shift.c} +23 -23
- data/{ca_obj_transpose.c → ext/ca_obj_transpose.c} +23 -23
- data/{ca_obj_unbound_repeat.c → ext/ca_obj_unbound_repeat.c} +55 -55
- data/{ca_obj_window.c → ext/ca_obj_window.c} +26 -26
- data/{carray.h → ext/carray.h} +77 -51
- data/{carray_access.c → ext/carray_access.c} +133 -91
- data/{carray_attribute.c → ext/carray_attribute.c} +12 -12
- data/{carray_call_cfunc.c → ext/carray_call_cfunc.c} +0 -0
- data/{carray_cast.c → ext/carray_cast.c} +6 -6
- data/{carray_cast_func.rb → ext/carray_cast_func.rb} +0 -0
- data/{carray_class.c → ext/carray_class.c} +0 -0
- data/{carray_conversion.c → ext/carray_conversion.c} +11 -13
- data/{carray_copy.c → ext/carray_copy.c} +19 -19
- data/{carray_core.c → ext/carray_core.c} +2 -2
- data/ext/carray_data_type.c +66 -0
- data/{carray_element.c → ext/carray_element.c} +9 -9
- data/{carray_generate.c → ext/carray_generate.c} +67 -1
- data/{carray_iterator.c → ext/carray_iterator.c} +40 -38
- data/{carray_loop.c → ext/carray_loop.c} +24 -24
- data/{carray_mask.c → ext/carray_mask.c} +17 -6
- data/{carray_math.rb → ext/carray_math.rb} +25 -25
- data/ext/{mathfunc/carray_mathfunc.c → carray_mathfunc.c} +0 -0
- data/{carray_numeric.c → ext/carray_numeric.c} +1 -1
- data/{carray_operator.c → ext/carray_operator.c} +32 -9
- data/{carray_order.c → ext/carray_order.c} +2 -153
- data/{carray_sort_addr.c → ext/carray_sort_addr.c} +0 -0
- data/{carray_stat.c → ext/carray_stat.c} +5 -5
- data/{carray_stat_proc.rb → ext/carray_stat_proc.rb} +23 -23
- data/{carray_test.c → ext/carray_test.c} +22 -21
- data/{carray_undef.c → ext/carray_undef.c} +0 -0
- data/{carray_utils.c → ext/carray_utils.c} +0 -0
- data/{extconf.rb → ext/extconf.rb} +0 -5
- data/{mkmath.rb → ext/mkmath.rb} +12 -2
- data/{ruby_carray.c → ext/ruby_carray.c} +9 -2
- data/{ruby_ccomplex.c → ext/ruby_ccomplex.c} +0 -0
- data/{ruby_float_func.c → ext/ruby_float_func.c} +0 -0
- data/{version.h → ext/version.h} +5 -5
- data/{version.rb → ext/version.rb} +0 -0
- data/lib/carray.rb +49 -7
- data/lib/carray/{base/autoload.rb → autoload.rb} +48 -6
- data/lib/carray/autoload/autoload_base.rb +1 -5
- data/lib/carray/autoload/autoload_gem_cairo.rb +9 -0
- data/lib/carray/autoload/autoload_gem_ffi.rb +9 -0
- data/lib/carray/autoload/autoload_gem_gnuplot.rb +2 -0
- data/lib/carray/autoload/autoload_gem_io_csv.rb +14 -0
- data/lib/carray/autoload/autoload_gem_io_pg.rb +6 -0
- data/lib/carray/autoload/autoload_gem_io_sqlite3.rb +12 -0
- data/lib/carray/autoload/autoload_gem_narray.rb +10 -0
- data/lib/carray/autoload/autoload_gem_numo_narray.rb +15 -0
- data/lib/carray/autoload/autoload_gem_opencv.rb +16 -0
- data/lib/carray/autoload/autoload_gem_random.rb +8 -0
- data/lib/carray/autoload/autoload_gem_rmagick.rb +23 -0
- data/lib/carray/autoload/{autoload_graphics_zimg.rb → autoload_gem_zimg.rb} +0 -0
- data/lib/carray/basic.rb +193 -0
- data/lib/carray/compose.rb +291 -0
- data/lib/carray/construct.rb +445 -0
- data/lib/carray/convert.rb +115 -0
- data/lib/carray/{base/inspect.rb → inspect.rb} +6 -6
- data/lib/carray/io/imagemagick.rb +1 -1
- data/lib/carray/{base/iterator.rb → iterator.rb} +3 -3
- data/lib/carray/mask.rb +91 -0
- data/lib/carray/{base/math.rb → math.rb} +17 -47
- data/lib/carray/math/histogram.rb +7 -7
- data/lib/carray/mkmf.rb +8 -0
- data/lib/carray/object/ca_obj_pack.rb +8 -8
- data/lib/carray/obsolete.rb +272 -0
- data/lib/carray/ordering.rb +157 -0
- data/lib/carray/{base/serialize.rb → serialize.rb} +28 -53
- data/lib/carray/string.rb +190 -0
- data/lib/carray/{base/struct.rb → struct.rb} +20 -20
- data/lib/carray/{io/table.rb → table.rb} +1 -9
- data/lib/carray/testing.rb +56 -0
- data/lib/carray/time.rb +78 -0
- data/lib/carray/transform.rb +100 -0
- data/misc/Methods.ja.md +182 -0
- data/{NOTE → misc/NOTE} +0 -0
- data/test/test_ALL.rb +0 -2
- data/test/test_order.rb +7 -7
- data/test/test_ref_store.rb +13 -13
- data/test/test_stat.rb +7 -15
- data/{devel → utils}/guess_shape.rb +0 -0
- data/utils/{diff_method.rb → monkey_patch_methods.rb} +17 -7
- metadata +100 -254
- data/COPYING +0 -56
- data/GPL +0 -340
- data/Gemfile +0 -8
- data/Gemfile.lock +0 -33
- data/LEGAL +0 -50
- data/TODO +0 -5
- data/carray_random.c +0 -531
- data/ext/calculus/carray_calculus.c +0 -931
- data/ext/calculus/carray_interp.c +0 -358
- data/ext/calculus/extconf.rb +0 -12
- data/ext/calculus/lib/autoload/autoload_math_calculus.rb +0 -2
- data/ext/calculus/lib/math/calculus.rb +0 -119
- data/ext/calculus/lib/math/interp/adapter_interp1d.rb +0 -31
- data/ext/fortio/extconf.rb +0 -3
- data/ext/fortio/lib/carray/autoload/autoload_fortran_format.rb +0 -5
- data/ext/fortio/lib/carray/io/fortran_format.rb +0 -43
- data/ext/fortio/lib/fortio.rb +0 -3
- data/ext/fortio/lib/fortio/fortran_format.rb +0 -605
- data/ext/fortio/lib/fortio/fortran_format.tab.rb +0 -536
- data/ext/fortio/lib/fortio/fortran_format.y +0 -215
- data/ext/fortio/lib/fortio/fortran_namelist.rb +0 -151
- data/ext/fortio/lib/fortio/fortran_namelist.tab.rb +0 -470
- data/ext/fortio/lib/fortio/fortran_namelist.y +0 -213
- data/ext/fortio/lib/fortio/fortran_sequential.rb +0 -345
- data/ext/fortio/ruby_fortio.c +0 -182
- data/ext/fortio/test/test_H.rb +0 -5
- data/ext/fortio/test/test_T.rb +0 -7
- data/ext/fortio/test/test_fortran_format.rb +0 -86
- data/ext/fortio/test/test_namelist.rb +0 -25
- data/ext/fortio/test/test_namelist_write.rb +0 -10
- data/ext/fortio/test/test_sequential.rb +0 -13
- data/ext/fortio/test/test_sequential2.rb +0 -13
- data/ext/fortio/work/test.rb +0 -10
- data/ext/fortio/work/test_e.rb +0 -19
- data/ext/fortio/work/test_ep.rb +0 -10
- data/ext/fortio/work/test_parse.rb +0 -12
- data/ext/imagemap/carray_imagemap.c +0 -495
- data/ext/imagemap/doc/call_graph.dot +0 -28
- data/ext/imagemap/draw.c +0 -567
- data/ext/imagemap/extconf.rb +0 -13
- data/ext/imagemap/lib/autoload/autoload_graphics_imagemap.rb +0 -1
- data/ext/imagemap/lib/graphics/imagemap.rb +0 -273
- data/ext/imagemap/lib/image_map.rb +0 -4
- data/ext/imagemap/test/swath_index.rb +0 -83
- data/ext/imagemap/test/swath_warp.rb +0 -99
- data/ext/imagemap/test/test.rb +0 -23
- data/ext/imagemap/test/test_image.rb +0 -42
- data/ext/imagemap/test/test_line.rb +0 -14
- data/ext/imagemap/test/test_rotate.rb +0 -17
- data/ext/imagemap/test/test_triangle.rb +0 -20
- data/ext/imagemap/test/test_warp.rb +0 -26
- data/ext/mathfunc/extconf.rb +0 -18
- data/ext/mathfunc/lib/autoload/autoload_math_mathfunc.rb +0 -1
- data/ext/mathfunc/lib/math/mathfunc.rb +0 -15
- data/ext/mathfunc/test/test_hypot.rb +0 -5
- data/ext/mathfunc/test/test_j0.rb +0 -22
- data/ext/mathfunc/test/test_jn.rb +0 -8
- data/ext/mathfunc/test/test_sph.rb +0 -9
- data/ext/narray/README +0 -22
- data/ext/narray/ca_wrap_narray.c +0 -500
- data/ext/narray/carray_narray.c +0 -21
- data/ext/narray/extconf.rb +0 -57
- data/ext/narray/lib/autoload/autoload_math_narray.rb +0 -1
- data/ext/narray/lib/autoload/autoload_math_narray_miss.rb +0 -11
- data/ext/narray/lib/math/narray.rb +0 -17
- data/ext/narray/lib/math/narray_miss.rb +0 -45
- data/lib/carray/autoload/autoload_graphics_gnuplot.rb +0 -2
- data/lib/carray/autoload/autoload_io_csv.rb +0 -14
- data/lib/carray/autoload/autoload_io_pg.rb +0 -6
- data/lib/carray/autoload/autoload_io_sqlite3.rb +0 -12
- data/lib/carray/autoload/autoload_io_table.rb +0 -1
- data/lib/carray/autoload/autoload_math_interp.rb +0 -4
- data/lib/carray/base/basic.rb +0 -1090
- data/lib/carray/base/obsolete.rb +0 -131
- data/lib/carray/graphics/gnuplot.rb +0 -2131
- data/lib/carray/graphics/zimg.rb +0 -296
- data/lib/carray/io/csv.rb +0 -572
- data/lib/carray/io/pg.rb +0 -101
- data/lib/carray/io/sqlite3.rb +0 -215
- data/lib/carray/math/interp.rb +0 -57
- data/lib/carray/math/interp/adapter_gsl_spline.rb +0 -47
- data/mt19937ar.c +0 -182
- data/mt19937ar.h +0 -86
- data/rdoc_main.rb +0 -27
- data/rdoc_math.rb +0 -5
- data/rdoc_stat.rb +0 -31
- data/test/test_narray.rb +0 -64
- data/test/test_random.rb +0 -15
- data/utils/create_rdoc.sh +0 -9
- data/utils/make_tgz.sh +0 -3
@@ -1,6 +1,6 @@
|
|
1
1
|
# ----------------------------------------------------------------------------
|
2
2
|
#
|
3
|
-
# carray/
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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/
|
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,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,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,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,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
|
+
|
File without changes
|
data/lib/carray/basic.rb
ADDED
@@ -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
|
+
|