Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/tensorflow.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'sciruby/Tensorflow'
require 'tensorflow/tensorflow_wrap'
require 'tensorflow/opspec'
require 'tensorflow/tensor'
require 'tensorflow/graph'
Expand Down
16 changes: 8 additions & 8 deletions lib/tensorflow/graph.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ class Tensorflow::Graph
# @!attribute c
# contains the graph representation.
def initialize
self.c = Tensorflow::TF_NewGraph()
self.c = TensorflowAPI::new_graph()
@number_of_defaults_created = Hash.new(0)
end

def delete_graph
Tensorflow::TF_DeleteGraph(c)
Tensorflow::delete_graph(c)
end

# write_to writes out a serialized representation of graph in binary wire format.
Expand Down Expand Up @@ -94,11 +94,11 @@ def AddOperation(opspec)
opspec.name = opspec.type if opspec.name == ''
cname = CString(opspec.name)
ctype = CString(opspec.type)
cdesc = Tensorflow::TF_NewOperation(c, ctype, cname)
cdesc = TensorflowAPI::new_operation(c, ctype, cname)

unless opspec.input.empty?
opspec.input.each do |name|
Tensorflow::TF_AddInput(cdesc, name.c)
Tensorflow::add_input(cdesc, name.c)
end
end

Expand All @@ -110,7 +110,7 @@ def AddOperation(opspec)
cdesc = Tensorflow.input_list_helper(cdesc, c_array, length)
end

status = Tensorflow::Status.new
status = TensorflowAPI::Status.new
opspec.attr.each do |name, value|
cdesc, status = set_attributes(cdesc, status, name, value)
# Memory leak here as the TF_OperationDescription
Expand All @@ -122,7 +122,7 @@ def AddOperation(opspec)
# consider adding a TF_DeleteOperationDescription
# function to the C API.
end
Tensorflow::Operation.new(Tensorflow::TF_FinishOperation(cdesc, status.c), self)
Tensorflow::Operation.new(Tensorflow::finish_operation(cdesc, status.c), self)
end

private
Expand Down Expand Up @@ -192,9 +192,9 @@ def set_attributes(cdesc, status, name, value)
end
Tensorflow::TF_SetAttrFloatList(cdesc, cAttrName, list, size)
when 'DataType'
Tensorflow::TF_SetAttrType(cdesc, cAttrName, value)
TensorflowAPI::set_attr_type(cdesc, cAttrName, value)
when 'Tensor'
Tensorflow::TF_SetAttrTensor(cdesc, cAttrName, value.tensor, status.c)
TensorflowAPI::set_attr_tensor(cdesc, cAttrName, value.tensor, status)
# TODO: Insert Tensor_list, DataType_list, Bool
else
raise 'Attribute type not supported or attribute type not specififed properly. Please look into the documentation for set_attributes in the graph class for more information.'
Expand Down
4 changes: 1 addition & 3 deletions lib/tensorflow/op.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,5 @@ def Placeholder(scope, dtype)

# A simple makeshift function to convert a ruby string to C++ string
def CString(string)
vector = Tensorflow::String_Vector.new
vector[0] = string
vector[0]
string
end
4 changes: 2 additions & 2 deletions lib/tensorflow/status.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
class Tensorflow::Status
attr_accessor :c
def initialize
self.c = Tensorflow::TF_NewStatus()
self.c = Tensorflow::new_status()
end

def newstatus
self.c = Tensorflow::TF_NewStatus()
self.c = Tensorflow::new_status()
end

def code
Expand Down
15 changes: 7 additions & 8 deletions lib/tensorflow/tensor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ def initialize(value, type = nil)
rank.zero? ? [1] : shape, Tensorflow::TF_INT64
)
if type_num == Tensorflow::TF_STRING
self.tensor = Tensorflow::String_encoder(CString(value), CString([0].pack("Q")) )
self.tensor = Tensorflow::String_encoder(value, [0].pack("Q"))
return self
end
self.tensor = Tensorflow::TF_NewTensor_wrapper(type_num,
dimension_data, rank, tensor_data, data_size * flatten.length)
self.tensor = TensorflowAPI.new_tensor(type_num,
dimension_data, rank, tensor_data, data_size * flatten.length, nil, nil)
end

#
Expand Down Expand Up @@ -148,12 +148,11 @@ def ruby_array_to_c(array, type)
c_array = Tensorflow::Int.new(array.length)
array.each_with_index { |value, i| c_array[i] = value }
when Tensorflow::TF_INT64
c_array = Tensorflow::Long_long.new(array.length)
array.each_with_index { |value, i| c_array[i] = value }
c_array = FFI::MemoryPointer.new(:long_long, array.size)
array.each_with_index { |value, i| c_array.put_long_long i, value }
when Tensorflow::TF_STRING
c_array = Tensorflow::String_Vector.new
array.each_with_index { |value, i| c_array[i] = value }
c_array = Tensorflow.string_array_from_string_vector(c_array)
c_array = FFI::MemoryPointer.new(:pointer, array.size)
array.each_with_index { |value, i| c_array.put_pointer i, FFI::MemoryPointer.from_string(value) }
else
c_array = Tensorflow::Complex_Vector.new
array.each_with_index { |value, i| c_array[i] = value }
Expand Down
Loading