Module: DefMethod

Included in:
DataType
Defined in:
lib/erbpp/narray_def.rb

Instance Method Summary collapse

Instance Method Details

#accum(meth, dtype, tpclass) ⇒ Object



81
82
83
84
# File 'lib/erbpp/narray_def.rb', line 81

def accum(meth, dtype, tpclass)
  h = {:dtype => dtype, :tpclass => tpclass}
  def_method(meth, -1, "accum", h)
end

#accum_binary(meth, ope = nil) ⇒ Object



94
95
96
97
# File 'lib/erbpp/narray_def.rb', line 94

def accum_binary(meth, ope=nil)
  ope = meth if ope.nil?
  def_method(meth, -1, "accum_binary", :op => ope)
end

#accum_index(meth) ⇒ Object



86
87
88
# File 'lib/erbpp/narray_def.rb', line 86

def accum_index(meth)
  def_method(meth, -1, "accum_index")
end

#binary(meth, ope = nil) ⇒ Object



29
30
31
32
# File 'lib/erbpp/narray_def.rb', line 29

def binary(meth, ope=nil)
  ope = meth if ope.nil?
  def_method(meth, 1, "binary", :op => ope)
end

#binary2(meth, ope = nil) ⇒ Object



34
35
36
37
# File 'lib/erbpp/narray_def.rb', line 34

def binary2(meth, ope=nil)
  ope = meth if ope.nil?
  def_method(meth, 1, "binary2", :op =>ope)
end

#bit_binary(meth, op = nil) ⇒ Object



65
66
67
68
69
# File 'lib/erbpp/narray_def.rb', line 65

def bit_binary(meth, op=nil)
  h = {:op=>op}
  h[:aliases] = [meth] if op
  def_method(meth, 1, "bit_binary", h)
end

#bit_count(meth) ⇒ Object



77
78
79
# File 'lib/erbpp/narray_def.rb', line 77

def bit_count(meth)
  def_method(meth, -1, "bit_count")
end

#bit_unary(meth, op = nil) ⇒ Object



71
72
73
74
75
# File 'lib/erbpp/narray_def.rb', line 71

def bit_unary(meth, op=nil)
  h = {:op=>op}
  h[:aliases] = [meth] if op
  def_method(meth, 0, "bit_unary", h)
end

#cast_arrayObject



126
127
128
# File 'lib/erbpp/narray_def.rb', line 126

def cast_array
  CastArray.new(self,"cast_array")
end

#cast_funcObject



146
147
148
# File 'lib/erbpp/narray_def.rb', line 146

def cast_func
  "numo_#{tp}_s_cast"
end

#cond_binary(meth, op = nil) ⇒ Object



57
58
59
# File 'lib/erbpp/narray_def.rb', line 57

def cond_binary(meth,op=nil)
  def_method(meth, 1, "cond_binary", :op => op)
end

#cond_unary(meth) ⇒ Object



61
62
63
# File 'lib/erbpp/narray_def.rb', line 61

def cond_unary(meth)
  def_method(meth, 0, "cond_unary")
end

#cum(meth, cmacro) ⇒ Object



90
91
92
# File 'lib/erbpp/narray_def.rb', line 90

def cum(meth, cmacro)
  def_method(meth, -1, "cum", cmacro:cmacro)
end

#def_alias(dst, src) ⇒ Object



20
21
22
# File 'lib/erbpp/narray_def.rb', line 20

def def_alias(dst, src)
  Alias.new(self, dst, src)
end

#def_allocate(tmpl) ⇒ Object



24
25
26
27
# File 'lib/erbpp/narray_def.rb', line 24

def def_allocate(tmpl)
  h = {:method => "allocate", :singleton => true}
  Allocate.new(self, tmpl, h)
end

#def_id(meth, var = nil) ⇒ Object



5
6
7
# File 'lib/erbpp/narray_def.rb', line 5

def def_id(meth,var=nil)
  IdVar.new(self, meth, var)
end

#def_method(meth, n_arg, tmpl = nil, opts = {}) ⇒ Object



9
10
11
12
13
14
# File 'lib/erbpp/narray_def.rb', line 9

def def_method(meth, n_arg, tmpl=nil, opts={})
  h = {:method => meth, :n_arg => n_arg}
  h.merge!(opts)
  tmpl ||= meth
  Function.new(self, tmpl, h)
end

#def_singleton(meth, n_arg, tmpl = nil, opts = {}) ⇒ Object



16
17
18
# File 'lib/erbpp/narray_def.rb', line 16

def def_singleton(meth, n_arg, tmpl=nil, opts={})
  def_method(meth, n_arg, tmpl, :singleton => true)
end

#find_method(meth) ⇒ Object



138
139
140
# File 'lib/erbpp/narray_def.rb', line 138

def find_method(meth)
  Function::DEFS.find{|x| x.kind_of?(Function) and meth == x.method }
end

#find_tmpl(meth) ⇒ Object



142
143
144
# File 'lib/erbpp/narray_def.rb', line 142

def find_tmpl(meth)
  Function::DEFS.find{|x| x.kind_of?(Function) and meth == x.tmpl }
end

#math(meth, n = 1) ⇒ Object



104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/erbpp/narray_def.rb', line 104

def math(meth, n=1)
  h = {:method => meth, :mod_var => 'mTM', :n_arg => n}
  case n
  when 1
    ModuleFunction.new(self, "unary_s", h)
  when 2
    ModuleFunction.new(self, "binary_s", h)
  when 3
    ModuleFunction.new(self, "ternary_s", h)
  else
    raise "invalid n=#{n}"
  end
end

#powObject



43
44
45
# File 'lib/erbpp/narray_def.rb', line 43

def pow
  def_method("pow", 1, "pow", :op => "**")
end

#qsort(tp, dtype, dcast) ⇒ Object



99
100
101
102
# File 'lib/erbpp/narray_def.rb', line 99

def qsort(tp, dtype, dcast)
  h = {:tp => tp, :dtype => dtype, :dcast => dcast}
  NodefFunction.new(self, "qsort", h)
end

#set2(meth, dtype, tpclass) ⇒ Object



52
53
54
55
# File 'lib/erbpp/narray_def.rb', line 52

def set2(meth, dtype, tpclass)
  h = {:dtype => dtype, :tpclass => tpclass}
  def_method(meth, 1, "set2", h)
end

#storeObject



134
135
136
# File 'lib/erbpp/narray_def.rb', line 134

def store
  Function.new(self,"store","store")
end

#store_arrayObject



122
123
124
# File 'lib/erbpp/narray_def.rb', line 122

def store_array
  StoreArray.new(self,"store_array")
end

#store_from(cname, dtype, macro) ⇒ Object



130
131
132
# File 'lib/erbpp/narray_def.rb', line 130

def store_from(cname,dtype,macro)
  Store.new(self,"store_from",cname.downcase,dtype,"numo_c"+cname,macro)
end

#store_numericObject



118
119
120
# File 'lib/erbpp/narray_def.rb', line 118

def store_numeric
  StoreNum.new(self,"store_numeric")
end

#unary(meth, ope = nil) ⇒ Object



39
40
41
# File 'lib/erbpp/narray_def.rb', line 39

def unary(meth, ope=nil)
  def_method(meth, 0, "unary", :op => ope)
end

#unary2(meth, dtype, tpclass) ⇒ Object



47
48
49
50
# File 'lib/erbpp/narray_def.rb', line 47

def unary2(meth, dtype, tpclass)
  h = {:dtype => dtype, :tpclass => tpclass}
  def_method(meth, 0, "unary2", h)
end