Class: Torch::NN::ParameterList
- Includes:
- Enumerable
- Defined in:
- lib/torch/nn/parameter_list.rb
Instance Attribute Summary
Attributes inherited from Module
Instance Method Summary collapse
- #[](idx) ⇒ Object
- #concat(parameters) ⇒ Object
- #each(&block) ⇒ Object
-
#initialize(parameters) ⇒ ParameterList
constructor
A new instance of ParameterList.
- #length ⇒ Object (also: #count, #size)
Methods inherited from Module
#_apply, #add_module, #apply, #buffers, #call, #children, #cpu, #cuda, #deep_dup, #double, #eval, #float, #forward, #half, #inspect, #load_state_dict, #method_missing, #modules, #named_buffers, #named_children, #named_modules, #named_parameters, #parameters, #register_buffer, #register_parameter, #requires_grad!, #respond_to?, #share_memory, #state_dict, #to, #train, #type, #zero_grad
Methods included from Utils
#_activation_fn, #_clones, #_ntuple, #_pair, #_quadrupal, #_single, #_triple
Constructor Details
#initialize(parameters) ⇒ ParameterList
Returns a new instance of ParameterList.
6 7 8 9 10 11 12 |
# File 'lib/torch/nn/parameter_list.rb', line 6 def initialize(parameters) super() @initialized = true unless parameters.nil? concat(parameters) end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Torch::NN::Module
Instance Method Details
#[](idx) ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/torch/nn/parameter_list.rb', line 39 def [](idx) if idx.is_a?(Range) self.class.new(@parameters.values[idx]) else @parameters[idx.to_s] end end |
#concat(parameters) ⇒ Object
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/torch/nn/parameter_list.rb', line 20 def concat(parameters) unless parameters.is_a?(Enumerable) raise TypeError, "ParameterList#concat should be called with an enumerable, but got #{parameters.class.name}" end offset = length parameters.each_with_index do |param, i| register_parameter((offset + i).to_s, param) end self end |
#each(&block) ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/torch/nn/parameter_list.rb', line 31 def each(&block) if block_given? @parameters.values.each(&block) else to_enum(:each) end end |
#length ⇒ Object Also known as: count, size
14 15 16 |
# File 'lib/torch/nn/parameter_list.rb', line 14 def length @parameters.length end |