Class: Torch::Native::Function
- Inherits:
-
Object
- Object
- Torch::Native::Function
- Defined in:
- lib/torch/native/function.rb
Instance Attribute Summary collapse
-
#function ⇒ Object
readonly
Returns the value of attribute function.
-
#tensor_options ⇒ Object
readonly
Returns the value of attribute tensor_options.
Instance Method Summary collapse
- #args ⇒ Object
- #base_name ⇒ Object
- #cpp_name ⇒ Object
- #func ⇒ Object
-
#initialize(function) ⇒ Function
constructor
A new instance of Function.
- #name ⇒ Object
- #out? ⇒ Boolean
- #out_size ⇒ Object
- #python_module ⇒ Object
- #ret_array? ⇒ Boolean
- #ret_size ⇒ Object
- #ruby_name ⇒ Object
- #variants ⇒ Object
Constructor Details
#initialize(function) ⇒ Function
Returns a new instance of Function.
6 7 8 9 10 11 12 |
# File 'lib/torch/native/function.rb', line 6 def initialize(function) @function = function = ", *, ScalarType? dtype=None, Layout? layout=None, Device? device=None, bool? pin_memory=None)" @tensor_options = @function["func"].include?() @function["func"].sub!(, ")") end |
Instance Attribute Details
#function ⇒ Object (readonly)
Returns the value of attribute function.
4 5 6 |
# File 'lib/torch/native/function.rb', line 4 def function @function end |
#tensor_options ⇒ Object (readonly)
Returns the value of attribute tensor_options.
4 5 6 |
# File 'lib/torch/native/function.rb', line 4 def @tensor_options end |
Instance Method Details
#args ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/torch/native/function.rb', line 30 def args @args ||= begin args = [] pos = true args_str = func.split("(", 2).last.split(") ->").first args_str.split(", ").each do |a| if a == "*" pos = false next end t, _, k = a.rpartition(" ") k, d = k.split("=") has_default = !d.nil? if d d = case d when "True" true when "False" false when "None" nil when /\A\-?\d+\z/ d.to_i when "[]" [] when "[0,1]" [0, 1] when /\A\de\-\d+\z/, /\A\d+\.\d+\z/ d.to_f when "Mean" "mean" when "contiguous_format" d when "long" :long else raise "Unknown default: #{d}" end end next if t == "Generator?" next if t == "MemoryFormat" next if t == "MemoryFormat?" args << {name: k, type: t, default: d, pos: pos, has_default: has_default} end args end end |
#base_name ⇒ Object
114 115 116 |
# File 'lib/torch/native/function.rb', line 114 def base_name @base_name ||= name.split(".").first end |
#cpp_name ⇒ Object
110 111 112 |
# File 'lib/torch/native/function.rb', line 110 def cpp_name @cpp_name ||= "_" + name.downcase.sub(".", "_") end |
#func ⇒ Object
14 15 16 |
# File 'lib/torch/native/function.rb', line 14 def func @func ||= @function["func"] end |
#name ⇒ Object
18 19 20 |
# File 'lib/torch/native/function.rb', line 18 def name @name ||= func.split("(", 2).first end |
#out? ⇒ Boolean
93 94 95 |
# File 'lib/torch/native/function.rb', line 93 def out? out_size > 0 && base_name[-1] != "_" end |
#out_size ⇒ Object
81 82 83 |
# File 'lib/torch/native/function.rb', line 81 def out_size @out_size ||= func.split("->").last.count("!") end |
#python_module ⇒ Object
22 23 24 |
# File 'lib/torch/native/function.rb', line 22 def python_module @python_module ||= @function["python_module"] end |
#ret_array? ⇒ Boolean
89 90 91 |
# File 'lib/torch/native/function.rb', line 89 def ret_array? @ret_array ||= func.split("->").last.include?('[]') end |
#ret_size ⇒ Object
85 86 87 |
# File 'lib/torch/native/function.rb', line 85 def ret_size @ret_size ||= func.split("->").last.split(", ").size end |
#ruby_name ⇒ Object
97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/torch/native/function.rb', line 97 def ruby_name @ruby_name ||= begin name = base_name if name.end_with?("_") "#{name[0..-2]}!" elsif name.start_with?("is_") "#{name[3..-1]}?" else name end end end |
#variants ⇒ Object
26 27 28 |
# File 'lib/torch/native/function.rb', line 26 def variants @variants ||= (@function["variants"] || "function").split(", ") end |