class DNN::Tensor

Attributes

data[R]

Public Class Methods

convert(inputs, link = nil) click to toggle source
# 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
new(data, link = nil) click to toggle source
# File lib/dnn/core/tensor.rb, line 16
def initialize(data, link = nil)
  @data = data
  @link = link
end

Public Instance Methods

*(other) click to toggle source
# 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) click to toggle source
# File lib/dnn/core/tensor.rb, line 57
def **(index)
  Layers::Pow.new(index).(self)
end
+(other) click to toggle source
# 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
+@() click to toggle source
# File lib/dnn/core/tensor.rb, line 29
def +@
  self
end
-(other) click to toggle source
# 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
-@() click to toggle source
# File lib/dnn/core/tensor.rb, line 33
def -@
  Neg.(self)
end
/(other) click to toggle source
# 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) click to toggle source
# File lib/dnn/core/tensor.rb, line 21
def >>(layer)
  layer.(self)
end
shape() click to toggle source
# File lib/dnn/core/tensor.rb, line 25
def shape
  @data.shape
end