예제 #1
0
        public static unsafe void bb6()
        {
            Variable v = new Variable(new Dimension[] { 6 }, new Shape(3));

            DynamicRecurrent r = new DynamicRecurrent(v.OuterDimensions, v.InnerDimensions, new[] { v },
                                                      (Layer me, List <Layer> x, Index t) =>
            {
                if (t[0] % 2 == 1)
                {
                    return(new Terms.Add(x[0].GetTerm(t), me.GetTerm(t - 1)));
                }
                else
                {
                    return(x[0].GetTerm(t));
                }
            });

            r.PreCheck();


            Index a = new Index(r.OuterShape);

            a.SetZero();

            for (int i = 0; i < r.OuterShape.TotalSize; i++, a.Increase(1))
            {
                Console.WriteLine(r.GetTerm(a).GetResult());
            }
        }
예제 #2
0
        public virtual unsafe void Minimize()
        {
            DeleteTerms();

            PreCheck();

            Index a = new Index(OuterShape);

            a.SetZero();

            for (int i = 0; i < OuterShape.TotalSize; i++, a.Increase(1))
            {
                GetTerm(a);
            }

            if (Terms.Count > 1)
            {
                Terms.Add min = new Terms.Add(Terms.ToArray());
                min.Minimize();
                min.DeleteResults();
            }
            else if (Terms.Count == 1)
            {
                Terms[0].Minimize();
            }


            DeleteTerms();
        }
예제 #3
0
        public unsafe void MultiplyTerm()
        {
            Input  x    = new Input(4, 2, 1);
            Tensor data = new Tensor((10, 3, 4), DeviceConfig.Host_Float);

            for (int i = 0; i < data.Shape.TotalSize; i++)
            {
                ((float *)data.Array)[i] = i / 12;
            }
            x.SetInput(data);

            Index a = new Index(x.OuterShape);

            a.SetZero();


            for (int i = 0; i < x.OuterShape.TotalSize; i++, a.Increase(1))
            {
                Term t = x.GetTerm(a);
                Console.WriteLine("Term " + i + ": " + x.GetTerm(a).GetResult());
                Term mul = new Multiply(t, t);
                Console.WriteLine("Term " + i + ": " + mul.GetResult());
                mul.DeleteResults();
                //todo check the result.
            }
        }
예제 #4
0
        public static unsafe void bb4()
        {
            Input x = new Input(4, 2, 1);

            var sum = new ShiftTime(x, new Dimension[] { -1 }); sum.Name = "sum";


            Stopwatch c = new Stopwatch();

            c.Start();

            for (int i2 = 0; i2 < 1; i2++)
            {
                Tensor data = new Tensor((10, 3, 4), DeviceConfig.Host_Float);

                for (int i = 0; i < data.Shape.TotalSize; i++)
                {
                    ((float *)data.Array)[i] = i / 12;
                }
                x.SetInput(data);

                sum.PreCheck();

                Index a = new Index(x.OuterShape);
                a.SetZero();

                for (int i = 0; i < x.OuterShape.TotalSize; i++, a.Increase(1))
                {
                    Console.WriteLine("Term " + i + ":" + sum.GetTerm(a).GetResult());
                }

                c.Restart();
                sum.Minimize();
                c.Stop();
                data.Dispose();
                Console.WriteLine($"{i2} took {c.ElapsedMilliseconds}ms");
            }
        }