Class: DNN::Tensor
- Inherits:
-
Object
- Object
- DNN::Tensor
- Defined in:
- lib/dnn/core/tensor.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#link ⇒ Object
Returns the value of attribute link.
Class Method Summary collapse
Instance Method Summary collapse
- #*(other) ⇒ Object
- #**(index) ⇒ Object
- #+(other) ⇒ Object
- #+@ ⇒ Object
- #-(other) ⇒ Object
- #-@ ⇒ Object
- #/(other) ⇒ Object
- #>>(layer) ⇒ Object
-
#initialize(data, link = nil) ⇒ Tensor
constructor
A new instance of Tensor.
- #shape ⇒ Object
Constructor Details
#initialize(data, link = nil) ⇒ Tensor
Returns a new instance of Tensor.
16 17 18 19 |
# File 'lib/dnn/core/tensor.rb', line 16 def initialize(data, link = nil) @data = data @link = link end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
3 4 5 |
# File 'lib/dnn/core/tensor.rb', line 3 def data @data end |
#link ⇒ Object
Returns the value of attribute link.
4 5 6 |
# File 'lib/dnn/core/tensor.rb', line 4 def link @link end |
Class Method Details
.convert(inputs, link = nil) ⇒ Object
6 7 8 9 10 11 12 13 14 |
# File 'lib/dnn/core/tensor.rb', line 6 def self.convert(inputs, link = nil) if inputs.is_a?(Array) inputs.map { |input| Tensor.new(input, link) } elsif inputs.is_a?(Integer) || inputs.is_a?(Float) Tensor.new(Xumo::SFloat[inputs], link) else Tensor.new(inputs, link) end end |
Instance Method Details
#*(other) ⇒ Object
47 48 49 50 |
# File 'lib/dnn/core/tensor.rb', line 47 def *(other) other = Tensor.convert(other) unless other.is_a?(DNN::Tensor) || other.is_a?(DNN::Param) Layers::Mul.(self, other) end |
#**(index) ⇒ Object
57 58 59 |
# File 'lib/dnn/core/tensor.rb', line 57 def **(index) Layers::Pow.new(index).(self) end |
#+(other) ⇒ Object
37 38 39 40 |
# File 'lib/dnn/core/tensor.rb', line 37 def +(other) other = Tensor.convert(other) unless other.is_a?(DNN::Tensor) || other.is_a?(DNN::Param) Layers::Add.(self, other) end |
#+@ ⇒ Object
29 30 31 |
# File 'lib/dnn/core/tensor.rb', line 29 def +@ self end |
#-(other) ⇒ Object
42 43 44 45 |
# File 'lib/dnn/core/tensor.rb', line 42 def -(other) other = Tensor.convert(other) unless other.is_a?(DNN::Tensor) || other.is_a?(DNN::Param) Layers::Sub.(self, other) end |
#-@ ⇒ Object
33 34 35 |
# File 'lib/dnn/core/tensor.rb', line 33 def -@ Neg.(self) end |
#/(other) ⇒ Object
52 53 54 55 |
# File 'lib/dnn/core/tensor.rb', line 52 def /(other) other = Tensor.convert(other) unless other.is_a?(DNN::Tensor) || other.is_a?(DNN::Param) Layers::Div.(self, other) end |
#>>(layer) ⇒ Object
21 22 23 |
# File 'lib/dnn/core/tensor.rb', line 21 def >>(layer) layer.(self) end |
#shape ⇒ Object
25 26 27 |
# File 'lib/dnn/core/tensor.rb', line 25 def shape @data.shape end |