Example #1
0
        public override IExpr Patch(Patch substitutions)
        {
            XSlice result;

            if (substitutions.TryGetValue(this, out result))
            {
                return(result);
            }
            var inputsPatched = Inputs.Patch(substitutions);

            if (inputsPatched != Inputs)
            {
                XSlice patched;
                if (IsSingleton)
                {
                    patched = new XSlice((Scalar <int>)inputsPatched[0]);
                }
                else
                {
                    patched = new XSlice((Scalar <int>)inputsPatched[0], (Scalar <int>)inputsPatched[1], (Scalar <int>)inputsPatched[2]);
                }
                substitutions.Add(this, patched);
                return(patched);
            }
            else
            {
                return(this);
            }
        }
Example #2
0
        public static IReadOnlyList <XSlice> Patch(Patch substitutions, IReadOnlyList <XSlice> slices)
        {
            var ok     = true;
            var result = new XSlice[slices.Count];

            for (int i = 0; i < result.Length; i++)
            {
                var slice = slices[i];
                result[i] = new XSlice(
                    (Scalar <int>)slice.Start.Patch(substitutions),
                    (Scalar <int>)slice.Stop.Patch(substitutions),
                    (Scalar <int>)slice.Step.Patch(substitutions)
                    );
                if (result[i].Start != slice.Start ||
                    result[i].Stop != slice.Stop ||
                    result[i].Step != slice.Step)
                {
                    ok = false;
                }
            }
            if (ok)
            {
                return(slices);
            }
            return(result);
        }
Example #3
0
 public static XSlice Step(int step)
 {
     if (step < 0)
     {
         return(XSlice.Create(-1, int.MinValue, step));
     }
     return(XSlice.Create(0, int.MaxValue, step));
 }
Example #4
0
 public static XSlice From(Scalar <int> start, int step = 1)
 {
     if (step < 0)
     {
         return(XSlice.Create(start, int.MinValue, step));
     }
     else
     {
         return(XSlice.Create(start, int.MaxValue, step));
     }
 }
Example #5
0
 public static XSlice Until(Scalar <int> stop, int step = 1)
 {
     if (step < 0)
     {
         return(XSlice.Create(-1, stop, step));
     }
     else
     {
         return(XSlice.Create(0, stop, step));
     }
 }
Example #6
0
        //public static readonly Slice NewAxis = Range(0, 0, int.MaxValue);

        public static XSlice Range(Scalar <int> start, Scalar <int> stop, int step = 1)
        {
            if (stop == null)
            {
                return(From(start, step));
            }
            if (start == null)
            {
                return(Until(stop, step));
            }
            return(XSlice.Create(start, stop, step));
        }
Example #7
0
 public static XSlice Only(Scalar <int> i) => XSlice.Create(i, i + 1, 0);