Class: RubyZero::NN::Parameters
- Inherits:
-
Object
- Object
- RubyZero::NN::Parameters
- Includes:
- Enumerable
- Defined in:
- lib/rubyzero/nn/parameters.rb
Instance Attribute Summary collapse
-
#elements ⇒ Object
Returns the value of attribute elements.
Class Method Summary collapse
Instance Method Summary collapse
- #<<(element) ⇒ Object
- #each(&block) ⇒ Object
-
#initialize(elems) ⇒ Parameters
constructor
A new instance of Parameters.
- #save(path) ⇒ Object
- #size ⇒ Object
- #to_marshal ⇒ Object
Constructor Details
#initialize(elems) ⇒ Parameters
Returns a new instance of Parameters.
4 5 6 |
# File 'lib/rubyzero/nn/parameters.rb', line 4 def initialize(elems) @elements = elems end |
Instance Attribute Details
#elements ⇒ Object
Returns the value of attribute elements.
3 4 5 |
# File 'lib/rubyzero/nn/parameters.rb', line 3 def elements @elements end |
Class Method Details
.from_marshal(marshal) ⇒ Object
23 24 25 |
# File 'lib/rubyzero/nn/parameters.rb', line 23 def self.from_marshal(marshal) return Parameters.new(Marshal.load(marshal).map{|d| RubyZero::Core::Tensor.new(d)}) end |
.load(path) ⇒ Object
31 32 33 |
# File 'lib/rubyzero/nn/parameters.rb', line 31 def self.load(path) return from_marshal(File.read(path)) end |
Instance Method Details
#<<(element) ⇒ Object
10 11 12 |
# File 'lib/rubyzero/nn/parameters.rb', line 10 def <<(element) @elements << element end |
#each(&block) ⇒ Object
7 8 9 |
# File 'lib/rubyzero/nn/parameters.rb', line 7 def each(&block) @elements.each(&block) end |
#save(path) ⇒ Object
26 27 28 29 30 |
# File 'lib/rubyzero/nn/parameters.rb', line 26 def save(path) File.open(path, 'wb') do |f| f.write(to_marshal) end end |
#size ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/rubyzero/nn/parameters.rb', line 13 def size sz = 0 @elements.each do |e| sz += e.shape.inject(:*) end return sz end |
#to_marshal ⇒ Object
20 21 22 |
# File 'lib/rubyzero/nn/parameters.rb', line 20 def to_marshal() return Marshal.dump(@elements.map{|e| e.data}) end |