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
data/lib/carray/io/pg.rb
DELETED
@@ -1,101 +0,0 @@
|
|
1
|
-
require "pg"
|
2
|
-
require "carray"
|
3
|
-
|
4
|
-
class CArray
|
5
|
-
|
6
|
-
def self.load_pg (expr, *args)
|
7
|
-
case expr
|
8
|
-
when Hash
|
9
|
-
opts = expr
|
10
|
-
sql, *vars = *args
|
11
|
-
db = PG.connect(opts)
|
12
|
-
begin
|
13
|
-
result = db.async_exec(sql, *vars)
|
14
|
-
names = result.fields
|
15
|
-
table = result.values
|
16
|
-
rescue Interrupt
|
17
|
-
db.cancel
|
18
|
-
raise
|
19
|
-
ensure
|
20
|
-
db.finish
|
21
|
-
end
|
22
|
-
when PG::Result
|
23
|
-
result = expr
|
24
|
-
names = result.fields
|
25
|
-
table = result.values
|
26
|
-
when PG::Connection
|
27
|
-
db = expr
|
28
|
-
sql, *vars = *args
|
29
|
-
begin
|
30
|
-
result = db.async_exec(sql, *vars)
|
31
|
-
names = result.fields
|
32
|
-
table = result.values
|
33
|
-
rescue Interrupt
|
34
|
-
db.cancel
|
35
|
-
raise
|
36
|
-
end
|
37
|
-
else
|
38
|
-
raise "invalid 1st arg"
|
39
|
-
end
|
40
|
-
table = table.to_ca
|
41
|
-
table.instance_exec {
|
42
|
-
@result = result
|
43
|
-
@names = names
|
44
|
-
}
|
45
|
-
class << table
|
46
|
-
attr_reader :names, :result
|
47
|
-
def column (name)
|
48
|
-
if self.size == 0
|
49
|
-
if name.is_a?(Integer)
|
50
|
-
return CA_OBJECT([])
|
51
|
-
elsif @names
|
52
|
-
if i = @names.index(name.to_s)
|
53
|
-
return CA_OBJECT([])
|
54
|
-
end
|
55
|
-
end
|
56
|
-
return nil
|
57
|
-
else
|
58
|
-
if name.is_a?(Integer)
|
59
|
-
return self[false, name]
|
60
|
-
elsif @names
|
61
|
-
if i = @names.index(name.to_s)
|
62
|
-
return self[false, i]
|
63
|
-
end
|
64
|
-
end
|
65
|
-
return nil
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
return table
|
70
|
-
end
|
71
|
-
|
72
|
-
def unescape_bytea (type, subdim = nil)
|
73
|
-
bytes = CArray.sizeof(type)
|
74
|
-
max_bytesize = self.convert{|v| v ? PG::Connection.unescape_bytea(v).bytesize : 0}.max
|
75
|
-
unless subdim
|
76
|
-
subdim = [max_bytesize/bytes]
|
77
|
-
end
|
78
|
-
out = CArray.new(type, dim + subdim)
|
79
|
-
needed_bytes = out.elements/self.elements*bytes
|
80
|
-
ref = out.refer(:fixlen, dim, :bytes=>needed_bytes)
|
81
|
-
if needed_bytes == max_bytesize
|
82
|
-
ref.load_binary self.convert {|v| PG::Connection.unescape_bytea(v) }.join
|
83
|
-
else
|
84
|
-
self.each_addr do |addr|
|
85
|
-
if self[addr]
|
86
|
-
text = PG::Connection.unescape_bytea(self[addr])
|
87
|
-
ref[[addr]].load_binary PG::Connection.unescape_bytea(self[addr])
|
88
|
-
else
|
89
|
-
out[addr,false] = UNDEF
|
90
|
-
end
|
91
|
-
end
|
92
|
-
end
|
93
|
-
return out
|
94
|
-
end
|
95
|
-
|
96
|
-
def escape_bytea (db)
|
97
|
-
return db.escape_bytea(self.to_s)
|
98
|
-
end
|
99
|
-
|
100
|
-
end
|
101
|
-
|
data/lib/carray/io/sqlite3.rb
DELETED
@@ -1,215 +0,0 @@
|
|
1
|
-
require "carray"
|
2
|
-
require "sqlite3"
|
3
|
-
require "carray/io/table"
|
4
|
-
|
5
|
-
class CArray
|
6
|
-
|
7
|
-
def self.load_sqlite3 (expr, *args)
|
8
|
-
case expr
|
9
|
-
when String
|
10
|
-
file = expr
|
11
|
-
sql, *vars = *args
|
12
|
-
db = SQLite3::Database.new(file)
|
13
|
-
names, *table = db.execute2(sql, *vars)
|
14
|
-
db.close
|
15
|
-
when SQLite3::Database
|
16
|
-
db = expr
|
17
|
-
sql, *vars = *args
|
18
|
-
names, *table = db.execute2(sql, *vars)
|
19
|
-
when SQLite3::Statement
|
20
|
-
stmt = expr
|
21
|
-
vars = args
|
22
|
-
names = stmt.columns
|
23
|
-
table = stmt.execute!(*vars)
|
24
|
-
else
|
25
|
-
raise "invalid 1st arg"
|
26
|
-
end
|
27
|
-
table = table.to_ca
|
28
|
-
table.extend(CA::TableMethods)
|
29
|
-
table.column_names = names
|
30
|
-
return table
|
31
|
-
end
|
32
|
-
|
33
|
-
def to_sqlite3 (database: nil, table:, datatype: "numeric", schema: nil, transaction: true)
|
34
|
-
unless rank <= 2
|
35
|
-
raise "to_sqlite3 is valid only for 2-dim array (table)"
|
36
|
-
end
|
37
|
-
case database
|
38
|
-
when SQLite3::Database
|
39
|
-
when String
|
40
|
-
if File.exist? database
|
41
|
-
database = SQLite3::Database.open(database)
|
42
|
-
else
|
43
|
-
database = SQLite3::Database.new(database)
|
44
|
-
end
|
45
|
-
else
|
46
|
-
database = SQLite3::Database.new ":memory:"
|
47
|
-
end
|
48
|
-
if respond_to?(:column_names) and column_names
|
49
|
-
vars = column_names
|
50
|
-
else
|
51
|
-
if rank == 1
|
52
|
-
vars = ["c0"]
|
53
|
-
else
|
54
|
-
vars = CArray.object(dim1).seq.map{|s| "c#{s}" }
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
if schema
|
59
|
-
database.execute "create table if not exists #{table} (" + schema + ")"
|
60
|
-
else
|
61
|
-
database.execute "create table if not exists #{table} (" + vars.map{|s| s + " " + datatype }.join(",") + ")"
|
62
|
-
end
|
63
|
-
|
64
|
-
insert = database.prepare %{ insert or replace into #{table} values (#{(["?"]*vars.size).join(",")}) }
|
65
|
-
database.transaction if transaction
|
66
|
-
if rank == 1
|
67
|
-
dim0.times do |i|
|
68
|
-
insert.execute [self[i]]
|
69
|
-
end
|
70
|
-
else
|
71
|
-
begin
|
72
|
-
dim0.times do |i|
|
73
|
-
begin
|
74
|
-
insert.execute self[i,nil].to_a
|
75
|
-
rescue
|
76
|
-
puts self[i,nil].to_a
|
77
|
-
raise $!
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
82
|
-
database.commit if transaction
|
83
|
-
insert.close
|
84
|
-
return database
|
85
|
-
end
|
86
|
-
|
87
|
-
def unblob (type, subdim = nil)
|
88
|
-
bytes = CArray.sizeof(type)
|
89
|
-
elem = nil
|
90
|
-
self.each do |e|
|
91
|
-
unless e.nil?
|
92
|
-
elem = e
|
93
|
-
break
|
94
|
-
end
|
95
|
-
end
|
96
|
-
if elem == nil and subdim == nil
|
97
|
-
raise "all element is nil, please specify dimension."
|
98
|
-
end
|
99
|
-
unless subdim
|
100
|
-
subdim = [elem.bytesize/bytes]
|
101
|
-
end
|
102
|
-
out = CArray.new(type, dim + subdim)
|
103
|
-
needed_bytes = out.elements/self.elements*bytes
|
104
|
-
ref = out.refer(:fixlen, dim, :bytes=>needed_bytes)
|
105
|
-
if elem and needed_bytes != elem.bytesize
|
106
|
-
self.each_addr do |addr|
|
107
|
-
if self[addr].nil?
|
108
|
-
ref[[addr]] = UNDEF
|
109
|
-
else
|
110
|
-
ref[[addr]].load_binary self[addr]
|
111
|
-
end
|
112
|
-
end
|
113
|
-
elsif self.any_equal?(nil)
|
114
|
-
copy = self.to_ca
|
115
|
-
sel = self.eq(nil)
|
116
|
-
copy[sel] = "\0" * needed_bytes
|
117
|
-
ref.load_binary copy.join
|
118
|
-
ref[sel] = UNDEF
|
119
|
-
else
|
120
|
-
ref.load_binary self.join
|
121
|
-
end
|
122
|
-
return out
|
123
|
-
end
|
124
|
-
|
125
|
-
end
|
126
|
-
|
127
|
-
module SQLite3
|
128
|
-
|
129
|
-
class Database
|
130
|
-
|
131
|
-
def create_table (table, data, names = nil)
|
132
|
-
ncols = data.rank == 1 ? 1 : data.dim1
|
133
|
-
if names
|
134
|
-
varlist = names.map{|s| s.to_s }
|
135
|
-
elsif data.respond_to?(:names)
|
136
|
-
varlist = data.names
|
137
|
-
else
|
138
|
-
varlist = []
|
139
|
-
ncols.times do |i|
|
140
|
-
varlist << "col#{i}"
|
141
|
-
end
|
142
|
-
end
|
143
|
-
execute %{create table #{table} (#{varlist.join(",")})}
|
144
|
-
insert(table, data)
|
145
|
-
end
|
146
|
-
|
147
|
-
def insert (table, data)
|
148
|
-
table_info = execute %{
|
149
|
-
pragma table_info(#{table})
|
150
|
-
}
|
151
|
-
if table_info.empty?
|
152
|
-
raise "#{table} is empty table"
|
153
|
-
end
|
154
|
-
qstns = (["?"]*table_info.size).join(",")
|
155
|
-
self.transaction {
|
156
|
-
stmt = prepare %{
|
157
|
-
insert or replace into #{table} values (#{qstns})
|
158
|
-
}
|
159
|
-
data.to_a.each do |row|
|
160
|
-
stmt.execute *row
|
161
|
-
end
|
162
|
-
stmt.close
|
163
|
-
}
|
164
|
-
end
|
165
|
-
|
166
|
-
def schema (table = nil)
|
167
|
-
if table
|
168
|
-
return get_first_value %{
|
169
|
-
select sql from sqlite_master where type in ('table', 'view', 'index') and name = "#{table}"
|
170
|
-
}
|
171
|
-
else
|
172
|
-
return execute(%{
|
173
|
-
select sql from sqlite_master where type in ('table', 'view', 'index')
|
174
|
-
}).map{|v| v[0]}
|
175
|
-
end
|
176
|
-
end
|
177
|
-
|
178
|
-
# insert
|
179
|
-
def import_table (dbfile, src_table, dst_table = nil)
|
180
|
-
dst_table ||= src_table
|
181
|
-
db = "db#{Thread.current.object_id}"
|
182
|
-
execute %{
|
183
|
-
attach database "#{dbfile}" as #{db};
|
184
|
-
}
|
185
|
-
sql = get_first_value %{
|
186
|
-
select sql from #{db}.sqlite_master where type = 'table' and name = "#{src_table}"
|
187
|
-
}
|
188
|
-
sql.sub!(/create\s+table\s(.+?)\s/i, "create table if not exists #{dst_table}")
|
189
|
-
execute sql
|
190
|
-
execute %{
|
191
|
-
insert into #{dst_table} select * from #{db}.#{src_table};
|
192
|
-
}
|
193
|
-
indeces = execute %{
|
194
|
-
select sql from #{db}.sqlite_master where type = 'index' and tbl_name = "#{src_table}"
|
195
|
-
}
|
196
|
-
indeces.each do |row|
|
197
|
-
sql = row[0]
|
198
|
-
unless sql
|
199
|
-
break
|
200
|
-
end
|
201
|
-
sql.sub!(/create\s+index/i, "create index if not exists")
|
202
|
-
sql.sub!(/on\s+#{src_table}\(/i, "on #{dst_table}(")
|
203
|
-
execute sql
|
204
|
-
end
|
205
|
-
execute %{
|
206
|
-
detach database #{db};
|
207
|
-
}
|
208
|
-
end
|
209
|
-
|
210
|
-
end
|
211
|
-
|
212
|
-
end
|
213
|
-
|
214
|
-
|
215
|
-
|
data/lib/carray/math/interp.rb
DELETED
@@ -1,57 +0,0 @@
|
|
1
|
-
# ----------------------------------------------------------------------------
|
2
|
-
#
|
3
|
-
# carray/math/interp.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 "carray"
|
14
|
-
|
15
|
-
class CA::Interp
|
16
|
-
|
17
|
-
ADAPTERS = {}
|
18
|
-
|
19
|
-
def initialize (type, scales, value, options={})
|
20
|
-
adapter_class = ADAPTERS[type]
|
21
|
-
if adapter_class
|
22
|
-
@type = type
|
23
|
-
@adapter = adapter_class.new(scales, value, options)
|
24
|
-
else
|
25
|
-
raise RuntimeError, "unknown interp adapter <#{type}>"
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
def [] (*args)
|
30
|
-
return @adapter.evaluate(*args)
|
31
|
-
end
|
32
|
-
|
33
|
-
def method_missing (id, *args)
|
34
|
-
return @adapter.send(id, *args)
|
35
|
-
end
|
36
|
-
|
37
|
-
end
|
38
|
-
|
39
|
-
class CA::Interp::Adapter # :nodoc:
|
40
|
-
|
41
|
-
def self.install_adapter (name)
|
42
|
-
CA::Interp::ADAPTERS[name] = self
|
43
|
-
end
|
44
|
-
|
45
|
-
end
|
46
|
-
|
47
|
-
def CA.interp (*argv)
|
48
|
-
return CA::Interp.new(*argv)
|
49
|
-
end
|
50
|
-
|
51
|
-
CA.each_load_path("carray/math/interp") {
|
52
|
-
Dir["adapter_*.rb"].each do |basename|
|
53
|
-
if basename =~ /\A(adapter_.+)\.rb\Z/
|
54
|
-
require "carray/math/interp/" + $1
|
55
|
-
end
|
56
|
-
end
|
57
|
-
}
|
@@ -1,47 +0,0 @@
|
|
1
|
-
#
|
2
|
-
#
|
3
|
-
#
|
4
|
-
|
5
|
-
#
|
6
|
-
# :type => type
|
7
|
-
#
|
8
|
-
# * "linear"
|
9
|
-
# * "polynomial"
|
10
|
-
# * "cspline"
|
11
|
-
# * "cspline_periodic"
|
12
|
-
# * "akima"
|
13
|
-
# * "akima_periodic"
|
14
|
-
#
|
15
|
-
|
16
|
-
require "carray/math/interp"
|
17
|
-
begin
|
18
|
-
require "gsl"
|
19
|
-
rescue LoadError
|
20
|
-
end
|
21
|
-
|
22
|
-
class CA::Interp::GSLSpline < CA::Interp::Adapter
|
23
|
-
|
24
|
-
install_adapter "gsl:spline"
|
25
|
-
|
26
|
-
def initialize (scales, value, options={})
|
27
|
-
@y = value
|
28
|
-
@x = scales
|
29
|
-
type = options[:type] || "linear"
|
30
|
-
CArray.attach(@x, @y) {
|
31
|
-
@interp = GSL::Spline.alloc(type, @x.na, @y.na)
|
32
|
-
}
|
33
|
-
end
|
34
|
-
|
35
|
-
def evaluate (x0)
|
36
|
-
case x0
|
37
|
-
when CArray
|
38
|
-
return x0.attach { @interp.eval(x0.na).ca }
|
39
|
-
else
|
40
|
-
return @interp.eval(x0)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
alias grid evaluate
|
45
|
-
|
46
|
-
end
|
47
|
-
|
data/mt19937ar.c
DELETED
@@ -1,182 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
The names of routines in original mt19937ar.c are all prefixed with "ca_"
|
3
|
-
to avoid collision with ruby's runtime library.
|
4
|
-
*/
|
5
|
-
|
6
|
-
#include "mt19937ar.h"
|
7
|
-
|
8
|
-
/*
|
9
|
-
A C-program for MT19937, with initialization improved 2002/1/26.
|
10
|
-
Coded by Takuji Nishimura and Makoto Matsumoto.
|
11
|
-
|
12
|
-
Before using, initialize the state by using init_genrand(seed)
|
13
|
-
or init_by_array(init_key, key_length).
|
14
|
-
|
15
|
-
Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura,
|
16
|
-
All rights reserved.
|
17
|
-
Copyright (C) 2005, Mutsuo Saito,
|
18
|
-
All rights reserved.
|
19
|
-
|
20
|
-
Redistribution and use in source and binary forms, with or without
|
21
|
-
modification, are permitted provided that the following conditions
|
22
|
-
are met:
|
23
|
-
|
24
|
-
1. Redistributions of source code must retain the above copyright
|
25
|
-
notice, this list of conditions and the following disclaimer.
|
26
|
-
|
27
|
-
2. Redistributions in binary form must reproduce the above copyright
|
28
|
-
notice, this list of conditions and the following disclaimer in the
|
29
|
-
documentation and/or other materials provided with the distribution.
|
30
|
-
|
31
|
-
3. The names of its contributors may not be used to endorse or promote
|
32
|
-
products derived from this software without specific prior written
|
33
|
-
permission.
|
34
|
-
|
35
|
-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
36
|
-
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
37
|
-
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
38
|
-
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
39
|
-
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
40
|
-
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
41
|
-
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
42
|
-
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
43
|
-
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
44
|
-
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
45
|
-
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
46
|
-
|
47
|
-
|
48
|
-
Any feedback is very welcome.
|
49
|
-
http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html
|
50
|
-
email: m-mat @ math.sci.hiroshima-u.ac.jp (remove space)
|
51
|
-
*/
|
52
|
-
|
53
|
-
#include <stdio.h>
|
54
|
-
#include "mt19937ar.h"
|
55
|
-
|
56
|
-
/* Period parameters */
|
57
|
-
#define N 624
|
58
|
-
#define M 397
|
59
|
-
#define MATRIX_A 0x9908b0dfUL /* constant vector a */
|
60
|
-
#define UPPER_MASK 0x80000000UL /* most significant w-r bits */
|
61
|
-
#define LOWER_MASK 0x7fffffffUL /* least significant r bits */
|
62
|
-
|
63
|
-
static unsigned long mt[N]; /* the array for the state vector */
|
64
|
-
static int mti=N+1; /* mti==N+1 means mt[N] is not initialized */
|
65
|
-
|
66
|
-
/* initializes mt[N] with a seed */
|
67
|
-
void init_genrand(unsigned long s)
|
68
|
-
{
|
69
|
-
mt[0]= s & 0xffffffffUL;
|
70
|
-
for (mti=1; mti<N; mti++) {
|
71
|
-
mt[mti] =
|
72
|
-
(1812433253UL * (mt[mti-1] ^ (mt[mti-1] >> 30)) + mti);
|
73
|
-
/* See Knuth TAOCP Vol2. 3rd Ed. P.106 for multiplier. */
|
74
|
-
/* In the previous versions, MSBs of the seed affect */
|
75
|
-
/* only MSBs of the array mt[]. */
|
76
|
-
/* 2002/01/09 modified by Makoto Matsumoto */
|
77
|
-
mt[mti] &= 0xffffffffUL;
|
78
|
-
/* for >32 bit machines */
|
79
|
-
}
|
80
|
-
}
|
81
|
-
|
82
|
-
/* initialize by an array with array-length */
|
83
|
-
/* init_key is the array for initializing keys */
|
84
|
-
/* key_length is its length */
|
85
|
-
/* slight change for C++, 2004/2/26 */
|
86
|
-
void init_by_array(unsigned long init_key[], int key_length)
|
87
|
-
{
|
88
|
-
int i, j, k;
|
89
|
-
init_genrand(19650218UL);
|
90
|
-
i=1; j=0;
|
91
|
-
k = (N>key_length ? N : key_length);
|
92
|
-
for (; k; k--) {
|
93
|
-
mt[i] = (mt[i] ^ ((mt[i-1] ^ (mt[i-1] >> 30)) * 1664525UL))
|
94
|
-
+ init_key[j] + j; /* non linear */
|
95
|
-
mt[i] &= 0xffffffffUL; /* for WORDSIZE > 32 machines */
|
96
|
-
i++; j++;
|
97
|
-
if (i>=N) { mt[0] = mt[N-1]; i=1; }
|
98
|
-
if (j>=key_length) j=0;
|
99
|
-
}
|
100
|
-
for (k=N-1; k; k--) {
|
101
|
-
mt[i] = (mt[i] ^ ((mt[i-1] ^ (mt[i-1] >> 30)) * 1566083941UL))
|
102
|
-
- i; /* non linear */
|
103
|
-
mt[i] &= 0xffffffffUL; /* for WORDSIZE > 32 machines */
|
104
|
-
i++;
|
105
|
-
if (i>=N) { mt[0] = mt[N-1]; i=1; }
|
106
|
-
}
|
107
|
-
|
108
|
-
mt[0] = 0x80000000UL; /* MSB is 1; assuring non-zero initial array */
|
109
|
-
}
|
110
|
-
|
111
|
-
/* generates a random number on [0,0xffffffff]-interval */
|
112
|
-
unsigned long genrand_int32(void)
|
113
|
-
{
|
114
|
-
unsigned long y;
|
115
|
-
static unsigned long mag01[2]={0x0UL, MATRIX_A};
|
116
|
-
/* mag01[x] = x * MATRIX_A for x=0,1 */
|
117
|
-
|
118
|
-
if (mti >= N) { /* generate N words at one time */
|
119
|
-
int kk;
|
120
|
-
|
121
|
-
if (mti == N+1) /* if init_genrand() has not been called, */
|
122
|
-
init_genrand(5489UL); /* a default initial seed is used */
|
123
|
-
|
124
|
-
for (kk=0;kk<N-M;kk++) {
|
125
|
-
y = (mt[kk]&UPPER_MASK)|(mt[kk+1]&LOWER_MASK);
|
126
|
-
mt[kk] = mt[kk+M] ^ (y >> 1) ^ mag01[y & 0x1UL];
|
127
|
-
}
|
128
|
-
for (;kk<N-1;kk++) {
|
129
|
-
y = (mt[kk]&UPPER_MASK)|(mt[kk+1]&LOWER_MASK);
|
130
|
-
mt[kk] = mt[kk+(M-N)] ^ (y >> 1) ^ mag01[y & 0x1UL];
|
131
|
-
}
|
132
|
-
y = (mt[N-1]&UPPER_MASK)|(mt[0]&LOWER_MASK);
|
133
|
-
mt[N-1] = mt[M-1] ^ (y >> 1) ^ mag01[y & 0x1UL];
|
134
|
-
|
135
|
-
mti = 0;
|
136
|
-
}
|
137
|
-
|
138
|
-
y = mt[mti++];
|
139
|
-
|
140
|
-
/* Tempering */
|
141
|
-
y ^= (y >> 11);
|
142
|
-
y ^= (y << 7) & 0x9d2c5680UL;
|
143
|
-
y ^= (y << 15) & 0xefc60000UL;
|
144
|
-
y ^= (y >> 18);
|
145
|
-
|
146
|
-
return y;
|
147
|
-
}
|
148
|
-
|
149
|
-
/* generates a random number on [0,0x7fffffff]-interval */
|
150
|
-
long genrand_int31(void)
|
151
|
-
{
|
152
|
-
return (long)(genrand_int32()>>1);
|
153
|
-
}
|
154
|
-
|
155
|
-
/* generates a random number on [0,1]-real-interval */
|
156
|
-
double genrand_real1(void)
|
157
|
-
{
|
158
|
-
return genrand_int32()*(1.0/4294967295.0);
|
159
|
-
/* divided by 2^32-1 */
|
160
|
-
}
|
161
|
-
|
162
|
-
/* generates a random number on [0,1)-real-interval */
|
163
|
-
double genrand_real2(void)
|
164
|
-
{
|
165
|
-
return genrand_int32()*(1.0/4294967296.0);
|
166
|
-
/* divided by 2^32 */
|
167
|
-
}
|
168
|
-
|
169
|
-
/* generates a random number on (0,1)-real-interval */
|
170
|
-
double genrand_real3(void)
|
171
|
-
{
|
172
|
-
return (((double)genrand_int32()) + 0.5)*(1.0/4294967296.0);
|
173
|
-
/* divided by 2^32 */
|
174
|
-
}
|
175
|
-
|
176
|
-
/* generates a random number on [0,1) with 53-bit resolution*/
|
177
|
-
double genrand_res53(void)
|
178
|
-
{
|
179
|
-
unsigned long a=genrand_int32()>>5, b=genrand_int32()>>6;
|
180
|
-
return(a*67108864.0+b)*(1.0/9007199254740992.0);
|
181
|
-
}
|
182
|
-
/* These real versions are due to Isaku Wada, 2002/01/09 added */
|