Skip to content

Commit

Permalink
Adding Linter Changes to Specs.
Browse files Browse the repository at this point in the history
  • Loading branch information
arafatkatze committed Mar 4, 2017
1 parent 23c6833 commit 41dd55f
Show file tree
Hide file tree
Showing 8 changed files with 280 additions and 295 deletions.
Binary file added abc
Binary file not shown.
21 changes: 3 additions & 18 deletions spec/graph_spec.rb
@@ -1,8 +1,8 @@
require 'spec_helper'
describe 'Graph' do
it 'should feed two placeholders with inputs and add them' do
it 'should feed two placeholders with inputs and add them' do
graph = Tensorflow::Graph.new
tensor_1 = Tensorflow::Tensor.new([[ 1, 3, 5], [2, 4, 7]])
tensor_1 = Tensorflow::Tensor.new([[1, 3, 5], [2, 4, 7]])
tensor_2 = Tensorflow::Tensor.new([[-5, 1, 4], [8, 2, 3]])
placeholder_1 = graph.placeholder('tensor1', tensor_1.type_num)
placeholder_2 = graph.placeholder('tensor2', tensor_2.type_num)
Expand All @@ -16,20 +16,5 @@
hash[placeholder_2] = tensor_2
out_tensor = session.run(hash, [op.output(0)], [])
expect(out_tensor[0]).to match_array([[-4, 4, 9], [10, 6, 10]])
end


it 'Image recognition' do
graph = Tensorflow::Graph.new
graph.read_file(File.dirname(__FILE__)+'/imaage')
session_op = Tensorflow::Session_options.new
session = Tensorflow::Session.new(graph, session_op)
modeldir = ''
imagefile = File.dirname(__FILE__)+'/inception5h/mysore_palace.jpg'
input1 = Tensorflow::Tensor.new(imagefile, :string)
end
it 'Image recognition' do
graph = Tensorflow::Graph.new

end
end
end
230 changes: 114 additions & 116 deletions spec/math_spec.rb
Expand Up @@ -136,14 +136,14 @@
it 'Batched diagonal part of a batched tensor.' do
graph = Tensorflow::Graph.new
tensor_1 = Tensorflow::Tensor.new([[[1, 0, 0, 0],
[0, 2, 0, 0],
[0, 0, 3, 0],
[0, 0, 0, 4]],
[0, 2, 0, 0],
[0, 0, 3, 0],
[0, 0, 0, 4]],

[[5, 0, 0, 0],
[0, 6, 0, 0],
[0, 0, 7, 0],
[0, 0, 0, 8]]])
[[5, 0, 0, 0],
[0, 6, 0, 0],
[0, 0, 7, 0],
[0, 0, 0, 8]]])
placeholder_1 = graph.placeholder('tensor1', tensor_1.type_num)
opspec = Tensorflow::OpSpec.new('Diagonal_of_matrices', 'MatrixDiagPart', nil, [placeholder_1])
op = graph.AddOperation(opspec)
Expand All @@ -152,8 +152,7 @@
hash = { placeholder_1 => tensor_1 }
result = session.run(hash, [op.output(0)], [])
expect(result[0]).to all_be_close([[1.0, 2.0, 3.0, 4.0],
[5.0, 6.0, 7.0, 8.0]])

[5.0, 6.0, 7.0, 8.0]])
end

it 'Computes exponential of x element-wise' do
Expand All @@ -170,86 +169,86 @@
end

it 'Computes natural logarithm of x element-wise.' do
graph = Tensorflow::Graph.new
tensor_1 = Tensorflow::Tensor.new([[1.0, 3.0, 5.0]])
placeholder_1 = graph.placeholder('tensor1', tensor_1.type_num)
opspec = Tensorflow::OpSpec.new('elementwise_log', 'Log', nil, [placeholder_1])
op = graph.AddOperation(opspec)
session_op = Tensorflow::Session_options.new
session = Tensorflow::Session.new(graph, session_op)
hash = { placeholder_1 => tensor_1 }
result = session.run(hash, [op.output(0)], [])
expect(result[0]).to all_be_close([[0.0, 1.0986122886681098, 1.6094379124341003]])
graph = Tensorflow::Graph.new
tensor_1 = Tensorflow::Tensor.new([[1.0, 3.0, 5.0]])
placeholder_1 = graph.placeholder('tensor1', tensor_1.type_num)
opspec = Tensorflow::OpSpec.new('elementwise_log', 'Log', nil, [placeholder_1])
op = graph.AddOperation(opspec)
session_op = Tensorflow::Session_options.new
session = Tensorflow::Session.new(graph, session_op)
hash = { placeholder_1 => tensor_1 }
result = session.run(hash, [op.output(0)], [])
expect(result[0]).to all_be_close([[0.0, 1.0986122886681098, 1.6094379124341003]])
end

