numo-narray 0.9.0.1-x64-mingw32
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +4 -0
- data/README.md +47 -0
- data/Rakefile +41 -0
- data/ext/numo/narray/SFMT-params.h +97 -0
- data/ext/numo/narray/SFMT-params19937.h +46 -0
- data/ext/numo/narray/SFMT.c +620 -0
- data/ext/numo/narray/SFMT.h +157 -0
- data/ext/numo/narray/array.c +525 -0
- data/ext/numo/narray/data.c +901 -0
- data/ext/numo/narray/depend.erb +33 -0
- data/ext/numo/narray/extconf.rb +117 -0
- data/ext/numo/narray/gen/bit.erb.c +811 -0
- data/ext/numo/narray/gen/cogen.rb +18 -0
- data/ext/numo/narray/gen/def/dcomplex.rb +32 -0
- data/ext/numo/narray/gen/def/dfloat.rb +30 -0
- data/ext/numo/narray/gen/def/int16.rb +29 -0
- data/ext/numo/narray/gen/def/int32.rb +29 -0
- data/ext/numo/narray/gen/def/int64.rb +29 -0
- data/ext/numo/narray/gen/def/int8.rb +29 -0
- data/ext/numo/narray/gen/def/robject.rb +30 -0
- data/ext/numo/narray/gen/def/scomplex.rb +32 -0
- data/ext/numo/narray/gen/def/sfloat.rb +30 -0
- data/ext/numo/narray/gen/def/uint16.rb +29 -0
- data/ext/numo/narray/gen/def/uint32.rb +29 -0
- data/ext/numo/narray/gen/def/uint64.rb +29 -0
- data/ext/numo/narray/gen/def/uint8.rb +29 -0
- data/ext/numo/narray/gen/dtype.erb.c +328 -0
- data/ext/numo/narray/gen/tmpl/accum.c +36 -0
- data/ext/numo/narray/gen/tmpl/accum_binary.c +75 -0
- data/ext/numo/narray/gen/tmpl/accum_index.c +58 -0
- data/ext/numo/narray/gen/tmpl/allocate.c +35 -0
- data/ext/numo/narray/gen/tmpl/aref.c +51 -0
- data/ext/numo/narray/gen/tmpl/aset.c +61 -0
- data/ext/numo/narray/gen/tmpl/binary.c +53 -0
- data/ext/numo/narray/gen/tmpl/binary2.c +55 -0
- data/ext/numo/narray/gen/tmpl/binary_s.c +34 -0
- data/ext/numo/narray/gen/tmpl/bit_binary.c +94 -0
- data/ext/numo/narray/gen/tmpl/bit_count.c +82 -0
- data/ext/numo/narray/gen/tmpl/bit_unary.c +77 -0
- data/ext/numo/narray/gen/tmpl/cast.c +37 -0
- data/ext/numo/narray/gen/tmpl/cast_array.c +79 -0
- data/ext/numo/narray/gen/tmpl/cast_numeric.c +22 -0
- data/ext/numo/narray/gen/tmpl/coerce_cast.c +8 -0
- data/ext/numo/narray/gen/tmpl/cond_binary.c +51 -0
- data/ext/numo/narray/gen/tmpl/cond_unary.c +45 -0
- data/ext/numo/narray/gen/tmpl/cum.c +42 -0
- data/ext/numo/narray/gen/tmpl/each.c +43 -0
- data/ext/numo/narray/gen/tmpl/each_with_index.c +64 -0
- data/ext/numo/narray/gen/tmpl/extract.c +23 -0
- data/ext/numo/narray/gen/tmpl/eye.c +91 -0
- data/ext/numo/narray/gen/tmpl/fill.c +38 -0
- data/ext/numo/narray/gen/tmpl/format.c +60 -0
- data/ext/numo/narray/gen/tmpl/format_to_a.c +47 -0
- data/ext/numo/narray/gen/tmpl/head.c +25 -0
- data/ext/numo/narray/gen/tmpl/inspect.c +16 -0
- data/ext/numo/narray/gen/tmpl/map_with_index.c +94 -0
- data/ext/numo/narray/gen/tmpl/median.c +44 -0
- data/ext/numo/narray/gen/tmpl/minmax.c +47 -0
- data/ext/numo/narray/gen/tmpl/poly.c +49 -0
- data/ext/numo/narray/gen/tmpl/pow.c +74 -0
- data/ext/numo/narray/gen/tmpl/powint.c +17 -0
- data/ext/numo/narray/gen/tmpl/qsort.c +149 -0
- data/ext/numo/narray/gen/tmpl/rand.c +33 -0
- data/ext/numo/narray/gen/tmpl/rand_norm.c +46 -0
- data/ext/numo/narray/gen/tmpl/robj_allocate.c +32 -0
- data/ext/numo/narray/gen/tmpl/seq.c +61 -0
- data/ext/numo/narray/gen/tmpl/set2.c +56 -0
- data/ext/numo/narray/gen/tmpl/sort.c +36 -0
- data/ext/numo/narray/gen/tmpl/sort_index.c +86 -0
- data/ext/numo/narray/gen/tmpl/store.c +31 -0
- data/ext/numo/narray/gen/tmpl/store_array.c +5 -0
- data/ext/numo/narray/gen/tmpl/store_from.c +53 -0
- data/ext/numo/narray/gen/tmpl/store_numeric.c +22 -0
- data/ext/numo/narray/gen/tmpl/to_a.c +41 -0
- data/ext/numo/narray/gen/tmpl/unary.c +58 -0
- data/ext/numo/narray/gen/tmpl/unary2.c +58 -0
- data/ext/numo/narray/gen/tmpl/unary_s.c +57 -0
- data/ext/numo/narray/index.c +822 -0
- data/ext/numo/narray/kwarg.c +79 -0
- data/ext/numo/narray/math.c +140 -0
- data/ext/numo/narray/narray.c +1539 -0
- data/ext/numo/narray/ndloop.c +1928 -0
- data/ext/numo/narray/numo/compat.h +23 -0
- data/ext/numo/narray/numo/intern.h +112 -0
- data/ext/numo/narray/numo/narray.h +411 -0
- data/ext/numo/narray/numo/ndloop.h +99 -0
- data/ext/numo/narray/numo/template.h +140 -0
- data/ext/numo/narray/numo/types/bit.h +19 -0
- data/ext/numo/narray/numo/types/complex.h +410 -0
- data/ext/numo/narray/numo/types/complex_macro.h +205 -0
- data/ext/numo/narray/numo/types/dcomplex.h +11 -0
- data/ext/numo/narray/numo/types/dfloat.h +12 -0
- data/ext/numo/narray/numo/types/float_def.h +34 -0
- data/ext/numo/narray/numo/types/float_macro.h +277 -0
- data/ext/numo/narray/numo/types/int16.h +12 -0
- data/ext/numo/narray/numo/types/int32.h +12 -0
- data/ext/numo/narray/numo/types/int64.h +12 -0
- data/ext/numo/narray/numo/types/int8.h +12 -0
- data/ext/numo/narray/numo/types/int_macro.h +34 -0
- data/ext/numo/narray/numo/types/robj_macro.h +218 -0
- data/ext/numo/narray/numo/types/robject.h +21 -0
- data/ext/numo/narray/numo/types/scomplex.h +11 -0
- data/ext/numo/narray/numo/types/sfloat.h +13 -0
- data/ext/numo/narray/numo/types/uint16.h +12 -0
- data/ext/numo/narray/numo/types/uint32.h +12 -0
- data/ext/numo/narray/numo/types/uint64.h +12 -0
- data/ext/numo/narray/numo/types/uint8.h +12 -0
- data/ext/numo/narray/numo/types/uint_macro.h +31 -0
- data/ext/numo/narray/numo/types/xint_macro.h +133 -0
- data/ext/numo/narray/rand.c +87 -0
- data/ext/numo/narray/step.c +506 -0
- data/ext/numo/narray/struct.c +872 -0
- data/lib/2.1/numo/narray.so +0 -0
- data/lib/2.2/numo/narray.so +0 -0
- data/lib/2.3/numo/narray.so +0 -0
- data/lib/erbpp.rb +286 -0
- data/lib/erbpp/line_number.rb +126 -0
- data/lib/erbpp/narray_def.rb +338 -0
- data/lib/numo/narray.rb +6 -0
- data/numo-narray.gemspec +35 -0
- data/spec/bit_spec.rb +93 -0
- data/spec/narray_spec.rb +249 -0
- metadata +238 -0
Binary file
|
Binary file
|
Binary file
|
data/lib/erbpp.rb
ADDED
@@ -0,0 +1,286 @@
|
|
1
|
+
require "erb"
|
2
|
+
|
3
|
+
class ErbPP
|
4
|
+
ATTRS = []
|
5
|
+
|
6
|
+
class ParamNotSetError < StandardError; end
|
7
|
+
|
8
|
+
def self.define_attrs(attrs)
|
9
|
+
attrs.each do |attr|
|
10
|
+
ivar = ("@"+attr).to_sym
|
11
|
+
define_method(attr){|*a| attr_method(ivar,*a)}
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def attr_method(ivar,arg=nil)
|
16
|
+
if arg.nil?
|
17
|
+
instance_variable_get(ivar)
|
18
|
+
else
|
19
|
+
instance_variable_set(ivar,arg)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def initialize(parent,erb_path,opts={})
|
24
|
+
parents.push(parent) if parent
|
25
|
+
@erb_path = erb_path
|
26
|
+
@tmpl = @erb_path
|
27
|
+
|
28
|
+
@opts = opts
|
29
|
+
if @opts.class != Hash
|
30
|
+
raise ArgumentError, "option is not Hash"
|
31
|
+
end
|
32
|
+
|
33
|
+
@opts.each do |k,v|
|
34
|
+
ivar = ("@"+k.to_s).to_sym
|
35
|
+
instance_variable_set(ivar,v)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def load_erb
|
40
|
+
safe_level = nil
|
41
|
+
trim_mode = '%<>'
|
42
|
+
@erb = ERB.new(File.read(@erb_path),safe_level,trim_mode)
|
43
|
+
@erb.filename = @erb_path
|
44
|
+
end
|
45
|
+
|
46
|
+
def parents
|
47
|
+
@parents ||= []
|
48
|
+
end
|
49
|
+
|
50
|
+
def search_method_in_parents(_meth_id)
|
51
|
+
parents.each do |x|
|
52
|
+
if x.has_attr? _meth_id
|
53
|
+
return x
|
54
|
+
end
|
55
|
+
end
|
56
|
+
parents.each do |x|
|
57
|
+
if f = x.search_method_in_parents(_meth_id)
|
58
|
+
return f
|
59
|
+
end
|
60
|
+
end
|
61
|
+
nil
|
62
|
+
end
|
63
|
+
|
64
|
+
def attrs
|
65
|
+
self.class::ATTRS
|
66
|
+
end
|
67
|
+
|
68
|
+
def has_attr?(_meth_id)
|
69
|
+
respond_to?(_meth_id) or attrs.include?(_meth_id.to_s)
|
70
|
+
end
|
71
|
+
|
72
|
+
def check_params(*params)
|
73
|
+
params.each do |x|
|
74
|
+
val = send(x)
|
75
|
+
if !val # || val.empty?
|
76
|
+
raise ParamNotSetError,"parameter #{x.to_s} is not set"
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
alias method_missing_alias method_missing
|
82
|
+
|
83
|
+
def method_missing(_meth_id, *args, &block)
|
84
|
+
ivar = "@"+_meth_id.to_s
|
85
|
+
if args.empty? and instance_variable_defined?(ivar)
|
86
|
+
parm = instance_variable_get(ivar)
|
87
|
+
if parm.nil?
|
88
|
+
raise ParamNotSetError,"parameter #{_meth_id.to_s} is not set"
|
89
|
+
end
|
90
|
+
parm
|
91
|
+
elsif args.size == 1 and attrs.include?(_meth_id.to_s)
|
92
|
+
instance_variable_set(ivar,args.first)
|
93
|
+
elsif x = search_method_in_parents(_meth_id)
|
94
|
+
x.send(_meth_id, *args, &block)
|
95
|
+
else
|
96
|
+
method_missing_alias(_meth_id, *args)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
def run
|
101
|
+
load_erb unless @erb
|
102
|
+
@erb.run(binding)
|
103
|
+
end
|
104
|
+
|
105
|
+
def result
|
106
|
+
load_erb unless @erb
|
107
|
+
@erb.result(binding)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
# ----------------------------------------------------------------------
|
112
|
+
|
113
|
+
class IdVar
|
114
|
+
DEFS = []
|
115
|
+
|
116
|
+
def id_decl
|
117
|
+
"static ID #{@id_var};"
|
118
|
+
end
|
119
|
+
|
120
|
+
def id_assign
|
121
|
+
"#{@id_var} = rb_intern(\"#{@name}\");"
|
122
|
+
end
|
123
|
+
|
124
|
+
def initialize(parent,name,var=nil)
|
125
|
+
@name = name
|
126
|
+
var = name if var.nil?
|
127
|
+
@id_var = "id_"+var.gsub(/\?/,"_p").gsub(/\!/,"_bang")
|
128
|
+
DEFS.push(self)
|
129
|
+
end
|
130
|
+
|
131
|
+
def self.declaration
|
132
|
+
DEFS.map do |x|
|
133
|
+
x.id_decl
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
def self.assignment
|
138
|
+
DEFS.map do |x|
|
139
|
+
x.id_assign
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
# ----------------------------------------------------------------------
|
145
|
+
|
146
|
+
class Function < ErbPP
|
147
|
+
DEFS = []
|
148
|
+
|
149
|
+
attrs = %w[
|
150
|
+
singleton
|
151
|
+
method
|
152
|
+
n_arg
|
153
|
+
]
|
154
|
+
define_attrs attrs
|
155
|
+
|
156
|
+
def id_op
|
157
|
+
if op.size == 1
|
158
|
+
"'#{op}'"
|
159
|
+
else
|
160
|
+
"id_#{method}"
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
def initialize(parent,tmpl,**opts)
|
165
|
+
super
|
166
|
+
@aliases = opts[:aliases] || []
|
167
|
+
@erb_path = File.join(parent.tmpl_dir, tmpl+".c")
|
168
|
+
DEFS.push(self)
|
169
|
+
end
|
170
|
+
|
171
|
+
def c_method
|
172
|
+
"#{m_prefix}#{method}"
|
173
|
+
end
|
174
|
+
|
175
|
+
def c_iter
|
176
|
+
begin
|
177
|
+
t = "_"+type_name
|
178
|
+
rescue
|
179
|
+
t = ""
|
180
|
+
end
|
181
|
+
"iter#{t}_#{method}"
|
182
|
+
end
|
183
|
+
alias c_iterator c_iter
|
184
|
+
|
185
|
+
def c_func
|
186
|
+
s = singleton ? "_s" : ""
|
187
|
+
begin
|
188
|
+
t = "_"+type_name
|
189
|
+
rescue
|
190
|
+
t = ""
|
191
|
+
end
|
192
|
+
"numo#{t}#{s}_#{method}"
|
193
|
+
end
|
194
|
+
alias c_function c_func
|
195
|
+
alias c_instance_method c_func
|
196
|
+
|
197
|
+
def op_map
|
198
|
+
@op || method
|
199
|
+
end
|
200
|
+
|
201
|
+
def code
|
202
|
+
result + "\n\n"
|
203
|
+
end
|
204
|
+
|
205
|
+
def definition
|
206
|
+
s = singleton ? "_singleton" : ""
|
207
|
+
check_params(:mod_var, :op_map, :c_func, :n_arg)
|
208
|
+
m = op_map
|
209
|
+
a = ["rb_define#{s}_method(#{mod_var}, \"#{m}\", #{c_func}, #{n_arg});"]
|
210
|
+
@aliases.map{|x| a << "rb_define_alias(#{mod_var}, \"#{x}\", \"#{m}\");"}
|
211
|
+
a
|
212
|
+
end
|
213
|
+
|
214
|
+
def self.codes
|
215
|
+
a = []
|
216
|
+
DEFS.each do |i|
|
217
|
+
x = i.code
|
218
|
+
a.push(x) if x
|
219
|
+
end
|
220
|
+
a
|
221
|
+
end
|
222
|
+
|
223
|
+
def self.definitions
|
224
|
+
a = []
|
225
|
+
DEFS.each do |i|
|
226
|
+
case x = i.definition
|
227
|
+
when Array
|
228
|
+
a.concat(x)
|
229
|
+
when String
|
230
|
+
a.push(x)
|
231
|
+
else
|
232
|
+
raise "unknown definition: #{x}" if x
|
233
|
+
end
|
234
|
+
end
|
235
|
+
a
|
236
|
+
end
|
237
|
+
end
|
238
|
+
|
239
|
+
class ModuleFunction < Function
|
240
|
+
def definition
|
241
|
+
m = op_map
|
242
|
+
"rb_define_module_function(#{mod_var}, \"#{m}\", #{c_func}, #{n_arg});"
|
243
|
+
end
|
244
|
+
end
|
245
|
+
|
246
|
+
class NodefFunction < Function
|
247
|
+
def definition
|
248
|
+
nil
|
249
|
+
end
|
250
|
+
end
|
251
|
+
|
252
|
+
class Alias < ErbPP
|
253
|
+
def initialize(parent, dst, src)
|
254
|
+
super(parent,nil)
|
255
|
+
@dst = dst
|
256
|
+
@src = src
|
257
|
+
Function::DEFS.push(self)
|
258
|
+
end
|
259
|
+
|
260
|
+
def code
|
261
|
+
nil
|
262
|
+
end
|
263
|
+
|
264
|
+
def definition
|
265
|
+
"rb_define_alias(#{mod_var}, \"#{dst}\", \"#{src}\");"
|
266
|
+
end
|
267
|
+
end
|
268
|
+
|
269
|
+
class Const < ErbPP
|
270
|
+
def initialize(parent,name,value,desc)
|
271
|
+
super(parent,nil)
|
272
|
+
@name = name
|
273
|
+
@value = value
|
274
|
+
@desc = desc
|
275
|
+
Function::DEFS.push(self)
|
276
|
+
end
|
277
|
+
|
278
|
+
def code
|
279
|
+
nil
|
280
|
+
end
|
281
|
+
|
282
|
+
def definition
|
283
|
+
"/*"+desc+"*/\n "+
|
284
|
+
"rb_define_const(#{mod_var},\"#{name}\",#{value});"
|
285
|
+
end
|
286
|
+
end
|
@@ -0,0 +1,126 @@
|
|
1
|
+
class CountLnString < String
|
2
|
+
|
3
|
+
def initialize(filename)
|
4
|
+
@filename = filename
|
5
|
+
@lnchar = "\n"
|
6
|
+
@buf = ""
|
7
|
+
@str = ""
|
8
|
+
@countln = 1
|
9
|
+
@current = 1
|
10
|
+
super(report_line)
|
11
|
+
end
|
12
|
+
|
13
|
+
def report_line
|
14
|
+
"#line #{@current} \"#{@filename}\"\n"
|
15
|
+
end
|
16
|
+
|
17
|
+
def concat0(s)
|
18
|
+
ln(caller[0])
|
19
|
+
@buf.concat(s)
|
20
|
+
@str.concat(s)
|
21
|
+
end
|
22
|
+
|
23
|
+
def concat1(s)
|
24
|
+
ln(caller[0])
|
25
|
+
@buf.concat(s)
|
26
|
+
end
|
27
|
+
|
28
|
+
def ln(status=nil)
|
29
|
+
case status
|
30
|
+
when /:(\d+):/
|
31
|
+
n = $1.to_i
|
32
|
+
else
|
33
|
+
n = status.to_i
|
34
|
+
end
|
35
|
+
return if n == @current
|
36
|
+
if @current != @countln || @postpone
|
37
|
+
if /^\s*$/ =~ @str || /\A#line / =~ @buf
|
38
|
+
@postpone = true
|
39
|
+
elsif @in_comment
|
40
|
+
@postpone = false
|
41
|
+
else
|
42
|
+
concat(report_line)
|
43
|
+
@postpone = false
|
44
|
+
end
|
45
|
+
end
|
46
|
+
concat(@buf)
|
47
|
+
|
48
|
+
b = @buf.gsub(/".*?(?<!\\)"/,'""')
|
49
|
+
/^.*(\/\*)(.*?)$/ =~ b
|
50
|
+
x = $2
|
51
|
+
/^.*(\*\/)(.*?)$/ =~ b
|
52
|
+
y = $2
|
53
|
+
if x
|
54
|
+
if y
|
55
|
+
if x.size < y.size
|
56
|
+
#:in_comment
|
57
|
+
@in_comment = true
|
58
|
+
else
|
59
|
+
#:out_comment
|
60
|
+
@in_comment = false
|
61
|
+
end
|
62
|
+
else
|
63
|
+
#:in_comment
|
64
|
+
@in_comment = true
|
65
|
+
end
|
66
|
+
else
|
67
|
+
if y
|
68
|
+
#:out_comment
|
69
|
+
@in_comment = false
|
70
|
+
else
|
71
|
+
#:keep
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
@countln = @current + @buf.count(@lnchar)
|
76
|
+
@current = n
|
77
|
+
@buf = ""
|
78
|
+
@str = ""
|
79
|
+
end
|
80
|
+
|
81
|
+
def d(s)
|
82
|
+
p [s, [x,y], r]
|
83
|
+
r
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
87
|
+
|
88
|
+
class ERB
|
89
|
+
alias result_orig result
|
90
|
+
|
91
|
+
def result(b=new_toplevel)
|
92
|
+
src = src_with_cpp_line
|
93
|
+
if @safe_level
|
94
|
+
proc {
|
95
|
+
$SAFE = @safe_level
|
96
|
+
eval(src, b, (@filename || '(erb)'), 0)
|
97
|
+
}.call
|
98
|
+
else
|
99
|
+
#open("tmpout","w"){|f| f.write src} if /dtype/=~@filename
|
100
|
+
eval(src, b, (@filename || '(erb)'), 0)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
alias src_orig src
|
105
|
+
|
106
|
+
def src
|
107
|
+
src_with_cpp_line
|
108
|
+
end
|
109
|
+
|
110
|
+
def src_with_cpp_line
|
111
|
+
@src.each_line.with_index.map do |line, num|
|
112
|
+
line.gsub!(/_erbout.concat "/,'_erbout.concat0 "')
|
113
|
+
line.gsub!(/_erbout.concat\(/,'_erbout.concat1(')
|
114
|
+
if num==0
|
115
|
+
# skip
|
116
|
+
elsif num==1
|
117
|
+
f = @filename.dump
|
118
|
+
line.sub!(/_erbout = '';/, "_erbout = CountLnString.new(#{f});")
|
119
|
+
elsif /^; _erbout\.force_encoding/ =~ line
|
120
|
+
line.sub!(/^;/,";_erbout.ln(#{num});")
|
121
|
+
end
|
122
|
+
line
|
123
|
+
end.join
|
124
|
+
end
|
125
|
+
|
126
|
+
end
|
@@ -0,0 +1,338 @@
|
|
1
|
+
require 'erbpp'
|
2
|
+
|
3
|
+
module DefMethod
|
4
|
+
|
5
|
+
def def_id(meth,var=nil)
|
6
|
+
IdVar.new(self, meth, var)
|
7
|
+
end
|
8
|
+
|
9
|
+
def def_method(meth, n_arg, tmpl=nil, opts={})
|
10
|
+
h = {:method => meth, :n_arg => n_arg}
|
11
|
+
h.merge!(opts)
|
12
|
+
tmpl ||= meth
|
13
|
+
Function.new(self, tmpl, h)
|
14
|
+
end
|
15
|
+
|
16
|
+
def def_singleton(meth, n_arg, tmpl=nil, opts={})
|
17
|
+
def_method(meth, n_arg, tmpl, :singleton => true)
|
18
|
+
end
|
19
|
+
|
20
|
+
def def_alias(dst, src)
|
21
|
+
Alias.new(self, dst, src)
|
22
|
+
end
|
23
|
+
|
24
|
+
def def_allocate(tmpl)
|
25
|
+
h = {:method => "allocate", :singleton => true}
|
26
|
+
Allocate.new(self, tmpl, h)
|
27
|
+
end
|
28
|
+
|
29
|
+
def binary(meth, ope=nil)
|
30
|
+
ope = meth if ope.nil?
|
31
|
+
def_method(meth, 1, "binary", :op => ope)
|
32
|
+
end
|
33
|
+
|
34
|
+
def binary2(meth, ope=nil)
|
35
|
+
ope = meth if ope.nil?
|
36
|
+
def_method(meth, 1, "binary2", :op =>ope)
|
37
|
+
end
|
38
|
+
|
39
|
+
def unary(meth, ope=nil)
|
40
|
+
def_method(meth, 0, "unary", :op => ope)
|
41
|
+
end
|
42
|
+
|
43
|
+
def pow
|
44
|
+
def_method("pow", 1, "pow", :op => "**")
|
45
|
+
end
|
46
|
+
|
47
|
+
def unary2(meth, dtype, tpclass)
|
48
|
+
h = {:dtype => dtype, :tpclass => tpclass}
|
49
|
+
def_method(meth, 0, "unary2", h)
|
50
|
+
end
|
51
|
+
|
52
|
+
def set2(meth, dtype, tpclass)
|
53
|
+
h = {:dtype => dtype, :tpclass => tpclass}
|
54
|
+
def_method(meth, 1, "set2", h)
|
55
|
+
end
|
56
|
+
|
57
|
+
def cond_binary(meth,op=nil)
|
58
|
+
def_method(meth, 1, "cond_binary", :op => op)
|
59
|
+
end
|
60
|
+
|
61
|
+
def cond_unary(meth)
|
62
|
+
def_method(meth, 0, "cond_unary")
|
63
|
+
end
|
64
|
+
|
65
|
+
def bit_binary(meth, op=nil)
|
66
|
+
h = {:op=>op}
|
67
|
+
h[:aliases] = [meth] if op
|
68
|
+
def_method(meth, 1, "bit_binary", h)
|
69
|
+
end
|
70
|
+
|
71
|
+
def bit_unary(meth, op=nil)
|
72
|
+
h = {:op=>op}
|
73
|
+
h[:aliases] = [meth] if op
|
74
|
+
def_method(meth, 0, "bit_unary", h)
|
75
|
+
end
|
76
|
+
|
77
|
+
def bit_count(meth)
|
78
|
+
def_method(meth, -1, "bit_count")
|
79
|
+
end
|
80
|
+
|
81
|
+
def accum(meth, dtype, tpclass)
|
82
|
+
h = {:dtype => dtype, :tpclass => tpclass}
|
83
|
+
def_method(meth, -1, "accum", h)
|
84
|
+
end
|
85
|
+
|
86
|
+
def accum_index(meth)
|
87
|
+
def_method(meth, -1, "accum_index")
|
88
|
+
end
|
89
|
+
|
90
|
+
def cum(meth, cmacro)
|
91
|
+
def_method(meth, -1, "cum", cmacro:cmacro)
|
92
|
+
end
|
93
|
+
|
94
|
+
def accum_binary(meth, ope=nil)
|
95
|
+
ope = meth if ope.nil?
|
96
|
+
def_method(meth, -1, "accum_binary", :op => ope)
|
97
|
+
end
|
98
|
+
|
99
|
+
def qsort(tp, dtype, dcast)
|
100
|
+
h = {:tp => tp, :dtype => dtype, :dcast => dcast}
|
101
|
+
NodefFunction.new(self, "qsort", h)
|
102
|
+
end
|
103
|
+
|
104
|
+
def math(meth, n=1)
|
105
|
+
h = {:method => meth, :mod_var => 'mTM', :n_arg => n}
|
106
|
+
case n
|
107
|
+
when 1
|
108
|
+
ModuleFunction.new(self, "unary_s", h)
|
109
|
+
when 2
|
110
|
+
ModuleFunction.new(self, "binary_s", h)
|
111
|
+
when 3
|
112
|
+
ModuleFunction.new(self, "ternary_s", h)
|
113
|
+
else
|
114
|
+
raise "invalid n=#{n}"
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
def store_numeric
|
119
|
+
StoreNum.new(self,"store_numeric")
|
120
|
+
end
|
121
|
+
|
122
|
+
def store_array
|
123
|
+
StoreArray.new(self,"store_array")
|
124
|
+
end
|
125
|
+
|
126
|
+
def cast_array
|
127
|
+
CastArray.new(self,"cast_array")
|
128
|
+
end
|
129
|
+
|
130
|
+
def store_from(cname,dtype,macro)
|
131
|
+
Store.new(self,"store_from",cname.downcase,dtype,"numo_c"+cname,macro)
|
132
|
+
end
|
133
|
+
|
134
|
+
def store
|
135
|
+
Function.new(self,"store","store")
|
136
|
+
end
|
137
|
+
|
138
|
+
def find_method(meth)
|
139
|
+
Function::DEFS.find{|x| x.kind_of?(Function) and meth == x.method }
|
140
|
+
end
|
141
|
+
|
142
|
+
def find_tmpl(meth)
|
143
|
+
Function::DEFS.find{|x| x.kind_of?(Function) and meth == x.tmpl }
|
144
|
+
end
|
145
|
+
|
146
|
+
def cast_func
|
147
|
+
"numo_#{tp}_s_cast"
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
# ----------------------------------------------------------------------
|
152
|
+
|
153
|
+
class DataType < ErbPP
|
154
|
+
include DefMethod
|
155
|
+
|
156
|
+
def initialize(erb_path, type_file)
|
157
|
+
super(nil, erb_path)
|
158
|
+
@class_alias = []
|
159
|
+
@upcast = []
|
160
|
+
@mod_var = "cT"
|
161
|
+
@tmpl_dir = File.join(File.dirname(erb_path),"tmpl")
|
162
|
+
load_type(type_file) if type_file
|
163
|
+
end
|
164
|
+
|
165
|
+
attr_reader :tmpl_dir
|
166
|
+
|
167
|
+
def load_type(file)
|
168
|
+
eval File.read(file)
|
169
|
+
end
|
170
|
+
|
171
|
+
attrs = %w[
|
172
|
+
class_name
|
173
|
+
ctype
|
174
|
+
blas_char
|
175
|
+
complex_class_name
|
176
|
+
complex_type
|
177
|
+
real_class_name
|
178
|
+
real_ctype
|
179
|
+
has_math
|
180
|
+
is_bit
|
181
|
+
is_int
|
182
|
+
is_float
|
183
|
+
is_real
|
184
|
+
is_complex
|
185
|
+
is_object
|
186
|
+
is_comparable
|
187
|
+
mod_var
|
188
|
+
]
|
189
|
+
define_attrs attrs
|
190
|
+
|
191
|
+
def type_name
|
192
|
+
@type_name ||= class_name.downcase
|
193
|
+
end
|
194
|
+
alias tp type_name
|
195
|
+
|
196
|
+
def type_var
|
197
|
+
@type_var ||= "numo_c"+class_name
|
198
|
+
end
|
199
|
+
|
200
|
+
def math_var
|
201
|
+
@math_var ||= "numo_m"+class_name+"Math"
|
202
|
+
end
|
203
|
+
|
204
|
+
def real_class_name(arg=nil)
|
205
|
+
if arg.nil?
|
206
|
+
@real_class_name ||= class_name
|
207
|
+
else
|
208
|
+
@real_class_name = arg
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
def real_ctype(arg=nil)
|
213
|
+
if arg.nil?
|
214
|
+
@real_ctype ||= ctype
|
215
|
+
else
|
216
|
+
@real_ctype = arg
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
220
|
+
def real_type_var
|
221
|
+
@real_type_var ||= "numo_c"+real_class_name
|
222
|
+
end
|
223
|
+
|
224
|
+
def real_type_name
|
225
|
+
@real_type_name ||= real_class_name.downcase
|
226
|
+
end
|
227
|
+
|
228
|
+
def class_alias(*args)
|
229
|
+
@class_alias.concat(args)
|
230
|
+
end
|
231
|
+
|
232
|
+
def upcast(c=nil,t=nil)
|
233
|
+
if c
|
234
|
+
if t
|
235
|
+
t = "numo_c#{t}"
|
236
|
+
else
|
237
|
+
t = "cT"
|
238
|
+
end
|
239
|
+
@upcast << "rb_hash_aset(hCast, numo_c#{c}, #{t});"
|
240
|
+
else
|
241
|
+
@upcast
|
242
|
+
end
|
243
|
+
end
|
244
|
+
|
245
|
+
def upcast_rb(c,t=nil)
|
246
|
+
if t
|
247
|
+
t = "numo_c#{t}"
|
248
|
+
else
|
249
|
+
t = "cT"
|
250
|
+
end
|
251
|
+
if c=="Integer"
|
252
|
+
@upcast << "rb_hash_aset(hCast, rb_cFixnum, #{t});"
|
253
|
+
@upcast << "rb_hash_aset(hCast, rb_cBignum, #{t});"
|
254
|
+
else
|
255
|
+
@upcast << "rb_hash_aset(hCast, rb_c#{c}, #{t});"
|
256
|
+
end
|
257
|
+
end
|
258
|
+
end
|
259
|
+
|
260
|
+
|
261
|
+
# ----------------------------------------------------------------------
|
262
|
+
|
263
|
+
|
264
|
+
class Allocate < Function
|
265
|
+
def definition
|
266
|
+
"rb_define_alloc_func(#{mod_var}, #{c_func});"
|
267
|
+
end
|
268
|
+
end
|
269
|
+
|
270
|
+
# ----------------------------------------------------------------------
|
271
|
+
|
272
|
+
class Store < Function
|
273
|
+
DEFS = []
|
274
|
+
|
275
|
+
def initialize(parent,tmpl,tpname,dtype,tpclass,macro)
|
276
|
+
super(parent,tmpl)
|
277
|
+
@tpname=tpname
|
278
|
+
@dtype=dtype
|
279
|
+
@tpclass=tpclass
|
280
|
+
@macro=macro
|
281
|
+
DEFS.push(self)
|
282
|
+
end
|
283
|
+
attr_reader :tmpl, :tpname, :dtype, :tpclass, :macro
|
284
|
+
|
285
|
+
def c_func
|
286
|
+
"numo_#{tp}_store_#{tpname}"
|
287
|
+
end
|
288
|
+
|
289
|
+
def c_iter
|
290
|
+
"iter_#{tp}_store_#{tpname}"
|
291
|
+
end
|
292
|
+
|
293
|
+
def definition
|
294
|
+
nil
|
295
|
+
end
|
296
|
+
|
297
|
+
def condition
|
298
|
+
"rb_obj_is_kind_of(obj,#{tpclass})"
|
299
|
+
end
|
300
|
+
|
301
|
+
def self.definitions
|
302
|
+
a = []
|
303
|
+
DEFS.each do |i|
|
304
|
+
a.push(i) if i.condition
|
305
|
+
end
|
306
|
+
a
|
307
|
+
end
|
308
|
+
end
|
309
|
+
|
310
|
+
class StoreNum < Store
|
311
|
+
def initialize(parent,tmpl)
|
312
|
+
super(parent,tmpl,"numeric",nil,nil,nil)
|
313
|
+
end
|
314
|
+
|
315
|
+
def condition
|
316
|
+
"FIXNUM_P(obj) || TYPE(obj)==T_FLOAT || TYPE(obj)==T_BIGNUM || rb_obj_is_kind_of(obj,rb_cComplex)"
|
317
|
+
end
|
318
|
+
end
|
319
|
+
|
320
|
+
class StoreArray < Store
|
321
|
+
def initialize(parent,tmpl)
|
322
|
+
super(parent,tmpl,"array",nil,nil,nil)
|
323
|
+
end
|
324
|
+
|
325
|
+
def c_func
|
326
|
+
"numo_#{tp}_#{tmpl}"
|
327
|
+
end
|
328
|
+
|
329
|
+
def condition
|
330
|
+
"TYPE(obj)==T_ARRAY"
|
331
|
+
end
|
332
|
+
end
|
333
|
+
|
334
|
+
class CastArray < StoreArray
|
335
|
+
def condition
|
336
|
+
nil
|
337
|
+
end
|
338
|
+
end
|