carray 1.4.0 → 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 -14
- data/Rakefile +1 -1
- data/carray.gemspec +5 -13
- 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} +73 -51
- data/{carray_access.c → ext/carray_access.c} +83 -83
- 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} +8 -10
- 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} +0 -0
- 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} +3 -3
- 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} +9 -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} +0 -0
- 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 +48 -37
- data/lib/carray/{base/autoload.rb → autoload.rb} +1 -1
- data/lib/carray/autoload/autoload_base.rb +1 -1
- data/lib/carray/autoload/autoload_gem_numo_narray.rb +4 -3
- data/lib/carray/autoload/autoload_gem_random.rb +8 -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} +16 -46
- 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/{base/string.rb → string.rb} +12 -64
- data/lib/carray/{base/struct.rb → struct.rb} +16 -16
- data/lib/carray/{io/table.rb → table.rb} +1 -10
- 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 +88 -151
- data/COPYING +0 -56
- data/GPL +0 -340
- data/LEGAL +0 -50
- data/TODO +0 -5
- data/carray_random.c +0 -531
- data/devel/im2col.rb +0 -17
- 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/math/calculus.rb +0 -119
- data/ext/calculus/lib/math/interp/adapter_interp1d.rb +0 -31
- data/ext/mathfunc/extconf.rb +0 -18
- 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/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 -1146
- data/lib/carray/base/obsolete.rb +0 -131
- 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/inspect.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
|
@@ -17,14 +17,14 @@ class CArray::Inspector # :nodoc:
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def inspect_string
|
20
|
-
if @carray.
|
21
|
-
raise "can't inspect CArray of
|
20
|
+
if @carray.ndim == 0
|
21
|
+
raise "can't inspect CArray of ndim == 0"
|
22
22
|
end
|
23
23
|
formatter = get_formatter()
|
24
24
|
class_name = get_class_name()
|
25
25
|
type_name = get_type_name()
|
26
26
|
shape = get_shape()
|
27
|
-
data_spec = get_data_spec(0, Array.new(@carray.
|
27
|
+
data_spec = get_data_spec(0, Array.new(@carray.ndim){0}, formatter)
|
28
28
|
info_list = get_info_list()
|
29
29
|
output = ["<",
|
30
30
|
format("%s.%s(%s)", class_name, type_name, shape.join(",")),
|
@@ -152,9 +152,9 @@ class CArray::Inspector # :nodoc:
|
|
152
152
|
|
153
153
|
def get_data_spec (level, idx, formatter)
|
154
154
|
io = "[ "
|
155
|
-
|
155
|
+
ndim = @carray.ndim
|
156
156
|
dim = @carray.dim
|
157
|
-
if level ==
|
157
|
+
if level == ndim - 1
|
158
158
|
over = false
|
159
159
|
dim[level].times do |i|
|
160
160
|
idx[level] = i
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# ----------------------------------------------------------------------------
|
2
2
|
#
|
3
|
-
# carray/
|
3
|
+
# carray/iterator.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
|
@@ -318,7 +318,7 @@ class CAClassIterator < CAIterator # :nodoc:
|
|
318
318
|
@classifier = classifier || @reference.uniq.sort
|
319
319
|
@null = CArray.new(@reference.data_type,[0])
|
320
320
|
@table = {}
|
321
|
-
@
|
321
|
+
@ndim = 1
|
322
322
|
@dim = [0]
|
323
323
|
if @classifier.all_masked? or @classifier.size == 0
|
324
324
|
@dim = [0]
|
@@ -343,7 +343,7 @@ class CAClassIterator < CAIterator # :nodoc:
|
|
343
343
|
return self
|
344
344
|
end
|
345
345
|
|
346
|
-
def
|
346
|
+
def ndiming (&block)
|
347
347
|
block ||= lambda {|a| a.size }
|
348
348
|
values = self.to_a.map{|v| block[v] }.to_ca
|
349
349
|
addrs = values.sort_addr.reverse
|
data/lib/carray/mask.rb
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
# ----------------------------------------------------------------------------
|
2
|
+
#
|
3
|
+
# carray/mask.rb
|
4
|
+
#
|
5
|
+
# This file is part of Ruby/CArray extension library.
|
6
|
+
# You can redistribute it and/or modify it under the terms of
|
7
|
+
# the Ruby Licence.
|
8
|
+
#
|
9
|
+
# Copyright (C) 2005 Hiroki Motoyoshi
|
10
|
+
#
|
11
|
+
# ----------------------------------------------------------------------------
|
12
|
+
|
13
|
+
class CArray
|
14
|
+
|
15
|
+
# mask
|
16
|
+
|
17
|
+
#
|
18
|
+
# Returns the number of masked elements.
|
19
|
+
#
|
20
|
+
|
21
|
+
def count_masked (*axis)
|
22
|
+
if has_mask?
|
23
|
+
return mask.int64.accumulate(*axis)
|
24
|
+
else
|
25
|
+
if axis.empty?
|
26
|
+
return 0
|
27
|
+
else
|
28
|
+
spec = shape.map{:i}
|
29
|
+
axis.each do |k|
|
30
|
+
spec[k] = nil
|
31
|
+
end
|
32
|
+
return self[*spec].ca.template(:int64) { 0 }
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
#
|
38
|
+
# Returns the number of not-masked elements.
|
39
|
+
#
|
40
|
+
def count_not_masked (*axis)
|
41
|
+
if has_mask?
|
42
|
+
return mask.not.int64.accumulate(*axis)
|
43
|
+
else
|
44
|
+
if axis.empty?
|
45
|
+
return elements
|
46
|
+
else
|
47
|
+
spec = shape.map {:i}
|
48
|
+
axis.each do |k|
|
49
|
+
spec[k] = nil
|
50
|
+
end
|
51
|
+
it = self[*spec].ca
|
52
|
+
count = self.elements/it.elements
|
53
|
+
return it.template(:int64) { count }
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def maskout! (*argv)
|
59
|
+
case argv.size
|
60
|
+
when 1
|
61
|
+
val = argv.first
|
62
|
+
case val
|
63
|
+
when CArray, Symbol
|
64
|
+
self[val] = UNDEF
|
65
|
+
else
|
66
|
+
self[:eq, val] = UNDEF
|
67
|
+
end
|
68
|
+
else
|
69
|
+
self[*argv] = UNDEF
|
70
|
+
end
|
71
|
+
return self
|
72
|
+
end
|
73
|
+
|
74
|
+
def maskout (*argv)
|
75
|
+
obj = self.to_ca
|
76
|
+
case argv.size
|
77
|
+
when 1
|
78
|
+
val = argv.first
|
79
|
+
case val
|
80
|
+
when CArray, Symbol
|
81
|
+
obj[val] = UNDEF
|
82
|
+
else
|
83
|
+
obj[:eq, val] = UNDEF
|
84
|
+
end
|
85
|
+
else
|
86
|
+
obj[*argv] = UNDEF
|
87
|
+
end
|
88
|
+
return obj
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# ----------------------------------------------------------------------------
|
2
2
|
#
|
3
|
-
# carray/
|
3
|
+
# carray/math.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
|
@@ -226,7 +226,7 @@ class CArray
|
|
226
226
|
|
227
227
|
def anomaly (*argv)
|
228
228
|
opt = argv.last.is_a?(Hash) ? argv.pop : {}
|
229
|
-
idxs = Array.new(self.
|
229
|
+
idxs = Array.new(self.ndim) { |i| argv.include?(i) ? :* : nil }
|
230
230
|
if mn = opt[:mean]
|
231
231
|
return self - mn[*idxs]
|
232
232
|
else
|
@@ -260,7 +260,7 @@ class CArray
|
|
260
260
|
return (c[(n-1)/2] + c[n/2])/2.0
|
261
261
|
end
|
262
262
|
else
|
263
|
-
raise "CArray#median is not implemented for multiple
|
263
|
+
raise "CArray#median is not implemented for multiple ndims"
|
264
264
|
end
|
265
265
|
|
266
266
|
end
|
@@ -285,27 +285,23 @@ class CArray
|
|
285
285
|
end
|
286
286
|
out = []
|
287
287
|
begin
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
288
|
+
pers.each do |per|
|
289
|
+
if per == 100
|
290
|
+
out << ca[n-1]
|
291
|
+
elsif per >= 0 and per < 100
|
292
|
+
if n > 1
|
293
|
+
f = (n-1)*per/100.0
|
294
|
+
k = f.floor
|
295
|
+
r = f - k
|
296
|
+
out << (1-r)*ca[k] + r*ca[k+1]
|
297
|
+
else
|
298
|
+
out << ca[0]
|
299
|
+
end
|
297
300
|
else
|
298
|
-
out <<
|
301
|
+
out << CA_NAN
|
299
302
|
end
|
300
|
-
else
|
301
|
-
out << CA_NAN
|
302
303
|
end
|
303
304
|
end
|
304
|
-
rescue
|
305
|
-
p self[:is_not_masked]
|
306
|
-
p n
|
307
|
-
raise
|
308
|
-
end
|
309
305
|
return out
|
310
306
|
end
|
311
307
|
|
@@ -373,31 +369,5 @@ class CArray
|
|
373
369
|
|
374
370
|
end
|
375
371
|
|
376
|
-
class CArray
|
377
|
-
|
378
|
-
def self.summation (*dim)
|
379
|
-
out = nil
|
380
|
-
first = true
|
381
|
-
CArray.each_index(*dim) { |*idx|
|
382
|
-
if first
|
383
|
-
out = yield(*idx)
|
384
|
-
first = false
|
385
|
-
else
|
386
|
-
out += yield(*idx)
|
387
|
-
end
|
388
|
-
}
|
389
|
-
return out
|
390
|
-
end
|
391
|
-
|
392
|
-
def by (other)
|
393
|
-
case other
|
394
|
-
when CArray
|
395
|
-
return (self[nil][nil,:*]*other[nil][:*,nil]).reshape(*(dim+other.dim))
|
396
|
-
else
|
397
|
-
return self * other
|
398
|
-
end
|
399
|
-
end
|
400
|
-
|
401
|
-
end
|
402
372
|
|
403
373
|
|
@@ -49,7 +49,7 @@ class CAHistogram < CArray
|
|
49
49
|
raise "scales should be an array of scales"
|
50
50
|
end
|
51
51
|
|
52
|
-
|
52
|
+
ndim = scales.size
|
53
53
|
@scales = scales.clone
|
54
54
|
@scales.map! { |s| CArray.wrap_readonly(s, CA_DOUBLE) }
|
55
55
|
|
@@ -60,10 +60,10 @@ class CAHistogram < CArray
|
|
60
60
|
raise "invalid length of offset in option"
|
61
61
|
end
|
62
62
|
else
|
63
|
-
@offsets = Array.new(
|
63
|
+
@offsets = Array.new(ndim) { 0 }
|
64
64
|
end
|
65
65
|
|
66
|
-
dim = Array.new(
|
66
|
+
dim = Array.new(ndim) { |i|
|
67
67
|
case @offsets[i]
|
68
68
|
when 0
|
69
69
|
@scales[i].size
|
@@ -76,12 +76,12 @@ class CAHistogram < CArray
|
|
76
76
|
|
77
77
|
super(data_type, dim, &block)
|
78
78
|
|
79
|
-
@mid_points = Array.new(
|
79
|
+
@mid_points = Array.new(ndim) { |i|
|
80
80
|
x = (@scales[i] + @scales[i].shifted(-1))/2
|
81
81
|
x[0..-2].to_ca
|
82
82
|
}
|
83
83
|
|
84
|
-
@inner = self[*Array.new(
|
84
|
+
@inner = self[*Array.new(ndim) { |i| @offsets[i]..-2 }]
|
85
85
|
|
86
86
|
end
|
87
87
|
|
@@ -91,7 +91,7 @@ class CAHistogram < CArray
|
|
91
91
|
alias midpoints mid_points
|
92
92
|
|
93
93
|
def increment (*values)
|
94
|
-
idx = Array.new(
|
94
|
+
idx = Array.new(ndim) {|i|
|
95
95
|
vi = CArray.wrap_readonly(values[i], CA_DOUBLE)
|
96
96
|
@scales[i].bin(vi, @include_upper, @include_lowest, @offsets[i]).to_ca
|
97
97
|
}
|
@@ -103,7 +103,7 @@ class CAHistogram < CArray
|
|
103
103
|
val = CArray.wrap_readonly(values.pop, self.data_type)
|
104
104
|
sel = val.ne(0)
|
105
105
|
val = val[sel].to_ca
|
106
|
-
idx = Array.new(
|
106
|
+
idx = Array.new(ndim) {|i|
|
107
107
|
vi = CArray.wrap_readonly(values[i], CA_DOUBLE)[sel]
|
108
108
|
@scales[i].bin(vi, @include_upper, @include_lowest, @offsets[i]).to_ca
|
109
109
|
}
|
data/lib/carray/mkmf.rb
CHANGED
@@ -18,6 +18,13 @@ def have_carray
|
|
18
18
|
rescue LoadError
|
19
19
|
abort "Ruby/CArray is not installed"
|
20
20
|
end
|
21
|
+
$LOAD_PATH.each do |path|
|
22
|
+
if File.exist? File.join(path, 'carray.h')
|
23
|
+
dir_config("carray", path, path)
|
24
|
+
break
|
25
|
+
end
|
26
|
+
end
|
27
|
+
=begin
|
21
28
|
dir_config("carray", $sitearchdir, $sitearchdir)
|
22
29
|
if defined? Gem
|
23
30
|
if Gem::VERSION >= "1.7.0"
|
@@ -34,6 +41,7 @@ def have_carray
|
|
34
41
|
end
|
35
42
|
end
|
36
43
|
end
|
44
|
+
=end
|
37
45
|
status = true
|
38
46
|
status &= have_header("carray.h")
|
39
47
|
if /cygwin|mingw/ =~ RUBY_PLATFORM
|
@@ -22,9 +22,9 @@ class CAPack < CAObject # :nodoc:
|
|
22
22
|
|
23
23
|
def initialize (list, options={})
|
24
24
|
@list = list
|
25
|
-
@
|
26
|
-
unless @
|
27
|
-
@
|
25
|
+
@ndim = options[:ndim]
|
26
|
+
unless @ndim
|
27
|
+
@ndim = list.map{|m| m.ndim}.min
|
28
28
|
end
|
29
29
|
@names = options[:names] || [nil]*@list.size
|
30
30
|
@dim = guess_dim(list)
|
@@ -55,10 +55,10 @@ class CAPack < CAObject # :nodoc:
|
|
55
55
|
list.each do |mem|
|
56
56
|
case mem
|
57
57
|
when CArray
|
58
|
-
if mem.
|
59
|
-
raise "mem.
|
58
|
+
if mem.ndim < @ndim
|
59
|
+
raise "mem.ndim < @ndim"
|
60
60
|
else
|
61
|
-
newdim = mem.dim[0, @
|
61
|
+
newdim = mem.dim[0, @ndim]
|
62
62
|
end
|
63
63
|
if dim
|
64
64
|
unless dim == newdim
|
@@ -78,10 +78,10 @@ class CAPack < CAObject # :nodoc:
|
|
78
78
|
name = @names[i]
|
79
79
|
case mem
|
80
80
|
when CArray
|
81
|
-
if mem.
|
81
|
+
if mem.ndim == @ndim
|
82
82
|
s.member mem.data_type, name, :bytes=>mem.bytes ### anonymous member
|
83
83
|
else
|
84
|
-
dummy = Array.new(@
|
84
|
+
dummy = Array.new(@ndim){0} + [false]
|
85
85
|
s.member mem[*dummy].to_ca, name ### anonymous member
|
86
86
|
end
|
87
87
|
else
|
@@ -0,0 +1,272 @@
|
|
1
|
+
# ----------------------------------------------------------------------------
|
2
|
+
#
|
3
|
+
# carray/obsolete.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 CA
|
14
|
+
TableMethods = CArray::TableMethods
|
15
|
+
end
|
16
|
+
|
17
|
+
class CArray
|
18
|
+
|
19
|
+
### obsolete methods
|
20
|
+
|
21
|
+
def extend_as_table (column_names)
|
22
|
+
warn "CArray#extend_as_table will be obsolete"
|
23
|
+
self.extend CArray::TableMethods
|
24
|
+
self.column_names = column_names
|
25
|
+
self
|
26
|
+
end
|
27
|
+
|
28
|
+
# pulled
|
29
|
+
|
30
|
+
def pulled (*args)
|
31
|
+
warn "CArray#pulled will be obsolete"
|
32
|
+
idx = args.map{|s| s.nil? ? :% : s}
|
33
|
+
return self[*idx]
|
34
|
+
end
|
35
|
+
|
36
|
+
def pull (*args)
|
37
|
+
warn "CArray#pull will be obsolete"
|
38
|
+
idx = args.map{|s| s.nil? ? :% : s}
|
39
|
+
return self[*idx].to_ca
|
40
|
+
end
|
41
|
+
|
42
|
+
# Returns the array eliminated all the duplicated elements.
|
43
|
+
def duplicated_values
|
44
|
+
warn "CArray#duplicated_values will be obsolete"
|
45
|
+
if uniq.size == size
|
46
|
+
return []
|
47
|
+
else
|
48
|
+
hash = {}
|
49
|
+
list = []
|
50
|
+
each_with_addr do |v, addr|
|
51
|
+
if v == UNDEF
|
52
|
+
next
|
53
|
+
elsif hash[v]
|
54
|
+
list << [v, addr, hash[v]]
|
55
|
+
hash[v] += 1
|
56
|
+
else
|
57
|
+
hash[v] = 0
|
58
|
+
end
|
59
|
+
end
|
60
|
+
return list
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def self.summation (*dim)
|
65
|
+
warn "CArray.summation will be obsolete"
|
66
|
+
out = nil
|
67
|
+
first = true
|
68
|
+
CArray.each_index(*dim) { |*idx|
|
69
|
+
if first
|
70
|
+
out = yield(*idx)
|
71
|
+
first = false
|
72
|
+
else
|
73
|
+
out += yield(*idx)
|
74
|
+
end
|
75
|
+
}
|
76
|
+
return out
|
77
|
+
end
|
78
|
+
|
79
|
+
def by (other)
|
80
|
+
warn "CArray#by will be obsolete"
|
81
|
+
case other
|
82
|
+
when CArray
|
83
|
+
return (self[nil][nil,:*]*other[nil][:*,nil]).reshape(*(dim+other.dim))
|
84
|
+
else
|
85
|
+
return self * other
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def save_binary (filename, opt={}) # :nodoc:
|
90
|
+
warn "CArray#save_binary will be obsolete, use CArray.save"
|
91
|
+
open(filename, "w") { |io|
|
92
|
+
return Serializer.new(io).save(self, opt)
|
93
|
+
}
|
94
|
+
end
|
95
|
+
|
96
|
+
def self.load_binary (filename, opt={}) # :nodoc:
|
97
|
+
warn "CArray.load_binary will be obsolete, use CArray.load"
|
98
|
+
open(filename) { |io|
|
99
|
+
return Serializer.new(io).load(opt)
|
100
|
+
}
|
101
|
+
end
|
102
|
+
|
103
|
+
def save_binary_io (io, opt={}) # :nodoc:
|
104
|
+
warn "CArray#save_binary_io will be obsolete, use CArray.save"
|
105
|
+
return Serializer.new(io).save(self, opt)
|
106
|
+
end
|
107
|
+
|
108
|
+
def self.load_binary_io (io, opt={}) # :nodoc:
|
109
|
+
warn "CArray#load_binary_io will be obsolete, use CArray.load"
|
110
|
+
return Serializer.new(io).load(opt)
|
111
|
+
end
|
112
|
+
|
113
|
+
def to_binary (io="", opt={}) # :nodoc:
|
114
|
+
warn "CArray#to_binary will be obsolete, use CArray.dump"
|
115
|
+
Serializer.new(io).save(self, opt)
|
116
|
+
return io
|
117
|
+
end
|
118
|
+
|
119
|
+
def self.from_binary (io, opt={}) # :nodoc:
|
120
|
+
warn "CArray.from_binary will be obsolete, use CArray.load"
|
121
|
+
return Serializer.new(io).load(opt)
|
122
|
+
end
|
123
|
+
|
124
|
+
def replace_value (from, to)
|
125
|
+
warn "CArray#replace_value will be obsolete"
|
126
|
+
self[:eq, from] = to
|
127
|
+
return self
|
128
|
+
end
|
129
|
+
|
130
|
+
def asign (*idx)
|
131
|
+
warn "CArray#asign will be obsolete"
|
132
|
+
self[*idx] = yield
|
133
|
+
return self
|
134
|
+
end
|
135
|
+
|
136
|
+
def fa # :nodoc:
|
137
|
+
warn "CArray#fa will be obsolete, use CArray#t"
|
138
|
+
return self.t
|
139
|
+
end
|
140
|
+
|
141
|
+
def block_iterator (*argv) # :nodoc:
|
142
|
+
warn "CArray#block_iterator will be obsolete, use CArray#blocks"
|
143
|
+
return blocks(*argv)
|
144
|
+
end
|
145
|
+
|
146
|
+
def window_iterator (*argv) # :nodoc:
|
147
|
+
warn "CArray#window_iterator will be obsolete, use CArray#windows"
|
148
|
+
return windows(*argv)
|
149
|
+
end
|
150
|
+
|
151
|
+
def rotated (*argv) # :nodoc:
|
152
|
+
warn "CArray#rotated will be obsolete, use CArray#rolled"
|
153
|
+
argv.push({:roll => Array.new(ndim){1} })
|
154
|
+
return shifted(*argv)
|
155
|
+
end
|
156
|
+
|
157
|
+
def rotate! (*argv) # :nodoc:
|
158
|
+
warn "CArray#rotate! will be obsolete, use CArray#roll!"
|
159
|
+
self[] = self.rolled(*argv)
|
160
|
+
return self
|
161
|
+
end
|
162
|
+
|
163
|
+
def rotate (*argv) # :nodoc:
|
164
|
+
warn "CArray#rotate will be obsolete, use CArray#roll"
|
165
|
+
return self.rolled(*argv).to_ca
|
166
|
+
end
|
167
|
+
|
168
|
+
def select (&block) # :nodoc:
|
169
|
+
warn "CArray#select will be obsolete"
|
170
|
+
case block.arity
|
171
|
+
when 1
|
172
|
+
return self[*yield(self)]
|
173
|
+
when -1, 0
|
174
|
+
return self[*instance_exec(&block)]
|
175
|
+
else
|
176
|
+
raise
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
def transform (type, dim, opt = {}) # :nodoc:
|
181
|
+
warn("CArray#transform will be obsolete")
|
182
|
+
return refer(type, dim, opt).to_ca
|
183
|
+
end
|
184
|
+
|
185
|
+
def classify (klass, outlier = nil) # :nodoc:
|
186
|
+
warn "CArray#classify will be obsolete"
|
187
|
+
b = CArray.int32(*dim)
|
188
|
+
f = CArray.boolean(*dim) { 1 }
|
189
|
+
attach {
|
190
|
+
(klass.elements-1).times do |i|
|
191
|
+
r = f.and(self < klass[i+1])
|
192
|
+
b[r] = i
|
193
|
+
f[r] = 0
|
194
|
+
end
|
195
|
+
if outlier
|
196
|
+
b[self < klass[0]] = outlier
|
197
|
+
b[f] = outlier
|
198
|
+
else
|
199
|
+
b[self < klass[0]] = -1
|
200
|
+
b[f] = klass.elements-1
|
201
|
+
end
|
202
|
+
}
|
203
|
+
return b
|
204
|
+
end
|
205
|
+
|
206
|
+
|
207
|
+
|
208
|
+
end
|
209
|
+
|
210
|
+
=begin
|
211
|
+
|
212
|
+
class Numeric
|
213
|
+
|
214
|
+
[
|
215
|
+
:boolean,
|
216
|
+
:int8,
|
217
|
+
:uint8,
|
218
|
+
:int16,
|
219
|
+
:uint16,
|
220
|
+
:int32,
|
221
|
+
:uint32,
|
222
|
+
:int64,
|
223
|
+
:uint64,
|
224
|
+
:float32,
|
225
|
+
:float64,
|
226
|
+
:float128,
|
227
|
+
:cmplx64,
|
228
|
+
:cmplx128,
|
229
|
+
:cmplx256,
|
230
|
+
:byte,
|
231
|
+
:short,
|
232
|
+
:int,
|
233
|
+
:float,
|
234
|
+
:double,
|
235
|
+
:complex,
|
236
|
+
:dcomplex,
|
237
|
+
:object
|
238
|
+
].each do |name|
|
239
|
+
class_eval %{
|
240
|
+
def #{name} ()
|
241
|
+
warn "Numeric##{name} will be obsolete"
|
242
|
+
CScalar.new(#{name.inspect}) {self}
|
243
|
+
end
|
244
|
+
}
|
245
|
+
end
|
246
|
+
|
247
|
+
end
|
248
|
+
|
249
|
+
class CArray
|
250
|
+
def histogram (klass)
|
251
|
+
c = CArray.int32(klass.elements-1)
|
252
|
+
f = CArray.boolean(*dim) { 1 }
|
253
|
+
attach {
|
254
|
+
k = 0
|
255
|
+
r = f.and(self < klass[0])
|
256
|
+
f[r] = 0
|
257
|
+
(klass.elements-1).times do |i|
|
258
|
+
r = f.and(self < klass[i+1])
|
259
|
+
c[k] = r.count_true
|
260
|
+
f[r] = 0
|
261
|
+
k+=1
|
262
|
+
end
|
263
|
+
}
|
264
|
+
return c
|
265
|
+
end
|
266
|
+
|
267
|
+
def self.load_from_file (filename, data_type, dim, opt={}) # :nodoc:
|
268
|
+
raise "Sorry, CArray.load_from_file is depleted"
|
269
|
+
end
|
270
|
+
|
271
|
+
end
|
272
|
+
=end
|