Home | History | Annotate | Download | only in op
      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 op defines functions for adding TensorFlow operations to a Graph.
     18 //
     19 // Functions for adding an operation to a graph take a Scope object as the
     20 // first argument. The Scope object encapsulates a graph and a set of
     21 // properties (such as a name prefix) for all operations being added
     22 // to the graph.
     23 //
     24 // WARNING: The API in this package has not been finalized and can
     25 // change without notice.
     26 package op
     27 
     28 import (
     29 	tf "github.com/tensorflow/tensorflow/tensorflow/go"
     30 )
     31 
     32 // Const adds an operation to graph that produces value as output.
     33 func Const(scope *Scope, value interface{}) (output tf.Output) {
     34 	if scope.Err() != nil {
     35 		return
     36 	}
     37 	t, ok := value.(*tf.Tensor)
     38 	if !ok {
     39 		var err error
     40 		if t, err = tf.NewTensor(value); err != nil {
     41 			scope.UpdateErr("Const", err)
     42 			return
     43 		}
     44 	}
     45 	return scope.AddOperation(tf.OpSpec{
     46 		Type: "Const",
     47 		Attrs: map[string]interface{}{
     48 			"dtype": t.DataType(),
     49 			"value": t,
     50 		}}).Output(0)
     51 }
     52