Module: TensorStream::TensorMixins

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

Instance Method Summary collapse

Instance Method Details

#!=(other) ⇒ Object



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

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

#%(other) ⇒ Object



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

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

#*(other) ⇒ Object



11
12
13
# File 'lib/tensor_stream/helpers/tensor_mixins.rb', line 11

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

#**(other) ⇒ Object



15
16
17
# File 'lib/tensor_stream/helpers/tensor_mixins.rb', line 15

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



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

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

#-@Object



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

def -@
  _op(:negate, self)
end

#/(other) ⇒ Object



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

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

#<(other) ⇒ Object



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

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

#<=(other) ⇒ Object



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

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

#==(other) ⇒ Object



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

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

#>(other) ⇒ Object



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

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

#>=(other) ⇒ Object



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

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

#[](index) ⇒ Object



7
8
9
# File 'lib/tensor_stream/helpers/tensor_mixins.rb', line 7

def [](index)
  _op(:index, self, index)
end

#and(other) ⇒ Object



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

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

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



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

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

#ceil(name: nil) ⇒ Object



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

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

#dot(other) ⇒ Object



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

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

#floor(name: nil) ⇒ Object



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

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

#log(name: nil) ⇒ Object



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

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

#matmul(other) ⇒ Object



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

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



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/tensor_stream/helpers/tensor_mixins.rb', line 106

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



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

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

#round(name: nil) ⇒ Object



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

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

#var(name: nil) ⇒ Object



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

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

#zero?Boolean

Returns:

  • (Boolean)


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

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