Exemplo n.º 1
0
        /// <summary>
        /// For an op that takes `input_ops` as inputs, compute control inputs.
        /// </summary>
        /// <param name="input_ops">The data input ops for an op to be created.</param>
        /// <returns>A list of control inputs for the op to be created.</returns>
        private ITensorOrOperation[] _control_dependencies_for_inputs(ITensorOrOperation[] input_ops)
        {
            var ret = new ITensorOrOperation[0];

            foreach (var controller in _control_dependencies_stack)
            {
                bool dominated = false;
                // If any of the input_ops already depends on the inputs from controller,
                // we say that the new op is dominated (by that input), and we therefore
                // do not need to add control dependencies for this controller's inputs.
                foreach (var op in input_ops)
                {
                    if (controller.op_in_group(op))
                    {
                        dominated = true;
                        break;
                    }
                }

                if (!dominated)
                {
                    ret = controller.control_inputs.Where(x => !input_ops.Contains(x)).ToArray();
                }
            }

            return(ret);
        }
Exemplo n.º 2
0
 public void Autocast_Case0()
 {
     var sess = tf.Session().as_default();
     ITensorOrOperation operation = tf.global_variables_initializer();
     // the cast to ITensorOrOperation is essential for the test of this method signature
     var ret = sess.run(operation);
 }
Exemplo n.º 3
0
 /// <summary>
 /// Adds keys to a collection.
 /// </summary>
 /// <param name="val"The value to add per each key.></param>
 /// <param name="collections">A collection of keys to add.</param>
 /// <param name="default_collections">Used if collections is None.</param>
 public void collect(ITensorOrOperation val, List <string> collections, List <string> default_collections)
 {
     if (collections == null)
     {
         collections = default_collections;
     }
     foreach (var key in collections)
     {
         ops.add_to_collection(key, val);
     }
 }
        public _ElementFetchMapper(object[] fetches, Func <List <object>, object> contraction_fn)
        {
            var g = ops.get_default_graph();
            ITensorOrOperation el = null;

            foreach (var fetch in fetches)
            {
                el = g.as_graph_element(fetch, allow_tensor: true, allow_operation: true);
            }

            _unique_fetches.Add(el);
            _contraction_fn = contraction_fn;
        }
Exemplo n.º 5
0
 public static bool is_constant(ITensorOrOperation tensor_or_op)
 {
     if (tensor_or_op is Tensor tensor)
     {
         return(tensor.op.type == "Const");
     }
     else if (tensor_or_op is Operation op)
     {
         return(op.type == "Const");
     }
     else
     {
         throw new ValueError("is_constant");
     }
 }
Exemplo n.º 6
0
        public virtual NDArray run(ITensorOrOperation fetche, params FeedItem[] feed_dict)
        {
            var results = _run(fetche, feed_dict);

            return(fetche is Tensor ? results[0] : null);
        }
Exemplo n.º 7
0
 public bool op_in_group(ITensorOrOperation op)
 {
     return(_seen_nodes.Contains(op));
 }
Exemplo n.º 8
0
 public void add_op(ITensorOrOperation op)
 {
     _seen_nodes.Add(op);
 }
Exemplo n.º 9
0
 public virtual NDArray run(ITensorOrOperation fetche, params FeedItem[] feed_dict)
 {
     return(_run(fetche, feed_dict)[0]);
 }