Example #1
0
        private Slicing(Tensor <Type> x, XList <XSlice, Slice> slices)
            : base("[]", x, slices)
        {
            // count the number of dropped dimensions
            Shape = new Dim[x.NDim - slices.Count(s => s.IsSingleton)];

            // align new axis with old ones
            int i = 0, j = 0;

            foreach (var slice in slices)
            {
                if (!slice.IsSingleton)
                {
                    Shape[i++] = slice.ExtractAxis(x, j);
                }
                ++j;
            }
            // axis not appearing in slices are not modified
            for (; i < Shape.Length; ++i)
            {
                Shape[i] = x.Shape[j++];
            }
        }