Module: TensorStream

Extended by:
OpHelper, Ops
Defined in:
lib/tensor_stream.rb,
lib/tensor_stream/ops.rb,
lib/tensor_stream/graph.rb,
lib/tensor_stream/types.rb,
lib/tensor_stream/tensor.rb,
lib/tensor_stream/session.rb,
lib/tensor_stream/trainer.rb,
lib/tensor_stream/version.rb,
lib/tensor_stream/variable.rb,
lib/tensor_stream/nn/nn_ops.rb,
lib/tensor_stream/operation.rb,
lib/tensor_stream/graph_keys.rb,
lib/tensor_stream/placeholder.rb,
lib/tensor_stream/train/saver.rb,
lib/tensor_stream/control_flow.rb,
lib/tensor_stream/tensor_shape.rb,
lib/tensor_stream/math_gradients.rb,
lib/tensor_stream/helpers/op_helper.rb,
lib/tensor_stream/evaluator/evaluator.rb,
lib/tensor_stream/evaluator/ruby_evaluator.rb,
lib/tensor_stream/train/gradient_descent_optimizer.rb

Defined Under Namespace

Modules: Evaluator, OpHelper, Ops, Train, Types Classes: ControlFlow, Graph, GraphKeys, MathGradients, NN, Operation, Placeholder, Session, Tensor, TensorShape, Variable

Constant Summary collapse

VERSION =
'0.1.1'

Constants included from Ops

Ops::FLOATING_POINT_TYPES, Ops::NUMERIC_TYPES

Class Method Summary collapse

Methods included from OpHelper

cons, dtype_eval, i_cons, i_op, op, shape_eval, val_to_dtype

Methods included from Ops

abs, add, argmax, cast, concat, cond, cos, equal, exp, eye, gradients, greater, greater_equal, identity, less, less_equal, log, matmul, max, multiply, negate, not_equal, ones, ones_like, pad, pow, print, random_normal, random_uniform, rank, reduce_mean, reduce_prod, reduce_sum, reshape, shape, sign, sin, slice, sqrt, square, stop_gradient, sub, tan, tanh, transpose, where, zeros, zeros_initializer, zeros_like

Class Method Details

.check_allowed_types(t, types) ⇒ Object



132
133
134
135
136
137
# File 'lib/tensor_stream.rb', line 132

def self.check_allowed_types(t, types)
  return t unless t.is_a?(Tensor)
  return t if t.data_type.nil?

  fail "Parameter data type #{t.data_type} passed not in #{types.join(',')}" if !types.map(&:to_sym).include?(t.data_type)
end

.constant(value, options = {}) ⇒ Object



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/tensor_stream.rb', line 83

def self.constant(value, options = {})
  shared_options = { const: true, value: value, name: options[:name] }
  if value.is_a?(Float)
    TensorStream::Tensor.new(options[:dtype] || :float32, 0, options[:shape] || [], shared_options)
  elsif value.is_a?(Integer)
    TensorStream::Tensor.new(options[:dtype] || :int32, 0, options[:shape] || [], shared_options)
  elsif value.is_a?(String)
    TensorStream::Tensor.new(options[:dtype] || :string, 0, options[:shape] || [], shared_options)
  elsif value.is_a?(Array)
    dtype = nil
    rank = 1
    dimensions = []
    value_ptr = value

    begin
      dtype, rank, value_ptr, d = dtype_eval(dtype, rank, value_ptr)
      dimensions << d
    end while dtype == :array

    TensorStream::Tensor.new(dtype, rank, options[:shape] || dimensions, shared_options)
  end
end

.disable_eager_executionObject



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

def self.disable_eager_execution
  TensorStream::Graph.get_default_graph.disable_eager_execution
end

.enable_eager_executionObject



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

def self.enable_eager_execution
  TensorStream::Graph.get_default_graph.enable_eager_execution
end

.executing_eagerly?Boolean

Returns:

  • (Boolean)


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

def self.executing_eagerly?
  TensorStream::Graph.get_default_graph.executing_eagerly?
end

.float32Object



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

def self.float32
  Types.float32
end

.get_collection(name, options = {}) ⇒ Object



114
115
116
# File 'lib/tensor_stream.rb', line 114

def self.get_collection(name, options = {})
  Graph.get_default_graph.get_collection(name, options)
end

.get_default_graphObject



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

def self.get_default_graph
  TensorStream::Graph.get_default_graph
end

.get_variable(name, options = {}) ⇒ Object



110
111
112
# File 'lib/tensor_stream.rb', line 110

def self.get_variable(name, options = {})
  TensorStream::Variable.new(options[:dtype] || :float32, nil, options[:shape], name: name, initializer: options[:initializer])
end

.global_variables_initializerObject



122
123
124
# File 'lib/tensor_stream.rb', line 122

def self.global_variables_initializer
  TensorStream::Variable.global_variables_initializer
end

.group(inputs) ⇒ Object



106
107
108
# File 'lib/tensor_stream.rb', line 106

def self.group(inputs)
  TensorStream::ControlFlow.new(:group, inputs)
end

.layersObject



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

def self.layers
  TensorStream::Layers
end

.nnObject

tensorflow compatibility



14
15
16
# File 'lib/tensor_stream/nn/nn_ops.rb', line 14

def self.nn
  TensorStream::NN
end

.placeholder(dtype, options = {}) ⇒ Object



118
119
120
# File 'lib/tensor_stream.rb', line 118

def self.placeholder(dtype, options = {})
  TensorStream::Placeholder.new(dtype, nil, options[:shape])
end

.program(&block) ⇒ Object



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

def self.program(&block)
  block.(self)
end

.reset_default_graphObject



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

def self.reset_default_graph
  TensorStream::Graph.get_default_graph.reset
end

.Session(evaluator = :ruby_evaluator, thread_pool_class: Concurrent::ImmediateExecutor) ⇒ Object



67
68
69
70
71
72
73
# File 'lib/tensor_stream.rb', line 67

def self.Session(evaluator = :ruby_evaluator, thread_pool_class: Concurrent::ImmediateExecutor)
  session = TensorStream::Session.new(evaluator, thread_pool_class: thread_pool_class)
  if block_given?
    yield session
  end
  session
end

.trainObject



126
127
128
# File 'lib/tensor_stream.rb', line 126

def self.train
  TensorStream::Trainer
end

.Variable(value, options = {}) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/tensor_stream.rb', line 51

def self.Variable(value, options = {})
  common_options= {
    initializer: Operation.new(:assign, nil, value),
    name: options[:name]
  }
  if value.is_a?(String)
    TensorStream::Variable.new(options[:dtype] || :string, 0, [], common_options)
  elsif value.is_a?(Integer)
    TensorStream::Variable.new(options[:dtype] || :int32, 0, [], common_options)
  elsif value.is_a?(Float)
    TensorStream::Variable.new(options[:dtype] || :float32, 0, [], common_options)
  else
    TensorStream::Variable.new(options[:dtype] || :float32, 0, nil, common_options)
  end
end

.versionObject



4
5
6
# File 'lib/tensor_stream/version.rb', line 4

def self.version
  VERSION
end