forked from somaticio/tensorflow.rb
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
229916c
commit 3b00f69
Showing
12 changed files
with
171 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
|
||
; | ||
input1Placeholder* | ||
dtype0 * | ||
shape: | ||
; | ||
input2Placeholder* | ||
dtype0 * | ||
shape: | ||
& | ||
outputAddinput1input2* | ||
T0 |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Const adds an operation to graph that produces value as output. | ||
def Const(scope, value) | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# Scope encapsulates common operation properties when building a Graph. | ||
# | ||
# A Scope object (and its derivates, e.g., obtained from Scope.SubScope) | ||
# act as a builder for graphs. They allow common properties (such as | ||
# a name prefix) to be specified for multiple operations being added | ||
# to the graph. | ||
# | ||
# A Scope object and all its derivates (e.g., obtained from Scope.SubScope) | ||
# are not safe for concurrent use by multiple goroutines. | ||
class Tensorflow::Scope | ||
attr_accessor :graph, :namemap, :namespace | ||
def initialize | ||
graph = Tensorflow::Graph.new | ||
namemap = {} | ||
end | ||
|
||
# AddOperation adds the operation to the Graph managed by s. | ||
# | ||
# If there is a name prefix associated with s (such as if s was created | ||
# by a call to SubScope), then this prefix will be applied to the name | ||
# of the operation being added. See also Graph.AddOperation. | ||
def AddOperation(args) | ||
args.name = args.type if args.name == nil | ||
args.name = self.namespace + "/" + args.name if self.namespace == nil | ||
op = graph.AddOperation(args) | ||
end | ||
|
||
# SubScope returns a new Scope which will cause all operations added to the | ||
# graph to be namespaced with 'namespace'. If namespace collides with an | ||
# existing namespace within the scope, then a suffix will be added. | ||
def subscope(namespace) | ||
namespace = uniqueName(namespace) | ||
namespace = namespace + "/" + namespace if namespace!="" | ||
end | ||
|
||
def uniqueName(name) | ||
count = self.namemap[name] | ||
self.namemap[name]++ | ||
return name if count == 0 | ||
name = name + "_" + count | ||
return name | ||
end | ||
|
||
def opName(typ) | ||
self.namespace+"/"+typ | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
node { | ||
name: "tensor1" | ||
op: "Placeholder" | ||
attr { | ||
key: "_class" | ||
value { | ||
list { | ||
} | ||
} | ||
} | ||
attr { | ||
key: "dtype" | ||
value { | ||
type: DT_INT64 | ||
} | ||
} | ||
attr { | ||
key: "shape" | ||
value { | ||
shape { | ||
} | ||
} | ||
} | ||
} | ||
node { | ||
name: "tensor2" | ||
op: "Placeholder" | ||
attr { | ||
key: "_class" | ||
value { | ||
list { | ||
} | ||
} | ||
} | ||
attr { | ||
key: "dtype" | ||
value { | ||
type: DT_INT64 | ||
} | ||
} | ||
attr { | ||
key: "shape" | ||
value { | ||
shape { | ||
} | ||
} | ||
} | ||
} | ||
node { | ||
name: "Addition_of_tensors" | ||
op: "Add" | ||
input: "tensor1" | ||
input: "tensor2" | ||
attr { | ||
key: "T" | ||
value { | ||
type: DT_INT64 | ||
} | ||
} | ||
attr { | ||
key: "_class" | ||
value { | ||
list { | ||
} | ||
} | ||
} | ||
} | ||
versions { | ||
producer: 21 | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
require 'spec_helper' | ||
|
||
describe 'Scope' do | ||
it 'Should Test Sub Scope' do | ||
root = Tensorflow::Scope.new | ||
sub1 = root.subscope("x") | ||
sub2 = root.subscope("x") | ||
sub1a = sub1.subscope("y") | ||
sub2a = sub2.subscope("y") | ||
|
||
end | ||
end |