it 'Returns element-wise smallest integer in not less than x. (ceil function)' do
graph = Tensorflow::Graph.new
tensor_1 = Tensorflow::Tensor.new([[1.0, 3.1, 5.000001, 7]])
placeholder_1 = graph.placeholder('tensor1', tensor_1.type_num)
opspec = Tensorflow::OpSpec.new('Ceil', 'Ceil', nil, [placeholder_1])
op = graph.AddOperation(opspec)
session_op = Tensorflow::Session_options.new
session = Tensorflow::Session.new(graph, session_op)
hash = { placeholder_1 => tensor_1 }
result = session.run(hash, [op.output(0)], [])
expect(result[0]).to all_be_close([[1.0, 4.0, 6.0, 7.0]])
graph = Tensorflow::Graph.new
tensor_1 = Tensorflow::Tensor.new([[1.0, 3.1, 5.000001, 7]])
placeholder_1 = graph.placeholder('tensor1', tensor_1.type_num)
opspec = Tensorflow::OpSpec.new('Ceil', 'Ceil', nil, [placeholder_1])
op = graph.AddOperation(opspec)
session_op = Tensorflow::Session_options.new
session = Tensorflow::Session.new(graph, session_op)
hash = { placeholder_1 => tensor_1 }
result = session.run(hash, [op.output(0)], [])
expect(result[0]).to all_be_close([[1.0, 4.0, 6.0, 7.0]])
end

it 'Returns element-wise largest integer not greater than x. (floor function)' do
graph = Tensorflow::Graph.new
tensor_1 = Tensorflow::Tensor.new([[1.0, 3.1, 5.000001, 7]])
placeholder_1 = graph.placeholder('tensor1', tensor_1.type_num)
opspec = Tensorflow::OpSpec.new('floor', 'Floor', nil, [placeholder_1])
op = graph.AddOperation(opspec)
session_op = Tensorflow::Session_options.new
session = Tensorflow::Session.new(graph, session_op)
hash = { placeholder_1 => tensor_1 }
result = session.run(hash, [op.output(0)], [])
expect(result[0]).to all_be_close([[1.0, 3.0, 5.0, 7.0]])
graph = Tensorflow::Graph.new
tensor_1 = Tensorflow::Tensor.new([[1.0, 3.1, 5.000001, 7]])
placeholder_1 = graph.placeholder('tensor1', tensor_1.type_num)
opspec = Tensorflow::OpSpec.new('floor', 'Floor', nil, [placeholder_1])
op = graph.AddOperation(opspec)
session_op = Tensorflow::Session_options.new
session = Tensorflow::Session.new(graph, session_op)
hash = { placeholder_1 => tensor_1 }
result = session.run(hash, [op.output(0)], [])
expect(result[0]).to all_be_close([[1.0, 3.0, 5.0, 7.0]])
end

it 'Computes the Gauss error function of x element-wise.' do
graph = Tensorflow::Graph.new
tensor_1 = Tensorflow::Tensor.new([[-0.32, 1.0, 3.1, 5.000001, 7]])
placeholder_1 = graph.placeholder('tensor1', tensor_1.type_num)
opspec = Tensorflow::OpSpec.new('Error', 'Erf', nil, [placeholder_1])
op = graph.AddOperation(opspec)
session_op = Tensorflow::Session_options.new
session = Tensorflow::Session.new(graph, session_op)
hash = { placeholder_1 => tensor_1 }
result = session.run(hash, [op.output(0)], [])
expect(result[0]).to all_be_close([[-0.34912599479558276, 0.8427007929497149, 0.9999883513426328, 0.9999999999984626, 1.0]])
graph = Tensorflow::Graph.new
tensor_1 = Tensorflow::Tensor.new([[-0.32, 1.0, 3.1, 5.000001, 7]])
placeholder_1 = graph.placeholder('tensor1', tensor_1.type_num)
opspec = Tensorflow::OpSpec.new('Error', 'Erf', nil, [placeholder_1])
op = graph.AddOperation(opspec)
session_op = Tensorflow::Session_options.new
session = Tensorflow::Session.new(graph, session_op)
hash = { placeholder_1 => tensor_1 }
result = session.run(hash, [op.output(0)], [])
expect(result[0]).to all_be_close([[-0.34912599479558276, 0.8427007929497149, 0.9999883513426328, 0.9999999999984626, 1.0]])
end

