Class: TensorStream::Graph

Inherits:
Object
  • Object
show all
Defined in:
lib/tensor_stream/graph.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeGraph

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

#collectionsObject

Returns the value of attribute collections.



3
4
5
# File 'lib/tensor_stream/graph.rb', line 3

def collections
  @collections
end

#eager_executionObject

Returns the value of attribute eager_execution.



3
4
5
# File 'lib/tensor_stream/graph.rb', line 3

def eager_execution
  @eager_execution
end

#nodesObject

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_defaultObject



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_graphObject



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, options = {})
  fail "duplicate variable detected #{node.name} and reuse=false in current scope" if @nodes[node.name] && !options[: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_executionObject



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

def disable_eager_execution
  @eager_execution = false
end

#enable_eager_executionObject



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

def enable_eager_execution
  @eager_execution = true
end

#executing_eagerly?Boolean

Returns:

  • (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, options = {})
  @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

Returns:

  • (Boolean)


49
50
51
# File 'lib/tensor_stream/graph.rb', line 49

def node_added?(name)
  @nodes.key?(name)
end

#resetObject



13
14
15
16
17
18
# File 'lib/tensor_stream/graph.rb', line 13

def reset
  @nodes = {}
  @collections = {
    :"#{GraphKeys::GLOBAL_VARIABLES}" => []
  }
end