Class: TensorStream::Graph
- Inherits:
-
Object
- Object
- TensorStream::Graph
- Defined in:
- lib/tensor_stream/graph.rb
Overview
A class that defines a TensorStream graph
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_const_counter ⇒ Object
- #get_node(name) ⇒ Object
- #get_operation_counter ⇒ Object
- #get_placeholder_counter ⇒ Object
- #get_var_counter ⇒ 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.
6 7 8 9 10 11 12 |
# File 'lib/tensor_stream/graph.rb', line 6 def initialize @eager_execution = false @nodes = {} @collections = { :"#{GraphKeys::GLOBAL_VARIABLES}" => [] } end |
Instance Attribute Details
#collections ⇒ Object
Returns the value of attribute collections.
4 5 6 |
# File 'lib/tensor_stream/graph.rb', line 4 def collections @collections end |
#eager_execution ⇒ Object
Returns the value of attribute eager_execution.
4 5 6 |
# File 'lib/tensor_stream/graph.rb', line 4 def eager_execution @eager_execution end |
#nodes ⇒ Object
Returns the value of attribute nodes.
4 5 6 |
# File 'lib/tensor_stream/graph.rb', line 4 def nodes @nodes end |
Class Method Details
.create_default ⇒ Object
25 26 27 |
# File 'lib/tensor_stream/graph.rb', line 25 def self.create_default Thread.current[:tensor_stream_current_graph] = TensorStream::Graph.new end |
.get_default_graph ⇒ Object
21 22 23 |
# File 'lib/tensor_stream/graph.rb', line 21 def self.get_default_graph Thread.current[:tensor_stream_current_graph] || create_default end |
Instance Method Details
#add_node(node) ⇒ Object
38 39 40 41 42 43 |
# File 'lib/tensor_stream/graph.rb', line 38 def add_node(node) raise 'Placeholder cannot be used when eager_execution is enabled' if @eager_execution && node.is_a?(Placeholder) node.name = uniqunify(node.name) if @nodes[node.name] @nodes[node.name] = node node.value = node.eval if @eager_execution end |
#add_node!(name, node) ⇒ Object
53 54 55 56 |
# File 'lib/tensor_stream/graph.rb', line 53 def add_node!(name, node) @nodes[name] = node node end |
#add_to_collection(collection_name, val) ⇒ Object
33 34 35 36 |
# File 'lib/tensor_stream/graph.rb', line 33 def add_to_collection(collection_name, val) @collections[collection_name.to_sym] ||= [] @collections[collection_name.to_sym] << val end |
#add_variable(node, options = {}) ⇒ Object
58 59 60 61 62 63 64 |
# File 'lib/tensor_stream/graph.rb', line 58 def add_variable(node, = {}) raise "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
66 67 68 |
# File 'lib/tensor_stream/graph.rb', line 66 def control_dependencies(_dependencies = [], &_block) raise 'not implemented' end |
#disable_eager_execution ⇒ Object
74 75 76 |
# File 'lib/tensor_stream/graph.rb', line 74 def disable_eager_execution @eager_execution = false end |
#enable_eager_execution ⇒ Object
70 71 72 |
# File 'lib/tensor_stream/graph.rb', line 70 def enable_eager_execution @eager_execution = true end |
#executing_eagerly? ⇒ Boolean
78 79 80 |
# File 'lib/tensor_stream/graph.rb', line 78 def executing_eagerly? @eager_execution end |
#get_collection(name, _options = {}) ⇒ Object
29 30 31 |
# File 'lib/tensor_stream/graph.rb', line 29 def get_collection(name, = {}) @collections[name.to_sym] end |
#get_const_counter ⇒ Object
108 109 110 111 112 113 114 115 |
# File 'lib/tensor_stream/graph.rb', line 108 def get_const_counter @const_counter ||= 0 name = @const_counter.zero? ? '' : "_#{@const_counter}" @const_counter += 1 name end |
#get_node(name) ⇒ Object
49 50 51 |
# File 'lib/tensor_stream/graph.rb', line 49 def get_node(name) @nodes[name] end |
#get_operation_counter ⇒ Object
82 83 84 85 86 87 88 89 90 |
# File 'lib/tensor_stream/graph.rb', line 82 def get_operation_counter @op_counter ||= 0 name = @op_counter.zero? ? '' : "_#{@op_counter}" @op_counter += 1 name end |
#get_placeholder_counter ⇒ Object
92 93 94 95 96 97 98 |
# File 'lib/tensor_stream/graph.rb', line 92 def get_placeholder_counter @placeholder_counter ||= 0 @placeholder_counter += 1 return '' if @placeholder_counter == 1 "_#{@placeholder_counter}" end |
#get_var_counter ⇒ Object
100 101 102 103 104 105 106 |
# File 'lib/tensor_stream/graph.rb', line 100 def get_var_counter @var_counter ||= 0 @var_counter += 1 return '' if @var_counter == 1 "_#{@var_counter}" end |
#node_added?(name) ⇒ Boolean
45 46 47 |
# File 'lib/tensor_stream/graph.rb', line 45 def node_added?(name) @nodes.key?(name) end |
#reset ⇒ Object
14 15 16 17 18 19 |
# File 'lib/tensor_stream/graph.rb', line 14 def reset @nodes = {} @collections = { :"#{GraphKeys::GLOBAL_VARIABLES}" => [] } end |