it 'Returns MatrixInverse.' do
graph = Tensorflow::Graph.new
tensor_1 = Tensorflow::Tensor.new([[3, 3.5],
[3.2, 3.6]])
placeholder_1 = graph.placeholder('tensor1', tensor_1.type_num)
opspec = Tensorflow::OpSpec.new('MatrixInverse', 'MatrixInverse', nil, [placeholder_1])
op = graph.AddOperation(opspec)
session_op = Tensorflow::Session_options.new
session = Tensorflow::Session.new(graph, session_op)
hash = { placeholder_1 => tensor_1 }
result = session.run(hash, [op.output(0)], [])
expect(result[0]).to all_be_close([[-9.0, 8.75],
[8.0, -7.5]])
graph = Tensorflow::Graph.new
tensor_1 = Tensorflow::Tensor.new([[3, 3.5],
[3.2, 3.6]])
placeholder_1 = graph.placeholder('tensor1', tensor_1.type_num)
opspec = Tensorflow::OpSpec.new('MatrixInverse', 'MatrixInverse', nil, [placeholder_1])
op = graph.AddOperation(opspec)
session_op = Tensorflow::Session_options.new
session = Tensorflow::Session.new(graph, session_op)
hash = { placeholder_1 => tensor_1 }
result = session.run(hash, [op.output(0)], [])
expect(result[0]).to all_be_close([[-9.0, 8.75],
[8.0, -7.5]])
end

it 'Returns Solves a system of linear equations.' do
graph = Tensorflow::Graph.new
tensor_1 = Tensorflow::Tensor.new([[1.0, 1.0, -1],
[1, -2, 3],
[2, 3, 1]])
[1, -2, 3],
[2, 3, 1]])
tensor_2 = Tensorflow::Tensor.new([[4.0],
[-6.0],
[7]])
'''
Consider the equations
x + y - z = 4
x -2y +3z =-6
2x +3y + z = 7
'''
[-6.0],
[7]])
'''
Consider the equations
x + y - z = 4
x -2y +3z =-6
2x +3y + z = 7
'''
placeholder_1 = graph.placeholder('tensor1', tensor_1.type_num)
placeholder_2 = graph.placeholder('tensor2', tensor_2.type_num)
opspec = Tensorflow::OpSpec.new('MatrixSolve', 'MatrixSolve', nil, [placeholder_1, placeholder_2])
Expand All @@ -259,62 +258,61 @@
hash = { placeholder_1 => tensor_1, placeholder_2 => tensor_2 }
result = session.run(hash, [op.output(0)], [])
expect(result[0]).to all_be_close([[1.0],
[2.0],
[-0.9999999999999999]])
[2.0],
[-0.9999999999999999]])

'''
The solution of the equations is
x = 1
y = 2
z = -0.99 (almost -1)
'''
'''
The solution of the equations is
x = 1
y = 2
z = -0.99 (almost -1)
'''
end

