Class: TensorFlow::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/tensorflow/context.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeContext

Returns a new instance of Context.



3
4
5
6
7
8
9
10
# File 'lib/tensorflow/context.rb', line 3

def initialize
  options = FFI.TFE_NewContextOptions
  @status = TensorFlow::FFI.TF_NewStatus
  @pointer = FFI.TFE_NewContext(options, @status)
  Utils.check_status @status
  ObjectSpace.define_finalizer(self, self.class.finalize(@pointer))
  FFI.TFE_DeleteContextOptions(options)
end

Class Method Details

.finalize(pointer) ⇒ Object



36
37
38
39
# File 'lib/tensorflow/context.rb', line 36

def self.finalize(pointer)
  # must use proc instead of stabby lambda
  proc { FFI.TFE_DeleteContext(pointer) }
end

Instance Method Details

#device_policyObject



16
17
18
# File 'lib/tensorflow/context.rb', line 16

def device_policy
  FFI::ContextDevicePlacementPolicy[FFI.TFE_ContextGetDevicePlacementPolicy(@pointer)]
end

#disable_run_metadataObject



24
25
26
# File 'lib/tensorflow/context.rb', line 24

def 
  FFI.(@pointer)
end

#enable_run_metadataObject



20
21
22
# File 'lib/tensorflow/context.rb', line 20

def 
  FFI.(@pointer)
end

#end_stepObject



32
33
34
# File 'lib/tensorflow/context.rb', line 32

def end_step
  FFI.TFE_ContextEndStep(@pointer)
end

#function?(name) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/tensorflow/context.rb', line 12

def function?(name)
  FFI.TFE_ContextHasFunction(@pointer, name) != 0
end

#shared_nameObject



45
46
47
48
# File 'lib/tensorflow/context.rb', line 45

def shared_name
  # hard-coded in Python library
  "cd2c89b7-88b7-44c8-ad83-06c2a9158347"
end

#start_stepObject



28
29
30
# File 'lib/tensorflow/context.rb', line 28

def start_step
  FFI.TFE_ContextStartStep(@pointer)
end

#to_ptrObject



41
42
43
# File 'lib/tensorflow/context.rb', line 41

def to_ptr
  @pointer
end