1 /* 2 Copyright 2016 The TensorFlow Authors. All Rights Reserved. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package tensorflow 18 19 func Placeholder(g *Graph, name string, dt DataType) (Output, error) { 20 op, err := g.AddOperation(OpSpec{ 21 Type: "Placeholder", 22 Name: name, 23 Attrs: map[string]interface{}{ 24 "dtype": dt, 25 }, 26 }) 27 return op.Output(0), err 28 } 29 30 func Const(g *Graph, name string, value interface{}) (Output, error) { 31 t, ok := value.(*Tensor) 32 if !ok { 33 var err error 34 if t, err = NewTensor(value); err != nil { 35 return Output{}, err 36 } 37 } 38 op, err := g.AddOperation(OpSpec{ 39 Type: "Const", 40 Name: name, 41 Attrs: map[string]interface{}{ 42 "dtype": t.DataType(), 43 "value": t, 44 }, 45 }) 46 return op.Output(0), err 47 } 48 49 func Neg(g *Graph, name string, port Output) (Output, error) { 50 op, err := g.AddOperation(OpSpec{ 51 Type: "Neg", 52 Name: name, 53 Input: []Input{port}, 54 }) 55 return op.Output(0), err 56 } 57 58 func Add(g *Graph, name string, x, y Output) (Output, error) { 59 op, err := g.AddOperation(OpSpec{ 60 Type: "Add", 61 Name: name, 62 Input: []Input{x, y}, 63 }) 64 return op.Output(0), err 65 } 66