Module: TensorStream::TensorMixins

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

Instance Method Summary collapse

Instance Method Details

#!=(other) ⇒ Object



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

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

#%(other) ⇒ Object



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

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

#*(other) ⇒ Object



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

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

#**(other) ⇒ Object



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

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

#+(other) ⇒ Object



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

def +(other)
  TensorStream.check_data_types(self, other)
  _op(:add, self, other)
end

#-(other) ⇒ Object



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

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

#-@Object



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

def -@
  _op(:negate, self)
end

#/(other) ⇒ Object



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

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

#<(other) ⇒ Object



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

def <(other)
  TensorStream.check_data_types(self, other)
  _op(:less, self, other)
end

#<=(other) ⇒ Object



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

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

#==(other) ⇒ Object



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

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

#>(other) ⇒ Object



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

def >(other)
  TensorStream.check_data_types(self, other)
  _op(:greater, self, other)
end

#>=(other) ⇒ Object



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

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

#[](index) ⇒ Object



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

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

#and(other) ⇒ Object



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

def and(other)
  TensorStream.check_data_types(self, other)
  _op(:logical_and, self, other)
end

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



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

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

#ceil(name: nil) ⇒ Object



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

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

#dot(other) ⇒ Object



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

def dot(other)
  TensorStream.check_data_types(self, other)
  _op(:mat_mul, self, other)
end

#floor(name: nil) ⇒ Object



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

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

#log(name: nil) ⇒ Object



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

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

#matmul(other) ⇒ Object



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

def matmul(other)
  TensorStream.check_data_types(self, other)
  _op(:mat_mul, self, other)
end

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

Apply a reduction to tensor



119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/tensor_stream/helpers/tensor_mixins.rb', line 119

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



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

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

#round(name: nil) ⇒ Object



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

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

#var(name: nil) ⇒ Object



113
114
115
# File 'lib/tensor_stream/helpers/tensor_mixins.rb', line 113

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

#zero?Boolean

Returns:

  • (Boolean)


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

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