class Tensorflow::Eager::TensorHandle
Attributes
context[R]
Public Class Methods
finalize(pointer)
click to toggle source
# File lib/tensorflow/eager/tensor_handle.rb, line 9 def self.finalize(pointer) proc do FFI.TFE_DeleteTensorHandle(pointer) end end
from_value(context, value, dtype: nil)
click to toggle source
# File lib/tensorflow/eager/tensor_handle.rb, line 15 def self.from_value(context, value, dtype: nil) case value when TensorHandle value when Data::Dataset value.variant_tensor when Tensor TensorHandle.new(context, value) when Variable value.value_handle else TensorHandle.new(context, Tensor.new(value, dtype: dtype)) end end
new(context, value)
click to toggle source
# File lib/tensorflow/eager/tensor_handle.rb, line 30 def initialize(context, value) @context = context case value when ::FFI::Pointer @pointer = value when Tensor Status.check do |status| @pointer = FFI.TFE_NewTensorHandle(value, status) end # We need to keep the tensor live so that it is not freed! @tensor = value else raise(Error::InvalidArgumentError, "Invalid value passed to tensor_handle: #{value}") end ObjectSpace.define_finalizer(self, self.class.finalize(@pointer)) end
Public Instance Methods
dtype()
click to toggle source
# File lib/tensorflow/eager/tensor_handle.rb, line 58 def dtype FFI.TFE_TensorHandleDataType(self) end
element_count()
click to toggle source
# File lib/tensorflow/eager/tensor_handle.rb, line 62 def element_count Status.check do |status| FFI.TFE_TensorHandleNumElements(self, status) end end
tensor()
click to toggle source
# File lib/tensorflow/eager/tensor_handle.rb, line 52 def tensor Status.check do |status| Tensor.from_pointer(FFI.TFE_TensorHandleResolve(self, status)) end end
to_ptr()
click to toggle source
# File lib/tensorflow/eager/tensor_handle.rb, line 48 def to_ptr @pointer end
value()
click to toggle source
# File lib/tensorflow/eager/tensor_handle.rb, line 68 def value self.tensor.value end
Private Instance Methods
dim(index)
click to toggle source
# File lib/tensorflow/eager/tensor_handle.rb, line 80 def dim(index) Status.check do |status| FFI.TFE_TensorHandleDim(self, index, status) end end
num_dims()
click to toggle source
# File lib/tensorflow/eager/tensor_handle.rb, line 74 def num_dims Status.check do |status| FFI.TFE_TensorHandleNumDims(self, status) end end