public void TensorCreation_Undressed()
        {
            //lock (Locks.ProcessWide)
            //    tf.Session(); //create one to increase next id to 1.

            MultiThreadedUnitTestExecuter.Run(8, Core);

            //the core method
            unsafe void Core(int tid)
            {
                using (var sess = tf.Session())
                {
                    Tensor t = null;
                    for (int i = 0; i < 100; i++)
                    {
                        var v = (int *)Marshal.AllocHGlobal(sizeof(int));
                        c_api.DeallocatorArgs _deallocatorArgs = new c_api.DeallocatorArgs();
                        var handle = c_api.TF_NewTensor(typeof(int).as_dtype(), dims: new long[0], num_dims: 0,
                                                        data: (IntPtr)v, len: (UIntPtr)sizeof(int),
                                                        deallocator: (IntPtr data, IntPtr size, ref c_api.DeallocatorArgs args) => Marshal.FreeHGlobal(data),
                                                        ref _deallocatorArgs);
                        c_api.TF_DeleteTensor(handle);
                    }
                }
            }
        }
        public void GraphCreation()
        {
            ops.uid(); //increment id by one

            MultiThreadedUnitTestExecuter.Run(8, Core);

            //the core method
            void Core(int tid)
            {
                tf.peak_default_graph().Should().BeNull();
                var beforehand = tf.get_default_graph(); //this should create default automatically.

                beforehand.graph_key.Should().NotContain("-0/", "Already created a graph in an other thread.");
                tf.peak_default_graph().Should().NotBeNull();

                using (var sess = tf.Session())
                {
                    var default_graph = tf.peak_default_graph();
                    var sess_graph    = sess.GetPrivate <Graph>("_graph");
                    sess_graph.Should().NotBeNull();
                    default_graph.Should().NotBeNull()
                    .And.BeEquivalentTo(sess_graph)
                    .And.BeEquivalentTo(beforehand);

                    Console.WriteLine($"{tid}-{default_graph.graph_key}");

                    //var result = sess.run(new object[] {g, a});
                    //var actualDeriv = result[0].GetData<float>()[0];
                    //var actual = result[1].GetData<float>()[0];
                }
            }
        }
        public void TF_GraphOperationByName_FromModel()
        {
            MultiThreadedUnitTestExecuter.Run(8, Core);

            //the core method
            void Core(int tid)
            {
                Console.WriteLine();
                for (int j = 0; j < 100; j++)
                {
                    var sess   = Session.LoadFromSavedModel(modelPath).as_default();
                    var inputs = new[] { "sp", "fuel" };

                    var inp  = inputs.Select(name => sess.graph.OperationByName(name).output).ToArray();
                    var outp = sess.graph.OperationByName("softmax_tensor").output;

                    for (var i = 0; i < 8; i++)
                    {
                        var        data  = new float[96];
                        FeedItem[] feeds = new FeedItem[2];

                        for (int f = 0; f < 2; f++)
                        {
                            feeds[f] = new FeedItem(inp[f], new NDArray(data));
                        }

                        sess.run(outp, feeds);
                    }
                }
            }
        }
        public void Marshal_AllocHGlobal()
        {
            MultiThreadedUnitTestExecuter.Run(8, Core);

            //the core method
            void Core(int tid)
            {
                for (int i = 0; i < 100; i++)
                {
                    Marshal.FreeHGlobal(Marshal.AllocHGlobal(sizeof(int)));
                }
            }
        }
        public void SessionRun_Initialization_OutsideSession()
        {
            MultiThreadedUnitTestExecuter.Run(8, Core);

            //the core method
            void Core(int tid)
            {
                tf.peak_default_graph().Should().BeNull();
                //graph is created automatically to perform create these operations
                var a1   = tf.constant(new[] { 2f }, shape: new[] { 1 });
                var a2   = tf.constant(new[] { 3f }, shape: new[] { 1 });
                var math = a1 + a2;
            }
        }
        public void TensorCreation()
        {
            MultiThreadedUnitTestExecuter.Run(8, Core);

            //the core method
            void Core(int tid)
            {
                using var sess = tf.Session();
                for (int i = 0; i < 100; i++)
                {
                    var t = new Tensor(1);
                }
            }
        }
        public void TensorCreation_Array()
        {
            MultiThreadedUnitTestExecuter.Run(8, Core);

            //the core method
            void Core(int tid)
            {
                //tf.Session created an other graph
                using var sess = tf.Session();
                for (int i = 0; i < 100; i++)
                {
                    var t = new Tensor(new int[] { 1, 2, 3 });
                }
            }
        }
        public void SessionRun_Initialization()
        {
            MultiThreadedUnitTestExecuter.Run(8, Core);

            //the core method
            void Core(int tid)
            {
                using var sess = tf.Session();
                Assert.IsNotNull(tf.get_default_graph());
                //graph is created automatically to perform create these operations
                var a1   = tf.constant(new[] { 2f }, shape: new[] { 1 });
                var a2   = tf.constant(new[] { 3f }, shape: new[] { 1 });
                var math = a1 + a2;
            }
        }
        public void TF_GraphOperationByName()
        {
            MultiThreadedUnitTestExecuter.Run(8, Core);

            //the core method
            void Core(int tid)
            {
                tf.peak_default_graph().Should().BeNull();
                //graph is created automatically to perform create these operations
                var a1   = tf.constant(new[] { 2f }, shape: new[] { 1 });
                var a2   = tf.constant(new[] { 3f }, shape: new[] { 1 }, name: "ConstantK");
                var math = a1 + a2;

                for (int i = 0; i < 100; i++)
                {
                    var op = tf.get_default_graph().OperationByName("ConstantK");
                }
            }
        }
        public void SessionRun_InsideSession()
        {
            MultiThreadedUnitTestExecuter.Run(8, Core);

            //the core method
            void Core(int tid)
            {
                using (var sess = tf.Session())
                {
                    tf.peak_default_graph().Should().NotBeNull();
                    //graph is created automatically to perform create these operations
                    var a1   = tf.constant(new[] { 2f }, shape: new[] { 1 });
                    var a2   = tf.constant(new[] { 3f }, shape: new[] { 1 });
                    var math = a1 + a2;

                    var result = sess.run(math);
                    result[0].GetAtIndex <float>(0).Should().Be(5);
                }
            }
        }
        public void TensorCreation()
        {
            //lock (Locks.ProcessWide)
            //    tf.Session(); //create one to increase next id to 1.

            MultiThreadedUnitTestExecuter.Run(8, Core);

            //the core method
            void Core(int tid)
            {
                using (var sess = tf.Session())
                {
                    Tensor t = null;
                    for (int i = 0; i < 100; i++)
                    {
                        t = new Tensor(1);
                    }
                }
            }
        }
        public void TensorCreation_Array()
        {
            //lock (Locks.ProcessWide)
            //    tf.Session(); //create one to increase next id to 1.

            MultiThreadedUnitTestExecuter.Run(8, Core);

            //the core method
            void Core(int tid)
            {
                //tf.Session created an other graph
                using (var sess = tf.Session())
                {
                    for (int i = 0; i < 100; i++)
                    {
                        var t = new Tensor(new int[] { 1, 2, 3 });
                    }
                }
            }
        }
        public void SessionCreation_x2()
        {
            ops.uid(); //increment id by one

            MultiThreadedUnitTestExecuter.Run(16, Core);

            //the core method
            void Core(int tid)
            {
                Assert.IsNull(tf.peak_default_graph());
                //tf.Session created an other graph
                using var sess = tf.Session();
                var default_graph = tf.get_default_graph();
                var sess_graph    = sess.graph;

                Assert.IsNotNull(default_graph);
                Assert.IsNotNull(sess_graph);
                Assert.AreEqual(default_graph, sess_graph);
            }
        }
        public void SessionCreation_x2()
        {
            ops.uid(); //increment id by one

            MultiThreadedUnitTestExecuter.Run(16, Core);

            //the core method
            void Core(int tid)
            {
                tf.peak_default_graph().Should().BeNull();
                //tf.Session created an other graph
                using (var sess = tf.Session())
                {
                    var default_graph = tf.peak_default_graph();
                    var sess_graph    = sess.GetPrivate <Graph>("_graph");
                    sess_graph.Should().NotBeNull();
                    default_graph.Should().NotBeNull()
                    .And.BeEquivalentTo(sess_graph);
                }
            }
        }
        public void SessionRun_InsideSession()
        {
            MultiThreadedUnitTestExecuter.Run(8, Core);

            //the core method
            void Core(int tid)
            {
                tf.compat.v1.disable_eager_execution();
                var graph = tf.Graph().as_default();

                using var sess = tf.Session(graph);
                Assert.IsNotNull(tf.get_default_graph());
                //graph is created automatically to perform create these operations
                var a1   = tf.constant(new[] { 2f }, shape: new[] { 1 });
                var a2   = tf.constant(new[] { 3f }, shape: new[] { 1 });
                var math = a1 + a2;

                var result = sess.run(math);

                Assert.AreEqual(result[0], 5f);
            }
        }
        public void TF_GraphOperationByName()
        {
            MultiThreadedUnitTestExecuter.Run(8, Core);

            //the core method
            void Core(int tid)
            {
                Assert.IsNull(tf.peak_default_graph());

                tf.compat.v1.disable_eager_execution();
                var graph = tf.Graph().as_default();

                //graph is created automatically to perform create these operations
                var a1   = tf.constant(new[] { 2f }, shape: new[] { 1 });
                var a2   = tf.constant(new[] { 3f }, shape: new[] { 1 }, name: "ConstantK");
                var math = a1 + a2;

                for (int i = 0; i < 100; i++)
                {
                    var op = tf.get_default_graph().OperationByName("ConstantK");
                }
            }
        }
        public void GraphCreation()
        {
            ops.uid(); //increment id by one

            MultiThreadedUnitTestExecuter.Run(8, Core);

            //the core method
            void Core(int tid)
            {
                Assert.IsNull(tf.peak_default_graph());
                var beforehand = tf.get_default_graph(); //this should create default automatically.

                beforehand.as_default();
                Assert.IsNotNull(tf.peak_default_graph());

                using var sess = tf.Session();
                var default_graph = tf.peak_default_graph();
                var sess_graph    = sess.graph;

                Assert.IsNotNull(default_graph);
                Assert.IsNotNull(sess_graph);
                Assert.AreEqual(default_graph, sess_graph);
            }
        }