Module: TensorStream::TensorMixins

Included in:
Tensor
Defined in:
lib/tensor_stream/helpers/tensor_mixins.rb

Instance Method Summary collapse

Instance Method Details

#!=(other) ⇒ Object



77
78
79
# File 'lib/tensor_stream/helpers/tensor_mixins.rb', line 77

def !=(other)
  _op(:not_equal, self, TensorStream.convert_to_tensor(other, dtype: data_type))
end

#%(other) ⇒ Object



40
41
42
# File 'lib/tensor_stream/helpers/tensor_mixins.rb', line 40

def %(other)
  TensorStream.mod(self, other)
end

#*(other) ⇒ Object



20
21
22
# File 'lib/tensor_stream/helpers/tensor_mixins.rb', line 20

def *(other)
  _op(:mul, self, TensorStream.convert_to_tensor(other, dtype: data_type))
end

#**(other) ⇒ Object



24
25
26
# File 'lib/tensor_stream/helpers/tensor_mixins.rb', line 24

def **(other)
  _op(:pow, self, TensorStream.convert_to_tensor(other, dtype: data_type))
end

#+(other) ⇒ Object



3
4
5
# File 'lib/tensor_stream/helpers/tensor_mixins.rb', line 3

def +(other)
  _op(:add, self, TensorStream.convert_to_tensor(other, dtype: data_type))
end

#-(other) ⇒ Object



32
33
34
# File 'lib/tensor_stream/helpers/tensor_mixins.rb', line 32

def -(other)
  _op(:sub, self, TensorStream.convert_to_tensor(other, dtype: data_type))
end

#-@Object



36
37
38
# File 'lib/tensor_stream/helpers/tensor_mixins.rb', line 36

def -@
  _op(:negate, self)
end

#/(other) ⇒ Object



28
29
30
# File 'lib/tensor_stream/helpers/tensor_mixins.rb', line 28

def /(other)
  _op(:div, self, TensorStream.convert_to_tensor(other, dtype: data_type))
end

#<(other) ⇒ Object



73
74
75
# File 'lib/tensor_stream/helpers/tensor_mixins.rb', line 73

def <(other)
  _op(:less, self, TensorStream.convert_to_tensor(other, dtype: data_type))
end

#<=(other) ⇒ Object



89
90
91
# File 'lib/tensor_stream/helpers/tensor_mixins.rb', line 89

def <=(other)
  _op(:less_equal, self, TensorStream.convert_to_tensor(other, dtype: data_type))
end

#==(other) ⇒ Object



68
69
70
71
# File 'lib/tensor_stream/helpers/tensor_mixins.rb', line 68

def ==(other)
  TensorStream.check_data_types(self, other)
  _op(:equal, self, other)
end

#>(other) ⇒ Object



81
82
83
# File 'lib/tensor_stream/helpers/tensor_mixins.rb', line 81

def >(other)
  _op(:greater, self, TensorStream.convert_to_tensor(other, dtype: data_type))
end

#>=(other) ⇒ Object



85
86
87
# File 'lib/tensor_stream/helpers/tensor_mixins.rb', line 85

def >=(other)
  _op(:greater_equal, self, TensorStream.convert_to_tensor(other, dtype: data_type))
end

#[](index) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/tensor_stream/helpers/tensor_mixins.rb', line 7

def [](index)
  if index.is_a?(Range)
    last = if index.end.nil?
             [TensorStream.shape(self)[0]]
           else
             [index.max + 1]
           end
    _op(:strided_slice, self, [index.min], last, [1])
  else
    _op(:index, self, index)
  end
end

#and(other) ⇒ Object



93
94
95
# File 'lib/tensor_stream/helpers/tensor_mixins.rb', line 93

def and(other)
  _op(:logical_and, self, TensorStream.convert_to_tensor(other, dtype: data_type))
end

#cast(data_type = :float32, name: nil) ⇒ Object



105
106
107
# File 'lib/tensor_stream/helpers/tensor_mixins.rb', line 105

def cast(data_type = :float32, name: nil)
  TensorStream.cast(self, data_type, name: name)
end

#ceil(name: nil) ⇒ Object



48
49
50
# File 'lib/tensor_stream/helpers/tensor_mixins.rb', line 48

def ceil(name: nil)
  TensorStream.ceil(self, name: name)
end

#dot(other) ⇒ Object



101
102
103
# File 'lib/tensor_stream/helpers/tensor_mixins.rb', line 101

def dot(other)
  _op(:mat_mul, self, TensorStream.convert_to_tensor(other, dtype: data_type))
end

#floor(name: nil) ⇒ Object



44
45
46
# File 'lib/tensor_stream/helpers/tensor_mixins.rb', line 44

def floor(name: nil)
  TensorStream.floor(self, name: name)
end

#log(name: nil) ⇒ Object



56
57
58
# File 'lib/tensor_stream/helpers/tensor_mixins.rb', line 56

def log(name: nil)
  TensorStream.log(self, name: name)
end

#matmul(other) ⇒ Object



97
98
99
# File 'lib/tensor_stream/helpers/tensor_mixins.rb', line 97

def matmul(other)
  _op(:mat_mul, self, TensorStream.convert_to_tensor(other, dtype: data_type))
end

#reduce(op_type = :+, axis: nil, keepdims: false, name: nil) ⇒ Object

Apply a reduction to tensor



115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/tensor_stream/helpers/tensor_mixins.rb', line 115

def reduce(op_type = :+, axis: nil, keepdims: false, name: nil)
  reduce_op = case op_type.to_sym
              when :+
                :sum
              when :*
                :prod
              when :mean
                :mean
              else
                raise "unsupported reduce op type #{op_type} valid values are :+, :*, :prod, :mean"
  end
  raise "blocks are not supported for tensors" if block_given?

  TensorStream.reduce(reduce_op, self, axis, keepdims: keepdims, name: name)
end

#reshape(shape, name: nil) ⇒ Object



60
61
62
# File 'lib/tensor_stream/helpers/tensor_mixins.rb', line 60

def reshape(shape, name: nil)
  TensorStream.reshape(self, shape, name: name)
end

#round(name: nil) ⇒ Object



52
53
54
# File 'lib/tensor_stream/helpers/tensor_mixins.rb', line 52

def round(name: nil)
  TensorStream.round(self, name: name)
end

#var(name: nil) ⇒ Object



109
110
111
# File 'lib/tensor_stream/helpers/tensor_mixins.rb', line 109

def var(name: nil)
  TensorStream.variable(self, name: name)
end

#zero?Boolean

Returns:

  • (Boolean)


64
65
66
# File 'lib/tensor_stream/helpers/tensor_mixins.rb', line 64

def zero?
  _op(:equal, self, TensorStream.constant(0, dtype: data_type, name: "equal/is_zero?"))
end