Class: Tensorflow::Output

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

Overview

Output represents one of the outputs of an operation in the graph. Has a DataType (and eventually a Shape). May be passed as an input argument to a function for adding operations to a graph, or to a Session’s Run() method to fetch that output as a tensor.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#indexObject

Index specifies the index of the output within the Operation. Operation is the Operation that produces this Output.



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

def index
  @index
end

#operationObject

Index specifies the index of the output within the Operation. Operation is the Operation that produces this Output.



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

def operation
  @operation
end

Instance Method Details

#cObject

Index specifies the index of the output within the Operation. Operation is the Operation that produces this Output.



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

def c
    Tensorflow.input(operation.c, index)
end

#dataTypeObject

DataType returns the type of elements in the tensor produced by p.



17
18
19
# File 'lib/tensorflow/operation.rb', line 17

def dataType
    Tensorflow::TF_OperationOutputType(c)
end

#shapeObject

Shape returns the (possibly incomplete) shape of the tensor produced p.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/tensorflow/operation.rb', line 22

def shape
    status = Tensorflow::Status.new
    port = c
    ndims = Tensorflow::TF_GraphGetTensorNumDims(operation.g.c, port, status.c)
    raise 'Operation improperly specified.' if status.code != 0
    # This should not be possible since an error only occurs if
    # the operation does not belong to the graph.  It should not
    # be possible to construct such an Operation object.
    return nil if ndims < 0
    return []  if ndims == 0
    c_array = Tensorflow::Long_long.new(ndims)
    Tensorflow::TF_GraphGetTensorShape(operation.g.c, port, c_array, ndims, status.c)
    dimension_array = []
    (0..ndims - 1).each do |i|
        dimension_array.push(c_array[i])
    end
    dimension_array
end