Module: Torch::Native::Generator

Defined in:
lib/torch/native/generator.rb

Class Method Summary collapse

Class Method Details

.generate_cpp_functionsObject



10
11
12
13
14
15
# File 'lib/torch/native/generator.rb', line 10

def generate_cpp_functions
  functions = grouped_functions
  generate_cpp_file("torch", :define_singleton_method, functions[:torch])
  generate_cpp_file("tensor", :define_method, functions[:tensor])
  generate_cpp_file("nn", :define_singleton_method, functions[:nn])
end

.grouped_functionsObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/torch/native/generator.rb', line 17

def grouped_functions
  functions = functions()

  # skip functions
  skip_args = ["Layout", "Storage", "ConstQuantizerPtr"]

  # remove functions
  functions.reject! do |f|
    f.ruby_name.start_with?("_") ||
    f.ruby_name.include?("_backward") ||
    f.args.any? { |a| a[:type].include?("Dimname") }
  end

  # separate out into todo
  todo_functions, functions =
    functions.partition do |f|
      f.args.any? do |a|
        skip_args.any? { |sa| a[:type].include?(sa) } ||
        # call to 'range' is ambiguous
        f.cpp_name == "_range" ||
        # native_functions.yaml is missing size argument for normal
        # https://pytorch.org/cppdocs/api/function_namespacetorch_1a80253fe5a3ded4716ec929a348adb4b9.html
        (f.base_name == "normal" && !f.out?)
      end
    end

  # todo_functions.each do |f|
  #   puts f.func
  #   puts
  # end

  nn_functions, other_functions = functions.partition { |f| f.python_module == "nn" }
  torch_functions = other_functions.select { |f| f.variants.include?("function") }
  tensor_functions = other_functions.select { |f| f.variants.include?("method") }

  {torch: torch_functions, tensor: tensor_functions, nn: nn_functions}
end