Class: Torch::NN::Module
- Inherits:
-
Object
show all
- Defined in:
- lib/torch/nn/module.rb
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
36
37
38
|
# File 'lib/torch/nn/module.rb', line 36
def method_missing(method, *args, &block)
modules[method.to_s] || super
end
|
Instance Method Details
#call(*input) ⇒ Object
13
14
15
|
# File 'lib/torch/nn/module.rb', line 13
def call(*input)
forward(*input)
end
|
#inspect ⇒ Object
4
5
6
7
8
9
10
11
|
# File 'lib/torch/nn/module.rb', line 4
def inspect
str = String.new
str << "#{self.class.name}(\n"
modules.each do |name, mod|
str << " (#{name}): #{mod.inspect}\n"
end
str << ")"
end
|
#parameters ⇒ Object
17
18
19
20
21
22
23
24
|
# File 'lib/torch/nn/module.rb', line 17
def parameters
params = []
instance_variables.each do |name|
param = instance_variable_get(name)
params << param if param.is_a?(Parameter)
end
params + modules.flat_map { |_, mod| mod.parameters }
end
|
#respond_to?(method, include_private = false) ⇒ Boolean
40
41
42
|
# File 'lib/torch/nn/module.rb', line 40
def respond_to?(method, include_private = false)
modules.key?(method.to_s) || super
end
|
#zero_grad ⇒ Object
26
27
28
29
30
31
32
33
34
|
# File 'lib/torch/nn/module.rb', line 26
def zero_grad
parameters.each do |param|
if param.grad
raise Error, "Not supported yet"
param.grad.detach!
param.grad.zero!
end
end
end
|