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
@@ -0,0 +1,115 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
|
4
|
+
class CArray
|
5
|
+
|
6
|
+
#
|
7
|
+
# Returns the 8-bit integer CArray object filled with 0 which
|
8
|
+
# dimension size is same as +self+. The resulted array represents
|
9
|
+
# the logical array which has +false+ for its all elements.
|
10
|
+
#
|
11
|
+
def false ()
|
12
|
+
return template(:boolean)
|
13
|
+
end
|
14
|
+
|
15
|
+
#
|
16
|
+
# Returns the 8-bit integer CArray object filled with 1 which
|
17
|
+
# dimension size is same as +self+. The resulted array represents
|
18
|
+
# the logical array which has +true+ for its all elements.
|
19
|
+
#
|
20
|
+
def true ()
|
21
|
+
return template(:boolean) { 1 }
|
22
|
+
end
|
23
|
+
|
24
|
+
# Returns map
|
25
|
+
def map (&block)
|
26
|
+
return self.convert(CA_OBJECT, &block).to_a
|
27
|
+
end
|
28
|
+
|
29
|
+
#
|
30
|
+
# ref = CA_INT([[0,1,2],[1,2,0],[2,0,1]])
|
31
|
+
# a = CArray.int(3,3).seq(1)
|
32
|
+
# b = CArray.int(3,3).seq(11)
|
33
|
+
# c = CArray.int(3,3).seq(21)
|
34
|
+
#
|
35
|
+
# CArray.pickup(CA_OBJECT, ref, [a,b,c])
|
36
|
+
# => <CArray.object(3,3): elem=9 mem=72b
|
37
|
+
# [ [ 1, 12, 23 ],
|
38
|
+
# [ 14, 25, 6 ],
|
39
|
+
# [ 27, 8, 19 ] ]>
|
40
|
+
#
|
41
|
+
# CArray.pickup(CA_OBJECT, ref, ["a","b","c"])
|
42
|
+
# => <CArray.object(3,3): elem=9 mem=36b
|
43
|
+
# [ [ "a", "b", "c" ],
|
44
|
+
# [ "b", "c", "a" ],
|
45
|
+
# [ "c", "a", "b" ] ]>
|
46
|
+
#
|
47
|
+
def self.pickup (data_type, ref, args)
|
48
|
+
out = ref.template(data_type)
|
49
|
+
args.each_with_index do |v, i|
|
50
|
+
s = ref.eq(i)
|
51
|
+
case v
|
52
|
+
when CArray
|
53
|
+
out[s] = v[s]
|
54
|
+
else
|
55
|
+
out[s] = v
|
56
|
+
end
|
57
|
+
end
|
58
|
+
return out
|
59
|
+
end
|
60
|
+
|
61
|
+
# Array#join like method
|
62
|
+
#
|
63
|
+
# > a = CArray.object(3,3).seq("a",:succ)
|
64
|
+
# => <CArray.object(3,3): elem=9 mem=72b
|
65
|
+
# [ [ "a", "b", "c" ],
|
66
|
+
# [ "d", "e", "f" ],
|
67
|
+
# [ "g", "h", "i" ] ]>
|
68
|
+
#
|
69
|
+
# > a.join("\n",",")
|
70
|
+
# => "a,b,c\nd,e,f\ng,h,i"
|
71
|
+
#
|
72
|
+
|
73
|
+
def join (*argv)
|
74
|
+
case argv.size
|
75
|
+
when 0
|
76
|
+
return to_a.join()
|
77
|
+
when 1
|
78
|
+
sep = argv.shift
|
79
|
+
return to_a.join(sep)
|
80
|
+
else
|
81
|
+
sep = argv.shift
|
82
|
+
return self[:i, false].map { |s|
|
83
|
+
s[0, false].join(*argv)
|
84
|
+
}.join(sep)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
#
|
89
|
+
def to_bit_string (nb)
|
90
|
+
hex = CArray.uint8(((nb*elements)/8.0).ceil)
|
91
|
+
hex.bits[nil].paste([0], self.bits[false,[(nb-1)..0]].flatten)
|
92
|
+
hex.bits[] = hex.bits[nil,[-1..0]]
|
93
|
+
return hex.to_s
|
94
|
+
end
|
95
|
+
|
96
|
+
def from_bit_string (bstr, nb)
|
97
|
+
hex = CArray.uint8(bstr.length).load_binary(bstr)
|
98
|
+
hex.bits[] = hex.bits[nil,[-1..0]]
|
99
|
+
bits = hex.bits.flatten
|
100
|
+
self.bits[false,[(nb-1)..0]][nil].paste([0], bits)
|
101
|
+
return self
|
102
|
+
end
|
103
|
+
|
104
|
+
def self.from_bit_string (bstr, nb, data_type=CA_INT32, dim=nil)
|
105
|
+
if dim
|
106
|
+
obj = CArray.new(data_type, dim)
|
107
|
+
else
|
108
|
+
dim0 = ((bstr.length*8)/nb.to_f).floor
|
109
|
+
obj = CArray.new(data_type, [dim0])
|
110
|
+
end
|
111
|
+
obj.from_bit_string(bstr, nb)
|
112
|
+
return obj
|
113
|
+
end
|
114
|
+
|
115
|
+
end
|
@@ -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
|
@@ -148,7 +148,7 @@ class CArray
|
|
148
148
|
def quo (other)
|
149
149
|
case
|
150
150
|
when integer?
|
151
|
-
return
|
151
|
+
return object.quo_i(other)
|
152
152
|
when object?
|
153
153
|
return quo_i(other)
|
154
154
|
else
|
@@ -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
|