class Tensorflow::Eager::Context
Public Class Methods
default()
click to toggle source
# File lib/tensorflow/eager/context.rb, line 7 def self.default @default ||= Context.new end
finalize(pointer)
click to toggle source
# File lib/tensorflow/eager/context.rb, line 11 def self.finalize(pointer) proc { FFI.TFE_DeleteContext(pointer) } end
new()
click to toggle source
# File lib/tensorflow/eager/context.rb, line 15 def initialize @name_scope = NameScope.new options = FFI.TFE_NewContextOptions Status.check do |status| @pointer = FFI.TFE_NewContext(options, status) end ObjectSpace.define_finalizer(self, self.class.finalize(@pointer)) FFI.TFE_DeleteContextOptions(options) end
Public Instance Methods
add_function(function)
click to toggle source
# File lib/tensorflow/eager/context.rb, line 100 def add_function(function) Status.check do |status| FFI.TFE_ContextAddFunction(self, function, status) end end
add_to_collection(name, value)
click to toggle source
Mimic graph api
# File lib/tensorflow/eager/context.rb, line 90 def add_to_collection(name, value) end
add_to_collections(names, value)
click to toggle source
Mimic graph api
# File lib/tensorflow/eager/context.rb, line 94 def add_to_collections(names, value) end
as_default() { |self| ... }
click to toggle source
# File lib/tensorflow/eager/context.rb, line 25 def as_default raise(Error::InvalidArgumentError, "Must provide block") unless block_given? ExecutionContext.push(self) begin yield self ensure ExecutionContext.pop end end
create_operation(op_type, inputs=[], attrs={})
click to toggle source
# File lib/tensorflow/eager/context.rb, line 35 def create_operation(op_type, inputs=[], attrs={}) Operation.new(self, op_type, inputs, attrs) end
device_policy()
click to toggle source
# File lib/tensorflow/eager/context.rb, line 60 def device_policy FFI::ContextDevicePlacementPolicy[FFI.TFE_ContextGetDevicePlacementPolicy(@pointer)] end
disable_run_metadata()
click to toggle source
# File lib/tensorflow/eager/context.rb, line 68 def disable_run_metadata FFI.TFE_ContextDisableRunMetadata(@pointer) end
enable_run_metadata()
click to toggle source
# File lib/tensorflow/eager/context.rb, line 64 def enable_run_metadata FFI.TFE_ContextEnableRunMetadata(@pointer) end
end_step()
click to toggle source
# File lib/tensorflow/eager/context.rb, line 76 def end_step FFI.TFE_ContextEndStep(@pointer) end
execute(operation)
click to toggle source
# File lib/tensorflow/eager/context.rb, line 39 def execute(operation) # TODO decide how many retvals to allocate retvals = ::FFI::MemoryPointer.new(:pointer, 10) num_retvals = ::FFI::MemoryPointer.new(:int) num_retvals.write_int(retvals.size) Status.check do |status| FFI.TFE_Execute(operation, retvals, num_retvals, status) end n = num_retvals.read_int if n > 0 handles = retvals.read_array_of_pointer(n).map do |handle| TensorHandle.new(self, handle) end # TODO handle case where n = 1 and still want an array for retvals n == 1 ? handles.first : handles end end
function?(function)
click to toggle source
# File lib/tensorflow/eager/context.rb, line 113 def function?(function) name = function.is_a?(Graph::Function) ? function.name : function # result is uchar FFI.TFE_ContextHasFunction(self, name) != 0 end
get_collection_ref(name)
click to toggle source
# File lib/tensorflow/eager/context.rb, line 97 def get_collection_ref(name) end
remove_function(function)
click to toggle source
# File lib/tensorflow/eager/context.rb, line 106 def remove_function(function) name = function.is_a?(Graph::Function) ? function.name : function Status.check do |status| FFI.TFE_ContextRemoveFunction(self, name, status) end end
start_step()
click to toggle source
# File lib/tensorflow/eager/context.rb, line 72 def start_step FFI.TFE_ContextStartStep(@pointer) end
to_ptr()
click to toggle source
# File lib/tensorflow/eager/context.rb, line 80 def to_ptr @pointer end