Class: Chainer::Initializers::Constant

Inherits:
Chainer::Initializer show all
Defined in:
lib/chainer/initializers/constant.rb

Instance Attribute Summary

Attributes inherited from Chainer::Initializer

#dtype

Instance Method Summary collapse

Constructor Details

#initialize(fill_value, dtype: nil) ⇒ Constant

Returns a new instance of Constant.



4
5
6
7
# File 'lib/chainer/initializers/constant.rb', line 4

def initialize(fill_value, dtype: nil)
  @fill_value = fill_value
  super(dtype: dtype)
end

Instance Method Details

#call(array) ⇒ Object



9
10
11
12
13
14
15
# File 'lib/chainer/initializers/constant.rb', line 9

def call(array)
  if @dtype
    raise ArgumentError unless array.class == @dtype
  end
  array.store(@fill_value)
  array
end