Ejemplo n.º 1
0
        public void ConcatShouldReturnValErrorIfMoreThan254Args()
        {
            var           func = new Concat();
            List <object> args = new List <object>();

            for (var i = 0; i < 255; i++)
            {
                args.Add("arg " + i);
            }
            var result = func.Execute(FunctionsHelper.CreateArgs(args.ToArray()), _parsingContext);

            Assert.AreEqual("#VALUE!", result.Result.ToString());
        }
Ejemplo n.º 2
0
        public void ExecuteTest()
        {
            Random rd = new Random(1234);

            foreach (Shape outshape in new Shape[] {
                new Shape(ShapeType.Map, 13),
                new Shape(ShapeType.Map, 24),
                new Shape(ShapeType.Map, 13, 14),
                new Shape(ShapeType.Map, 24, 21),
                new Shape(ShapeType.Map, 14, 19, 13),
                new Shape(ShapeType.Map, 13, 14, 19),
                new Shape(ShapeType.Map, 13, 14, 19, 21),
                new Shape(ShapeType.Map, 19, 21, 13, 14),
                new Shape(ShapeType.Map, 13, 14, 19, 21, 24),
                new Shape(ShapeType.Map, 24, 19, 14, 13, 21),
                new Shape(ShapeType.Map, 19, 13, 21, 24, 14)
            })
            {
                for (int axis = 0; axis < outshape.Ndim; axis++)
                {
                    int length = outshape[axis];

                    for (int n = 1; n <= 5; n++)
                    {
                        int[] c = (new int[n]).Select((_) => 1).ToArray();

                        for (int j = n; j < length; j++)
                        {
                            c[rd.Next(c.Length)]++;
                        }

                        float[][] xs       = new float[n][];
                        Shape[]   inshapes = new Shape[n];
                        OverflowCheckedTensor[] intensors  = new OverflowCheckedTensor[n];
                        OverflowCheckedTensor[] outtensors = new OverflowCheckedTensor[n];

                        for (int i = 0; i < n; i++)
                        {
                            int[] s = outshape;
                            s[axis]     = c[i];
                            inshapes[i] = new Shape(ShapeType.Map, s);

                            xs[i] = (new float[inshapes[i].Length]).Select((_) => (float)rd.NextDouble() * (i + 1)).ToArray();

                            intensors[i]  = new OverflowCheckedTensor(inshapes[i], xs[i]);
                            outtensors[i] = new OverflowCheckedTensor(inshapes[i]);
                        }

                        OverflowCheckedTensor outtensor = new OverflowCheckedTensor(outshape);

                        Concat concat = new Concat(inshapes, outshape, axis);
                        concat.Execute(intensors.Concat(new Tensor[] { outtensor }).ToArray());

                        float[] y = outtensor.State;

                        Separate separate = new Separate(outshape, inshapes, axis);
                        separate.Execute((new Tensor[] { outtensor }).Concat(outtensors).ToArray());

                        CollectionAssert.AreEqual(y, outtensor.State);

                        for (int i = 0; i < n; i++)
                        {
                            CollectionAssert.AreEqual(xs[i], outtensors[i].State);
                        }

                        Console.WriteLine($"pass {outshape} axis:{axis} -> {string.Join(", ", inshapes.Select((shape) => shape.ToString()))}");
                    }
                }
                ;
            }
        }