Class: DNN::Layers::Sum
- Includes:
- LayerNode
- Defined in:
- lib/dnn/core/layers/math_layers.rb
Instance Attribute Summary collapse
-
#axis ⇒ Object
readonly
Returns the value of attribute axis.
-
#keepdims ⇒ Object
readonly
Returns the value of attribute keepdims.
Attributes inherited from Layer
Instance Method Summary collapse
- #backward_node(dy) ⇒ Object
- #forward_node(x) ⇒ Object
-
#initialize(axis: 0, keepdims: true) ⇒ Sum
constructor
A new instance of Sum.
- #load_hash(hash) ⇒ Object
- #to_hash ⇒ Object
Methods included from LayerNode
Methods inherited from Layer
#<<, #build, #built?, #call, call, #clean, #compute_output_shape, #forward, from_hash
Constructor Details
#initialize(axis: 0, keepdims: true) ⇒ Sum
Returns a new instance of Sum.
200 201 202 203 204 |
# File 'lib/dnn/core/layers/math_layers.rb', line 200 def initialize(axis: 0, keepdims: true) super() @axis = axis @keepdims = keepdims end |
Instance Attribute Details
#axis ⇒ Object (readonly)
Returns the value of attribute axis.
197 198 199 |
# File 'lib/dnn/core/layers/math_layers.rb', line 197 def axis @axis end |
#keepdims ⇒ Object (readonly)
Returns the value of attribute keepdims.
198 199 200 |
# File 'lib/dnn/core/layers/math_layers.rb', line 198 def keepdims @keepdims end |
Instance Method Details
#backward_node(dy) ⇒ Object
215 216 217 |
# File 'lib/dnn/core/layers/math_layers.rb', line 215 def backward_node(dy) MathUtils.broadcast_to(dy, @x_shape) end |
#forward_node(x) ⇒ Object
206 207 208 209 210 211 212 213 |
# File 'lib/dnn/core/layers/math_layers.rb', line 206 def forward_node(x) @x_shape = x.shape if @axis x.sum(axis: @axis, keepdims: true) else x.sum end end |
#load_hash(hash) ⇒ Object
223 224 225 |
# File 'lib/dnn/core/layers/math_layers.rb', line 223 def load_hash(hash) initialize(axis: hash[:axis], keepdims: hash[:keepdims]) end |
#to_hash ⇒ Object
219 220 221 |
# File 'lib/dnn/core/layers/math_layers.rb', line 219 def to_hash super(axis: @axis, keepdims: @keepdims) end |