class Tensorflow::Graph::Operation

Attributes

graph[R]

Public Class Methods

new(graph, pointer) click to toggle source
# File lib/tensorflow/graph/operation.rb, line 7
def initialize(graph, pointer)
  @graph = graph
  @pointer = pointer
end

Public Instance Methods

==(other) click to toggle source
# File lib/tensorflow/graph/operation.rb, line 20
def ==(other)
  self.name == other.name
end
[](index) click to toggle source
# File lib/tensorflow/graph/operation.rb, line 91
def [](index)
  self.outputs[index]
end
attr(attr_name) click to toggle source
# File lib/tensorflow/graph/operation.rb, line 138
def attr(attr_name)
  metadata = Status.check do |status|
    FFI.TF_OperationGetAttrMetadata(self, attr_name, status)
  end

  OperationAttr.new(self, attr_name, metadata)
end
attributes() click to toggle source
# File lib/tensorflow/graph/operation.rb, line 132
def attributes
  self.op_def.attr.map do |attr_def|
    self.attr(attr_def.name)
  end
end
consumers() click to toggle source
# File lib/tensorflow/graph/operation.rb, line 159
def consumers
  self.outputs.reduce(Array.new) do |result, output|
    result.concat(self.output_consumers(output))
    result
  end
end
control_inputs() click to toggle source
# File lib/tensorflow/graph/operation.rb, line 123
def control_inputs
  pointer = ::FFI::MemoryPointer.new(:pointer, self.num_control_inputs)
  FFI.TF_OperationGetControlInputs(self, pointer, self.num_control_inputs)
  self.num_control_inputs.times.map do |index|
    operation_ptr = pointer[index].read_pointer
    self.class.new(self.graph, operation_ptr)
  end
end
control_outputs() click to toggle source
# File lib/tensorflow/graph/operation.rb, line 72
def control_outputs
  pointer = ::FFI::MemoryPointer.new(:pointer, self.num_control_outputs)
  FFI.TF_OperationGetControlOutputs(self, pointer, self.num_control_outputs)
  self.num_control_outputs.times.map do |index|
    operation_ptr = pointer[index].read_pointer
    self.class.new(self.graph, operation_ptr)
  end
end
device() click to toggle source
# File lib/tensorflow/graph/operation.rb, line 40
def device
  FFI.TF_OperationDevice(self)
end
dtype() click to toggle source
# File lib/tensorflow/graph/operation.rb, line 109
def dtype
  self.output_types.first
end
eql?(other) click to toggle source
# File lib/tensorflow/graph/operation.rb, line 16
def eql?(other)
  self.name.eql?(other.name)
end
hash() click to toggle source
# File lib/tensorflow/graph/operation.rb, line 24
def hash
  self.name.hash
end
inputs() click to toggle source
# File lib/tensorflow/graph/operation.rb, line 60
def inputs
  pointer = ::FFI::MemoryPointer.new(FFI::Output, self.num_inputs)
  FFI.TF_OperationAllInputs(self, pointer, self.num_inputs)
  self.num_inputs.times.map do |index|
    OperationOutput.from_graph(self.graph, pointer[index])
  end
end
name() click to toggle source
# File lib/tensorflow/graph/operation.rb, line 28
def name
  FFI.TF_OperationName(self)
end
node_def() click to toggle source
# File lib/tensorflow/graph/operation.rb, line 44
def node_def
  buffer_ptr = FFI.TF_NewBuffer
  Status.check do |status|
    FFI.TF_OperationToNodeDef(self, buffer_ptr, status)
  end
  buffer = FFI::Buffer.new(buffer_ptr)
  string = buffer[:data].read_string(buffer[:length])
  NodeDef.decode(string)
ensure
  FFI.TF_DeleteBuffer(buffer)
end
num_control_inputs() click to toggle source
# File lib/tensorflow/graph/operation.rb, line 119
def num_control_inputs
  FFI.TF_OperationNumControlInputs(self)
end
num_control_outputs() click to toggle source
# File lib/tensorflow/graph/operation.rb, line 68
def num_control_outputs
  FFI.TF_OperationNumControlOutputs(self)
end
num_inputs() click to toggle source
# File lib/tensorflow/graph/operation.rb, line 56
def num_inputs
  FFI.TF_OperationNumInputs(self)
end
num_outputs() click to toggle source
# File lib/tensorflow/graph/operation.rb, line 81
def num_outputs
  FFI.TF_OperationNumOutputs(self)
end
op_def() click to toggle source
# File lib/tensorflow/graph/operation.rb, line 36
def op_def
  self.graph.op_def(self.op_type)
end
op_type() click to toggle source
# File lib/tensorflow/graph/operation.rb, line 32
def op_type
  FFI.TF_OperationOpType(self)
end
output_consumers(output) click to toggle source
# File lib/tensorflow/graph/operation.rb, line 146
def output_consumers(output)
  # How many consumers does this output have?
  count = FFI.TF_OperationOutputNumConsumers(output)

  # Get the consumers
  consumers_ptr = ::FFI::MemoryPointer.new(FFI::Input, count)
  FFI.TF_OperationOutputConsumers(output, consumers_ptr, count)

  count.times.map do |i|
    OperationOutput.from_graph(self.graph, consumers_ptr[i])
  end
end
output_list_length(arg_name) click to toggle source
# File lib/tensorflow/graph/operation.rb, line 113
def output_list_length(arg_name)
  Status.check do |status|
    FFI.TF_OperationOutputListLength(self, arg_name, status)
  end
end
output_shapes() click to toggle source
# File lib/tensorflow/graph/operation.rb, line 101
def output_shapes
  self.graph.output_shapes(self)
end
output_types() click to toggle source
# File lib/tensorflow/graph/operation.rb, line 95
def output_types
  self.outputs.map do |output|
    FFI.TF_OperationOutputType(output)
  end
end
outputs() click to toggle source
# File lib/tensorflow/graph/operation.rb, line 85
def outputs
  self.num_outputs.times.map do |i|
    OperationOutput.from_index(self, i)
  end
end
shape() click to toggle source
# File lib/tensorflow/graph/operation.rb, line 105
def shape
  self.output_shapes.first
end
to_ptr() click to toggle source
# File lib/tensorflow/graph/operation.rb, line 12
def to_ptr
  @pointer
end
to_s() click to toggle source
# File lib/tensorflow/graph/operation.rb, line 166
def to_s
  result = [self.op_type]
  result << "name=#{self.name}"
  outputs.length.times do |index|
    result << "#{index}:(shape=#{self.output_shapes[index]}, dtype=#{self.output_types[index]})"
  end
  result.join(', ')
end