Class: TensorStream::Graph
- Inherits:
-
Object
- Object
- TensorStream::Graph
- Defined in:
- lib/tensor_stream/graph.rb
Instance Attribute Summary collapse
-
#collections ⇒ Object
Returns the value of attribute collections.
-
#eager_execution ⇒ Object
Returns the value of attribute eager_execution.
-
#nodes ⇒ Object
Returns the value of attribute nodes.
Class Method Summary collapse
Instance Method Summary collapse
- #add_node(node) ⇒ Object
- #add_node!(name, node) ⇒ Object
- #add_to_collection(collection_name, val) ⇒ Object
- #add_variable(node, options = {}) ⇒ Object
- #control_dependencies(dependencies = [], &block) ⇒ Object
- #disable_eager_execution ⇒ Object
- #enable_eager_execution ⇒ Object
- #executing_eagerly? ⇒ Boolean
- #get_collection(name, options = {}) ⇒ Object
- #get_node(name) ⇒ Object
-
#initialize ⇒ Graph
constructor
A new instance of Graph.
- #node_added?(name) ⇒ Boolean
- #reset ⇒ Object
Constructor Details
#initialize ⇒ Graph
Returns a new instance of Graph.
5 6 7 8 9 10 11 |
# File 'lib/tensor_stream/graph.rb', line 5 def initialize @eager_execution = false @nodes = {} @collections = { :"#{GraphKeys::GLOBAL_VARIABLES}" => [] } end |
Instance Attribute Details
#collections ⇒ Object
Returns the value of attribute collections.
3 4 5 |
# File 'lib/tensor_stream/graph.rb', line 3 def collections @collections end |
#eager_execution ⇒ Object
Returns the value of attribute eager_execution.
3 4 5 |
# File 'lib/tensor_stream/graph.rb', line 3 def eager_execution @eager_execution end |
#nodes ⇒ Object
Returns the value of attribute nodes.
3 4 5 |
# File 'lib/tensor_stream/graph.rb', line 3 def nodes @nodes end |
Class Method Details
.create_default ⇒ Object
24 25 26 |
# File 'lib/tensor_stream/graph.rb', line 24 def self.create_default Thread.current[:tensor_stream_current_graph] = TensorStream::Graph.new end |
.get_default_graph ⇒ Object
20 21 22 |
# File 'lib/tensor_stream/graph.rb', line 20 def self.get_default_graph Thread.current[:tensor_stream_current_graph] || create_default end |
Instance Method Details
#add_node(node) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/tensor_stream/graph.rb', line 37 def add_node(node) fail "Placeholder cannot be used when eager_execution is enabled" if @eager_execution && node.is_a?(Placeholder) if @nodes[node.name] node.name = uniqunify(node.name) end @nodes[node.name] = node if @eager_execution node.value = node.eval end end |
#add_node!(name, node) ⇒ Object
57 58 59 60 |
# File 'lib/tensor_stream/graph.rb', line 57 def add_node!(name, node) @nodes[name] = node node end |
#add_to_collection(collection_name, val) ⇒ Object
32 33 34 35 |
# File 'lib/tensor_stream/graph.rb', line 32 def add_to_collection(collection_name, val) @collections[collection_name.to_sym] ||= [] @collections[collection_name.to_sym] << val end |
#add_variable(node, options = {}) ⇒ Object
62 63 64 65 66 67 68 |
# File 'lib/tensor_stream/graph.rb', line 62 def add_variable(node, = {}) fail "duplicate variable detected #{node.name} and reuse=false in current scope" if @nodes[node.name] && ![:reuse] add_to_collection(GraphKeys::GLOBAL_VARIABLES, node) add_node(node) end |
#control_dependencies(dependencies = [], &block) ⇒ Object
70 71 72 |
# File 'lib/tensor_stream/graph.rb', line 70 def control_dependencies(dependencies = [], &block) end |
#disable_eager_execution ⇒ Object
78 79 80 |
# File 'lib/tensor_stream/graph.rb', line 78 def disable_eager_execution @eager_execution = false end |
#enable_eager_execution ⇒ Object
74 75 76 |
# File 'lib/tensor_stream/graph.rb', line 74 def enable_eager_execution @eager_execution = true end |
#executing_eagerly? ⇒ Boolean
82 83 84 |
# File 'lib/tensor_stream/graph.rb', line 82 def executing_eagerly? @eager_execution end |
#get_collection(name, options = {}) ⇒ Object
28 29 30 |
# File 'lib/tensor_stream/graph.rb', line 28 def get_collection(name, = {}) @collections[name.to_sym] end |
#get_node(name) ⇒ Object
53 54 55 |
# File 'lib/tensor_stream/graph.rb', line 53 def get_node(name) @nodes[name] end |
#node_added?(name) ⇒ Boolean
49 50 51 |
# File 'lib/tensor_stream/graph.rb', line 49 def node_added?(name) @nodes.key?(name) end |
#reset ⇒ Object
13 14 15 16 17 18 |
# File 'lib/tensor_stream/graph.rb', line 13 def reset @nodes = {} @collections = { :"#{GraphKeys::GLOBAL_VARIABLES}" => [] } end |