Class: Tensorflow::ExecutionContext
- Inherits:
-
Object
- Object
- Tensorflow::ExecutionContext
- Extended by:
- Forwardable
- Defined in:
- lib/tensorflow/execution_context.rb
Class Method Summary collapse
Instance Method Summary collapse
- #current(inputs = []) ⇒ Object
- #eager?(inputs = []) ⇒ Boolean
- #figure_from_context ⇒ Object
- #figure_from_execution_mode ⇒ Object
- #figure_from_inputs(inputs = []) ⇒ Object
- #graph?(inputs = []) ⇒ Boolean
-
#initialize ⇒ ExecutionContext
constructor
A new instance of ExecutionContext.
- #pop ⇒ Object
- #push(value) ⇒ Object
Constructor Details
#initialize ⇒ ExecutionContext
Returns a new instance of ExecutionContext.
12 13 14 |
# File 'lib/tensorflow/execution_context.rb', line 12 def initialize @stack = Array.new end |
Class Method Details
.context ⇒ Object
8 9 10 |
# File 'lib/tensorflow/execution_context.rb', line 8 def self.context Thread.current[:execution_context] ||= self.new end |
Instance Method Details
#current(inputs = []) ⇒ Object
48 49 50 |
# File 'lib/tensorflow/execution_context.rb', line 48 def current(inputs=[]) figure_from_context || figure_from_inputs(inputs) || figure_from_execution_mode end |
#eager?(inputs = []) ⇒ Boolean
52 53 54 55 |
# File 'lib/tensorflow/execution_context.rb', line 52 def eager?(inputs=[]) context = self.current(inputs) context.is_a?(Eager::Context) end |
#figure_from_context ⇒ Object
36 37 38 |
# File 'lib/tensorflow/execution_context.rb', line 36 def figure_from_context @stack.last end |
#figure_from_execution_mode ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/tensorflow/execution_context.rb', line 40 def figure_from_execution_mode if ::Tensorflow.execution_mode == Tensorflow::GRAPH_MODE Graph::Graph.default else Eager::Context.default end end |
#figure_from_inputs(inputs = []) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/tensorflow/execution_context.rb', line 24 def figure_from_inputs(inputs=[]) inputs.flatten.each do |input| case input when Graph::Operation return input.graph when Eager::TensorHandle return input.context end end nil end |
#graph?(inputs = []) ⇒ Boolean
57 58 59 60 |
# File 'lib/tensorflow/execution_context.rb', line 57 def graph?(inputs=[]) context = self.current(inputs) context.is_a?(Graph::Graph) end |
#pop ⇒ Object
20 21 22 |
# File 'lib/tensorflow/execution_context.rb', line 20 def pop @stack.pop end |
#push(value) ⇒ Object
16 17 18 |
# File 'lib/tensorflow/execution_context.rb', line 16 def push(value) @stack.push(value) end |