Rename Port to Output in the Go API.

Change: 131089292
This commit is contained in:
Jonathan Hseu 2016-08-23 12:29:10 -08:00 committed by TensorFlower Gardener
parent b73bad5a5a
commit 31e0b3bef5
3 changed files with 21 additions and 19 deletions

View File

@ -24,17 +24,19 @@ type Operation struct {
c *C.TF_Operation
}
// Port represents a specific input or output of an operation, e.g. to specify
// the specific output to pass as an input to a new op.
//
// Note the difference in naming convention: Port corresponds to Tensor/Output
// in the Python API.
type Port struct {
Op *Operation
// 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.
type Output struct {
// Op is the Operation that produces this Output.
Op *Operation
// Index specifies the index of the output within the Operation.
Index int
}
func (p *Port) c() C.TF_Port {
func (p *Output) c() C.TF_Port {
return C.TF_Port{oper: p.Op.c, index: C.int(p.Index)}
}
@ -67,7 +69,7 @@ func (b *opBuilder) SetAttrType(name string, typ DataType) {
C.free(unsafe.Pointer(attrName))
}
func (b *opBuilder) AddInput(port Port) {
func (b *opBuilder) AddInput(port Output) {
C.TF_AddInput(b.c, port.c())
}

View File

@ -66,7 +66,7 @@ func NewSession(graph *Graph, options *SessionOptions) (*Session, error) {
// On success, returns the Tensor outputs in the same order as supplied in
// the outputs argument. If outputs is set to nil, the returned Tensor outputs
// is empty.
func (s *Session) Run(inputs map[Port]*Tensor, outputs []Port, targets []*Operation) ([]*Tensor, error) {
func (s *Session) Run(inputs map[Output]*Tensor, outputs []Output, targets []*Operation) ([]*Tensor, error) {
s.mu.Lock()
if s.c == nil {
s.mu.Unlock()

View File

@ -19,27 +19,27 @@ import (
"testing"
)
func Placeholder(g *Graph, name string, dt DataType) (Port, error) {
func Placeholder(g *Graph, name string, dt DataType) (Output, error) {
b := newOpBuilder(g, "Placeholder", name)
b.SetAttrType("dtype", dt)
op, err := b.Build()
if err != nil {
return Port{}, err
return Output{}, err
}
return Port{op, 0}, nil
return Output{op, 0}, nil
}
func Neg(g *Graph, name string, port Port) (Port, error) {
func Neg(g *Graph, name string, port Output) (Output, error) {
b := newOpBuilder(g, "Neg", name)
b.AddInput(port)
op, err := b.Build()
if err != nil {
return Port{}, err
return Output{}, err
}
return Port{op, 0}, nil
return Output{op, 0}, nil
}
func createTestGraph(t *testing.T, dt DataType) (*Graph, Port, Port) {
func createTestGraph(t *testing.T, dt DataType) (*Graph, Output, Output) {
g := NewGraph()
inp, err := Placeholder(g, "p1", dt)
if err != nil {
@ -72,7 +72,7 @@ func TestSessionRunNeg(t *testing.T) {
if err != nil {
t.Fatalf("NewSession() for %v: %v", test.input, err)
}
output, err := s.Run(map[Port]*Tensor{inp: t1}, []Port{out}, []*Operation{out.Op})
output, err := s.Run(map[Output]*Tensor{inp: t1}, []Output{out}, []*Operation{out.Op})
if err != nil {
t.Fatalf("Run() for %v: %v", test.input, err)
}
@ -103,7 +103,7 @@ func TestConcurrency(t *testing.T) {
}
for i := 0; i < 100; i++ {
// Session may close before Run() starts, so we don't check the error.
go s.Run(map[Port]*Tensor{inp: tensor}, []Port{out}, []*Operation{out.Op})
go s.Run(map[Output]*Tensor{inp: tensor}, []Output{out}, []*Operation{out.Op})
}
if err = s.Close(); err != nil {
t.Errorf("Close() 1: %v", err)