it 'Square Tensor elements.' do
graph = Tensorflow::Graph.new
tensor_1 = Tensorflow::Tensor.new([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
placeholder_1 = graph.placeholder('tensor1', tensor_1.type_num)
opspec = Tensorflow::OpSpec.new('Square', 'Square', nil, [placeholder_1])
op = graph.AddOperation(opspec)
session_op = Tensorflow::Session_options.new
session = Tensorflow::Session.new(graph, session_op)
hash = { placeholder_1 => tensor_1 }
result = session.run(hash, [op.output(0)], [])
expect(result[0]).to all_be_close([[1.0, 4.0, 9.0], [16.0, 25.0, 36.0], [49.0, 64.0, 81.0]])
graph = Tensorflow::Graph.new
tensor_1 = Tensorflow::Tensor.new([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
placeholder_1 = graph.placeholder('tensor1', tensor_1.type_num)
opspec = Tensorflow::OpSpec.new('Square', 'Square', nil, [placeholder_1])
op = graph.AddOperation(opspec)
session_op = Tensorflow::Session_options.new
session = Tensorflow::Session.new(graph, session_op)
hash = { placeholder_1 => tensor_1 }
result = session.run(hash, [op.output(0)], [])
expect(result[0]).to all_be_close([[1.0, 4.0, 9.0], [16.0, 25.0, 36.0], [49.0, 64.0, 81.0]])
end

it 'Multiplies two matrices.' do
graph = Tensorflow::Graph.new
tensor_1 = Tensorflow::Tensor.new([[1.0, 2, 3],
[4, 5, 6]])
tensor_2 = Tensorflow::Tensor.new([[7.0, 8],
[9, 10],
[11, 12]])
placeholder_1 = graph.placeholder('tensor1', tensor_1.type_num)
placeholder_2 = graph.placeholder('tensor2', tensor_2.type_num)
opspec = Tensorflow::OpSpec.new('output', 'MatMul', nil, [placeholder_1, placeholder_2])
op = graph.AddOperation(opspec)
session_op = Tensorflow::Session_options.new
session = Tensorflow::Session.new(graph, session_op)
hash = { placeholder_1 => tensor_1, placeholder_2 => tensor_2 }
result = session.run(hash, [op.output(0)], [])
expect(result[0]).to all_be_close([[58.0, 64.0],
graph = Tensorflow::Graph.new
tensor_1 = Tensorflow::Tensor.new([[1.0, 2, 3],
[4, 5, 6]])
tensor_2 = Tensorflow::Tensor.new([[7.0, 8],
[9, 10],
[11, 12]])
placeholder_1 = graph.placeholder('tensor1', tensor_1.type_num)
placeholder_2 = graph.placeholder('tensor2', tensor_2.type_num)
opspec = Tensorflow::OpSpec.new('output', 'MatMul', nil, [placeholder_1, placeholder_2])
op = graph.AddOperation(opspec)
session_op = Tensorflow::Session_options.new
session = Tensorflow::Session.new(graph, session_op)
hash = { placeholder_1 => tensor_1, placeholder_2 => tensor_2 }
result = session.run(hash, [op.output(0)], [])
expect(result[0]).to all_be_close([[58.0, 64.0],
[139.0, 154.0]])

end

it 'Multiplies two matrices.' do
graph = Tensorflow::Graph.new
tensor_1 = Tensorflow::Tensor.new([[Complex(9, -2), Complex(0, 8)], [Complex(3, 7), Complex(5, 2)]])
tensor_2 = Tensorflow::Tensor.new([[Complex(-1, 7), Complex(6, 4)], [Complex(8, 9), Complex(1, 0)]])
placeholder_1 = graph.placeholder('tensor1', tensor_1.type_num)
placeholder_2 = graph.placeholder('tensor2', tensor_2.type_num)
opspec = Tensorflow::OpSpec.new('output', 'MatMul', nil, [placeholder_1, placeholder_2])
op = graph.AddOperation(opspec)
session_op = Tensorflow::Session_options.new
session = Tensorflow::Session.new(graph, session_op)
hash = { placeholder_1 => tensor_1, placeholder_2 => tensor_2 }
result = session.run(hash, [op.output(0)], [])
graph = Tensorflow::Graph.new
tensor_1 = Tensorflow::Tensor.new([[Complex(9, -2), Complex(0, 8)], [Complex(3, 7), Complex(5, 2)]])
tensor_2 = Tensorflow::Tensor.new([[Complex(-1, 7), Complex(6, 4)], [Complex(8, 9), Complex(1, 0)]])
placeholder_1 = graph.placeholder('tensor1', tensor_1.type_num)
placeholder_2 = graph.placeholder('tensor2', tensor_2.type_num)
opspec = Tensorflow::OpSpec.new('output', 'MatMul', nil, [placeholder_1, placeholder_2])
op = graph.AddOperation(opspec)
session_op = Tensorflow::Session_options.new
session = Tensorflow::Session.new(graph, session_op)
hash = { placeholder_1 => tensor_1, placeholder_2 => tensor_2 }
result = session.run(hash, [op.output(0)], [])
expect(result[0]).to match_array([[(-67.0 + 129.0i), (62.0 + 32.0i)], [(-30.0 + 75.0i), (-5.0 + 56.0i)]])
end
end
38 changes: 19 additions & 19 deletions spec/operation_spec.rb
@@ -1,39 +1,39 @@
require 'spec_helper'
describe 'Operation' do
it 'Should ensure that the Graph is not garbage collected while the program still has access to the Operation' do
it 'Should ensure that the Graph is not garbage collected while the program still has access to the Operation' do
graph = Tensorflow::Graph.new
tensor_1 = Tensorflow::Tensor.new([[ 1, 3, 5], [2, 4, 7]])
tensor_1 = Tensorflow::Tensor.new([[1, 3, 5], [2, 4, 7]])
placeholder_1 = graph.placeholder('tensor1', tensor_1.type_num)
expect(placeholder_1.operation.name).to match('tensor1')
expect(placeholder_1.operation.type).to match('Placeholder')
end
end

it 'Should Test Operation Output List Size' do
it 'Should Test Operation Output List Size' do
graph = Tensorflow::Graph.new
tensor_1 = Tensorflow::Tensor.new(1)
tensor_2 = Tensorflow::Tensor.new([[1,2], [3,4]])
const_1 = graph.const("const1", tensor_1)
const_2 = graph.const("const2", tensor_2)
tensor_2 = Tensorflow::Tensor.new([[1, 2], [3, 4]])
const_1 = graph.const('const1', tensor_1)
const_2 = graph.const('const2', tensor_2)
opspec = Tensorflow::OpSpec.new('Addition_of_tensors', 'ShapeN', nil, nil, [const_1, const_2])
op = graph.AddOperation(opspec)
n = op.output_list_size("output")
n = op.output_list_size('output')
expect(n).to match(2)
expect(op.num_outputs).to match(2)
end
end

#TODO: If and when the API to get attributes is added add a test to check it.
# TODO: If and when the API to get attributes is added add a test to check it.
it 'Should Test Operation DataType' do
graph = Tensorflow::Graph.new
tensor_1 = Tensorflow::Tensor.new(1)
const_1 = graph.const("const1", tensor_1)
expect(const_1.dataType).to match(9) # TF_INT64 => 9
graph = Tensorflow::Graph.new
tensor_1 = Tensorflow::Tensor.new(1)
const_1 = graph.const('const1', tensor_1)
expect(const_1.dataType).to match(9) # TF_INT64 => 9
end

it 'Should Test Operation DataType' do
graph = Tensorflow::Graph.new
tensor_1 = Tensorflow::Tensor.new(1.232)
const_1 = graph.const("const1", tensor_1)
expect(const_1.dataType).to match(2) # TF_DOUBLE => 2
graph = Tensorflow::Graph.new
tensor_1 = Tensorflow::Tensor.new(1.232)
const_1 = graph.const('const1', tensor_1)
expect(const_1.dataType).to match(2) # TF_DOUBLE => 2
end
#TODO: Add Shape method and tests.
# TODO: Add Shape method and tests.
end
12 changes: 6 additions & 6 deletions spec/saved_model_spec.rb
@@ -1,9 +1,9 @@
require 'spec_helper'
# TODO: Check std::pair in savedmodel.
describe "Savedmodel" do
it "Load Saved model" do
bundle = Tensorflow::Savedmodel.new()
bundle.LoadSavedModel(File.dirname(__FILE__)+'/testdata/half_plus_two/00000123',["serve"], nil)
bundle.graph.operation('y')
end
describe 'Savedmodel' do
it 'Load Saved model' do
bundle = Tensorflow::Savedmodel.new
bundle.LoadSavedModel(File.dirname(__FILE__) + '/testdata/half_plus_two/00000123', ['serve'], nil)
bundle.graph.operation('y')
end
end

0 comments on commit 41dd55f

Please sign in to comment.