Class: DNN::Tensor

Inherits:
Object
  • Object
show all
Defined in:
lib/dnn/core/tensor.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data, link = nil) ⇒ Tensor

Returns a new instance of Tensor.



14
15
16
17
# File 'lib/dnn/core/tensor.rb', line 14

def initialize(data, link = nil)
  @data = data
  @link = link
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



3
4
5
# File 'lib/dnn/core/tensor.rb', line 3

def data
  @data
end

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) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/dnn/core/tensor.rb', line 6

def self.convert(inputs)
  if inputs.is_a?(Array)
    inputs.map { |input| Tensor.new(input) }
  else
    Tensor.new(inputs)
  end
end

Instance Method Details

#*(other) ⇒ Object



39
40
41
# File 'lib/dnn/core/tensor.rb', line 39

def *(other)
  Layers::Mul.(self, other)
end

#**(index) ⇒ Object



47
48
49
# File 'lib/dnn/core/tensor.rb', line 47

def **(index)
  Layers::Pow.new(index).(self)
end

#+(other) ⇒ Object



31
32
33
# File 'lib/dnn/core/tensor.rb', line 31

def +(other)
  Layers::Add.(self, other)
end

#+@Object



23
24
25
# File 'lib/dnn/core/tensor.rb', line 23

def +@
  self
end

#-(other) ⇒ Object



35
36
37
# File 'lib/dnn/core/tensor.rb', line 35

def -(other)
  Layers::Sub.(self, other)
end

#-@Object



27
28
29
# File 'lib/dnn/core/tensor.rb', line 27

def -@
  self * -1
end

#/(other) ⇒ Object



43
44
45
# File 'lib/dnn/core/tensor.rb', line 43

def /(other)
  Layers::Div.(self, other)
end

#shapeObject



19
20
21
# File 'lib/dnn/core/tensor.rb', line 19

def shape
  @data.shape
end