carray 1.3.7 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (78) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +0 -7
  3. data/Rakefile +31 -0
  4. data/carray.gemspec +9 -14
  5. data/carray.h +4 -0
  6. data/carray_access.c +50 -8
  7. data/carray_conversion.c +3 -3
  8. data/carray_generate.c +67 -1
  9. data/carray_math.rb +22 -22
  10. data/carray_operator.c +23 -0
  11. data/devel/im2col.rb +17 -0
  12. data/lib/carray.rb +32 -1
  13. data/lib/carray/autoload/autoload_base.rb +0 -4
  14. data/lib/carray/autoload/autoload_gem_cairo.rb +9 -0
  15. data/lib/carray/autoload/autoload_gem_ffi.rb +9 -0
  16. data/lib/carray/autoload/autoload_gem_gnuplot.rb +2 -0
  17. data/lib/carray/autoload/autoload_gem_io_csv.rb +14 -0
  18. data/lib/carray/autoload/autoload_gem_io_pg.rb +6 -0
  19. data/lib/carray/autoload/autoload_gem_io_sqlite3.rb +12 -0
  20. data/lib/carray/autoload/autoload_gem_narray.rb +10 -0
  21. data/lib/carray/autoload/autoload_gem_numo_narray.rb +14 -0
  22. data/lib/carray/autoload/autoload_gem_opencv.rb +16 -0
  23. data/lib/carray/autoload/autoload_gem_rmagick.rb +23 -0
  24. data/lib/carray/autoload/{autoload_graphics_zimg.rb → autoload_gem_zimg.rb} +0 -0
  25. data/lib/carray/base/autoload.rb +47 -5
  26. data/lib/carray/base/basic.rb +58 -2
  27. data/lib/carray/base/math.rb +1 -1
  28. data/lib/carray/base/string.rb +242 -0
  29. data/mkmath.rb +12 -2
  30. data/version.h +5 -5
  31. metadata +29 -109
  32. data/Gemfile +0 -8
  33. data/Gemfile.lock +0 -33
  34. data/ext/calculus/lib/autoload/autoload_math_calculus.rb +0 -2
  35. data/ext/fortio/extconf.rb +0 -3
  36. data/ext/fortio/lib/carray/autoload/autoload_fortran_format.rb +0 -5
  37. data/ext/fortio/lib/carray/io/fortran_format.rb +0 -43
  38. data/ext/fortio/lib/fortio.rb +0 -3
  39. data/ext/fortio/lib/fortio/fortran_format.rb +0 -605
  40. data/ext/fortio/lib/fortio/fortran_format.tab.rb +0 -536
  41. data/ext/fortio/lib/fortio/fortran_format.y +0 -215
  42. data/ext/fortio/lib/fortio/fortran_namelist.rb +0 -151
  43. data/ext/fortio/lib/fortio/fortran_namelist.tab.rb +0 -470
  44. data/ext/fortio/lib/fortio/fortran_namelist.y +0 -213
  45. data/ext/fortio/lib/fortio/fortran_sequential.rb +0 -345
  46. data/ext/fortio/ruby_fortio.c +0 -182
  47. data/ext/fortio/test/test_H.rb +0 -5
  48. data/ext/fortio/test/test_T.rb +0 -7
  49. data/ext/fortio/test/test_fortran_format.rb +0 -86
  50. data/ext/fortio/test/test_namelist.rb +0 -25
  51. data/ext/fortio/test/test_namelist_write.rb +0 -10
  52. data/ext/fortio/test/test_sequential.rb +0 -13
  53. data/ext/fortio/test/test_sequential2.rb +0 -13
  54. data/ext/fortio/work/test.rb +0 -10
  55. data/ext/fortio/work/test_e.rb +0 -19
  56. data/ext/fortio/work/test_ep.rb +0 -10
  57. data/ext/fortio/work/test_parse.rb +0 -12
  58. data/ext/mathfunc/lib/autoload/autoload_math_mathfunc.rb +0 -1
  59. data/ext/mathfunc/lib/math/mathfunc.rb +0 -15
  60. data/ext/narray/README +0 -22
  61. data/ext/narray/ca_wrap_narray.c +0 -500
  62. data/ext/narray/carray_narray.c +0 -21
  63. data/ext/narray/extconf.rb +0 -57
  64. data/ext/narray/lib/autoload/autoload_math_narray.rb +0 -1
  65. data/ext/narray/lib/autoload/autoload_math_narray_miss.rb +0 -11
  66. data/ext/narray/lib/math/narray.rb +0 -17
  67. data/ext/narray/lib/math/narray_miss.rb +0 -45
  68. data/lib/carray/autoload/autoload_graphics_gnuplot.rb +0 -2
  69. data/lib/carray/autoload/autoload_io_csv.rb +0 -14
  70. data/lib/carray/autoload/autoload_io_numo.rb +0 -9
  71. data/lib/carray/autoload/autoload_io_pg.rb +0 -6
  72. data/lib/carray/autoload/autoload_io_sqlite3.rb +0 -12
  73. data/lib/carray/graphics/gnuplot.rb +0 -2141
  74. data/lib/carray/graphics/zimg.rb +0 -296
  75. data/lib/carray/io/csv.rb +0 -572
  76. data/lib/carray/io/numo.rb +0 -52
  77. data/lib/carray/io/pg.rb +0 -101
  78. data/lib/carray/io/sqlite3.rb +0 -215
@@ -1,52 +0,0 @@
1
- require "numo/narray"
2
-
3
- class CArray
4
-
5
- CARRAY2NUMO = {
6
- CA_INT8 => Numo::Int8,
7
- CA_UINT8 => Numo::UInt8,
8
- CA_INT16 => Numo::Int16,
9
- CA_UINT16 => Numo::UInt16,
10
- CA_INT32 => Numo::Int32,
11
- CA_UINT32 => Numo::UInt32,
12
- CA_INT64 => Numo::Int64,
13
- CA_UINT64 => Numo::UInt64,
14
- CA_INT64 => Numo::Int64,
15
- CA_UINT64 => Numo::UInt64,
16
- CA_FLOAT32 => Numo::SFloat,
17
- CA_FLOAT64 => Numo::DFloat,
18
- }
19
-
20
- def to_numo
21
- narray = CARRAY2NUMO[data_type].new(*dim)
22
- narray.store_binary(to_s)
23
- return narray
24
- end
25
-
26
- end
27
-
28
- module Numo
29
-
30
- class NArray
31
-
32
- NUMO2CARRAY = {
33
- Numo::Int8 => CA_INT8,
34
- Numo::UInt8 => CA_UINT8,
35
- Numo::Int16 => CA_INT16 ,
36
- Numo::UInt16 => CA_UINT16 ,
37
- Numo::Int32 => CA_INT32 ,
38
- Numo::UInt32 => CA_UINT32,
39
- Numo::Int64 => CA_INT64 ,
40
- Numo::UInt64 => CA_UINT64,
41
- Numo::Int64 => CA_INT64 ,
42
- Numo::UInt64 => CA_UINT64,
43
- Numo::SFloat => CA_FLOAT32,
44
- Numo::DFloat => CA_FLOAT64,
45
- }
46
-
47
- def to_ca
48
- return CArray.new(NUMO2CARRAY[self.class], self.shape).load_binary(to_binary)
49
- end
50
-
51
- end
52
- end
@@ -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
-
@@ -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
-