Esempio n. 1
0
        void compMsg(int offset, SOAPService.Attribute a, AttrValue v)
        {
            if (IsCompare)
            {
                string s = a.Attr_Id + "=" +
                           fdb.ValueString(v.Value) + " " +
                           fdb.EditableStatusStr(v.Status);

                Error1(offset, s);
            }
        }
Esempio n. 2
0
        public void Graph()
        {
            var s     = new Status();
            var graph = new Graph();

            // Make a placeholder operation.
            var feed = c_test_util.Placeholder(graph, s);

            EXPECT_EQ("feed", feed.Name);
            EXPECT_EQ("Placeholder", feed.OpType);
            EXPECT_EQ("", feed.Device);
            EXPECT_EQ(1, feed.NumOutputs);
            EXPECT_EQ(TF_DataType.TF_INT32, feed.OutputType(0));
            EXPECT_EQ(1, feed.OutputListLength("output"));
            EXPECT_EQ(0, feed.NumInputs);
            EXPECT_EQ(0, feed.OutputNumConsumers(0));
            EXPECT_EQ(0, feed.NumControlInputs);
            EXPECT_EQ(0, feed.NumControlOutputs);

            AttrValue attr_value = null;

            ASSERT_TRUE(c_test_util.GetAttrValue(feed, "dtype", ref attr_value, s));
            EXPECT_EQ(attr_value.Type, DataType.DtInt32);

            // Test not found errors in TF_Operation*() query functions.
            EXPECT_EQ(-1, c_api.TF_OperationOutputListLength(feed, "bogus", s));
            EXPECT_EQ(TF_Code.TF_INVALID_ARGUMENT, s.Code);
            Assert.IsFalse(c_test_util.GetAttrValue(feed, "missing", ref attr_value, s));
            EXPECT_EQ("Operation 'feed' has no attr named 'missing'.", s.Message);

            // Make a constant oper with the scalar "3".
            var three = c_test_util.ScalarConst(3, graph, s);

            EXPECT_EQ(TF_Code.TF_OK, s.Code);

            // Add oper.
            var add = c_test_util.Add(feed, three, graph, s);

            EXPECT_EQ(TF_Code.TF_OK, s.Code);

            // Test TF_Operation*() query functions.
            EXPECT_EQ("add", add.Name);
            EXPECT_EQ("AddN", add.OpType);
            EXPECT_EQ("", add.Device);
            EXPECT_EQ(1, add.NumOutputs);
            EXPECT_EQ(TF_DataType.TF_INT32, add.OutputType(0));
            EXPECT_EQ(1, add.OutputListLength("sum"));
            EXPECT_EQ(TF_Code.TF_OK, s.Code);
            EXPECT_EQ(2, add.InputListLength("inputs"));
            EXPECT_EQ(TF_Code.TF_OK, s.Code);
            EXPECT_EQ(TF_DataType.TF_INT32, add.InputType(0));
            EXPECT_EQ(TF_DataType.TF_INT32, add.InputType(1));
            var add_in_0 = add.Input(0);

            EXPECT_EQ(feed, add_in_0.oper);
            EXPECT_EQ(0, add_in_0.index);
            var add_in_1 = add.Input(1);

            EXPECT_EQ(three, add_in_1.oper);
            EXPECT_EQ(0, add_in_1.index);
            EXPECT_EQ(0, add.OutputNumConsumers(0));
            EXPECT_EQ(0, add.NumControlInputs);
            EXPECT_EQ(0, add.NumControlOutputs);

            ASSERT_TRUE(c_test_util.GetAttrValue(add, "T", ref attr_value, s));
            EXPECT_EQ(DataType.DtInt32, attr_value.Type);
            ASSERT_TRUE(c_test_util.GetAttrValue(add, "N", ref attr_value, s));
            EXPECT_EQ(2, (int)attr_value.I);

            // Placeholder oper now has a consumer.
            EXPECT_EQ(1, feed.OutputNumConsumers(0));
            TF_Input[] feed_port = feed.OutputConsumers(0, 1);
            EXPECT_EQ(1, feed_port.Length);
            EXPECT_EQ(add, feed_port[0].oper);
            EXPECT_EQ(0, feed_port[0].index);

            // The scalar const oper also has a consumer.
            EXPECT_EQ(1, three.OutputNumConsumers(0));
            TF_Input[] three_port = three.OutputConsumers(0, 1);
            EXPECT_EQ(add, three_port[0].oper);
            EXPECT_EQ(1, three_port[0].index);

            // Serialize to GraphDef.
            var graph_def = c_test_util.GetGraphDef(graph);

            // Validate GraphDef is what we expect.
            bool found_placeholder  = false;
            bool found_scalar_const = false;
            bool found_add          = false;

            foreach (var n in graph_def.Node)
            {
                if (c_test_util.IsPlaceholder(n))
                {
                    Assert.IsFalse(found_placeholder);
                    found_placeholder = true;
                }
                else if (c_test_util.IsScalarConst(n, 3))
                {
                    Assert.IsFalse(found_scalar_const);
                    found_scalar_const = true;
                }
                else if (c_test_util.IsAddN(n, 2))
                {
                    Assert.IsFalse(found_add);
                    found_add = true;
                }
                else
                {
                    Assert.Fail($"Unexpected NodeDef: {n}");
                }
            }
            ASSERT_TRUE(found_placeholder);
            ASSERT_TRUE(found_scalar_const);
            ASSERT_TRUE(found_add);

            // Add another oper to the graph.
            var neg = c_test_util.Neg(add, graph, s);

            EXPECT_EQ(TF_Code.TF_OK, s.Code);

            // Serialize to NodeDef.
            var node_def = neg.GetNodeDef();

            // Validate NodeDef is what we expect.
            ASSERT_TRUE(c_test_util.IsNeg(node_def, "add"));

            // Serialize to GraphDef.
            var graph_def2 = c_test_util.GetGraphDef(graph);

            // Compare with first GraphDef + added NodeDef.
            graph_def.Node.Add(node_def);
            EXPECT_EQ(graph_def.ToString(), graph_def2.ToString());

            // Look up some nodes by name.
            Operation neg2 = c_api.TF_GraphOperationByName(graph, "neg");

            EXPECT_EQ(neg, neg2);
            var node_def2 = neg2.GetNodeDef();

            EXPECT_EQ(node_def.ToString(), node_def2.ToString());

            Operation feed2 = c_api.TF_GraphOperationByName(graph, "feed");

            EXPECT_EQ(feed, feed2);
            node_def  = feed.GetNodeDef();
            node_def2 = feed2.GetNodeDef();
            EXPECT_EQ(node_def.ToString(), node_def2.ToString());

            // Test iterating through the nodes of a graph.
            found_placeholder  = false;
            found_scalar_const = false;
            found_add          = false;
            bool      found_neg = false;
            uint      pos       = 0;
            Operation oper;

            while ((oper = c_api.TF_GraphNextOperation(graph, ref pos)) != IntPtr.Zero)
            {
                if (oper.Equals(feed))
                {
                    Assert.IsFalse(found_placeholder);
                    found_placeholder = true;
                }
                else if (oper.Equals(three))
                {
                    Assert.IsFalse(found_scalar_const);
                    found_scalar_const = true;
                }
                else if (oper.Equals(add))
                {
                    Assert.IsFalse(found_add);
                    found_add = true;
                }
                else if (oper.Equals(neg))
                {
                    Assert.IsFalse(found_neg);
                    found_neg = true;
                }
                else
                {
                    node_def = oper.GetNodeDef();
                    Assert.Fail($"Unexpected Node: {node_def.ToString()}");
                }
            }

            ASSERT_TRUE(found_placeholder);
            ASSERT_TRUE(found_scalar_const);
            ASSERT_TRUE(found_add);
            ASSERT_TRUE(found_neg);

            graph.Dispose();
            s.Dispose();
        }