Class: DefLinalgFunction

Inherits:
DefModuleFunction show all
Defined in:
ext/numo/linalg/blas/gen/decl.rb

Instance Attribute Summary

Attributes inherited from ErbPP

#children, #parent

Instance Method Summary collapse

Methods inherited from DefModuleFunction

#init_def, #initialize

Methods inherited from DefMethod

#c_func, #c_iter, #c_name, #define_method_args, #id_op, #init_def, #initialize, #op_map, #singleton

Methods included from DeclMethod

#def_alias, #def_alloc_func, #def_const, #def_method, #def_module_function, #def_singleton_method, #undef_alloc_func, #undef_method, #undef_singleton_method

Methods inherited from ErbPP

#add_child, #find, #find_tmpl, #get, #init_def, #initialize, #load_erb, #method_missing, #method_missing_alias, #result, #run, #set, #write

Constructor Details

This class inherits a constructor from DefModuleFunction

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class ErbPP

Instance Method Details

#descriptionObject



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'ext/numo/linalg/blas/gen/decl.rb', line 80

def description
  indent = false
  lines = []
  h = get(:module_desc)[name]
  input = h && h['summary']
  if input.nil?
    puts "no description: #{name}"
    return ""
  end
  re_trim = /^(\s+)/=~input[0] ? /^#{$1}/ : nil
  input.each do |line|
    line.sub!(re_trim,"") if re_trim
    case line
    when /^\s*\d+\. /, /^\s*\(\d+\)/   # itemize
      lines << ""
      indent ||= ""
      line = indent+line
    when /^(\s+)/ #, /^(\s*)\w+\s*=/  # indent
      n_space = $1.size
      if !indent
        lines << ""
        indent = " " * [0,8-n_space].max
      end
      line = indent+line
    else  # standard
      if indent
        lines << ""
        indent = false
      end
    end
    if /^\s{8,}/ !~ line
      escape!(line)
    end
    lines << line
  end
  lines.join("\n")+"\n"
end

#escape!(s) ⇒ Object



58
59
60
61
62
# File 'ext/numo/linalg/blas/gen/decl.rb', line 58

def escape!(s)
  s.gsub!(/\*/,"\\*")
  s.gsub!(/_/,"\\_")
  s
end

#jobe(v) ⇒ Object



155
156
157
158
159
160
161
162
163
164
165
166
# File 'ext/numo/linalg/blas/gen/decl.rb', line 155

def jobe(v)
  tp = "String or Symbol"
  a =
    case v
    when /jobvl$/i; "left eigenvectors"
    when /jobvr$/i; "right eigenvectors"
    when /jobz$/i ; "eigenvectors"
    end
  if a
    return "@param #{v} [#{tp}]  if 'V': Compute #{a}, if 'N': Not compute #{a} (default='V')"
  end
end

#jobs(v) ⇒ Object



168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
# File 'ext/numo/linalg/blas/gen/decl.rb', line 168

def jobs(v)
  tp = "String or Symbol"
  a =
    case v
    when /jobu/
      "If 'A': all M columns of U are returned in array U, " +
        "If 'S': the first min(m,n) columns of U (the left " +
        "singular vectors) are returned in the array U, " +
        "If 'O': the first min(m,n) columns of U (the left " +
        "singular vectors) are overwritten on the array A, " +
        "If 'N': no columns of U (no left singular vectors) are computed."
    when /jobvt/
      "If 'A': all N rows of V\\*\\*T are returned in the array VT;" +
        "If 'S': the first min(m,n) rows of V\\*\\*T (the right singular" +
        " vectors) are returned in the array VT;" +
        "If 'O': the first min(m,n) rows of V\\*\\*T (the right singular" +
        " vectors) are overwritten on the array A;" +
        "If 'N': no rows of V\\*\\*T (no right singular vectors) are" +
        " computed."
    when /jobz/
      "If 'A':  all M columns of U and all N rows of V\\*\\*H are" +
        " returned in the arrays U and VT;" +
        " If 'S':  the first min(M,N) columns of U and the first" +
        " min(M,N) rows of V\\*\\*H are returned in the arrays U" +
        " and VT;" +
        "If 'O':  If M >= N, the first N columns of U are overwritten" +
        " in the array A and all rows of V\\*\\*H are returned in" +
        " the array VT;" +
        " otherwise, all columns of U are returned in the" +
        " array U and the first M rows of V\\*\\*H are overwritten" +
        " in the array A;" +
        "If 'N':  no columns of U or rows of V\\*\\*H are computed."
    end
  "@param #{v} [#{tp}]  #{a} (default='A')"
end

#mat(v, *a, **h) ⇒ Object



125
126
127
128
129
130
# File 'ext/numo/linalg/blas/gen/decl.rb', line 125

def mat(v,*a,**h)
  tp = h[:type] || class_name
  a.map!{|x| x==:inplace ? "inplace allowed" : x}
  a.unshift ">=2-dimentional NArray"
  "@param #{v} [#{tp}]  matrix (#{a.join(', ')})."
end

#opt(v, tp = nil, *a) ⇒ Object



132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'ext/numo/linalg/blas/gen/decl.rb', line 132

def opt(v,tp=nil,*a)
  tp ||= "String or Symbol"
  case v
  when /^order$/
    "@param #{v} [#{tp}]  if 'R': Row-major, if 'C': Column-major. (default='R')"
  when /^uplo$/
    "@param #{v} [#{tp}]  if 'U': Upper triangle, if 'L': Lower triangle. (default='U')"
  when /^side$/
    "@param #{v} [#{tp}]  if 'L': op(A)\\*B (left-side op), if 'R': B\\*op(A) (right-side op). (default='L')"
  when /^diag$/
    "@param #{v} [#{tp}]  if 'U': assumed to be unit triangular, if 'N': not assumed to be unit triangular. (default='U')"
  when /^trans(\w+)?$/
    b = a[0] || $1
    "@param #{v} [#{tp}]  if 'N': Not transpose #{b}, if 'T': Transpose #{b}. (default='N')"
  when "alpha"
    "@param #{v} [Float]  (default=1.0)"
  when "beta"
    "@param #{v} [Float]  (default=0.0)"
  else
    "@param #{v} [#{tp}]  #{a[0]}"
  end
end

#outparam(vars) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'ext/numo/linalg/blas/gen/decl.rb', line 64

def outparam(vars)
  m = get(:module_desc)[name]
  h = m && m['param']
  return "" if h.nil?
  result = [""]
  v = vars.split(/,\s*/)
  v.each do |var|
    if content = h[var.upcase]
      result << "    - **#{var}** -- "
      content[1..-1].each{|s| result << "  "+escape!(s)}
    end
    result << ""
  end
  result.join("\n")
end

#vec(v, *a, **h) ⇒ Object



118
119
120
121
122
123
# File 'ext/numo/linalg/blas/gen/decl.rb', line 118

def vec(v,*a,**h)
  tp = h[:type] || class_name
  a.map!{|x| x==:inplace ? "inplace allowed" : x}
  a.unshift ">=1-dimentional NArray"
  "@param #{v} [#{tp}]  vector (#{a.join(', ')})."
end