示例#1
0
        public Axis ExtractAxis <T>(Tensor <T> t, int i)
        {
            if (IsSingleton)
            {
                return(null);
            }

            var axis = t.Shape[i];

            if (Step.IsOne)
            {
                // [x:]
                if (Stop == null || Stop.IsConst(int.MaxValue))
                {
                    return(axis - GetAbsoluteIndex(t, i, Start));
                }
            }
            else if (Step.Check((Int s) => s.Value < 0))
            {
                // [x::-s]
                if (Stop.IsConst(int.MinValue))
                {
                    // [::-s]
                    if (Start.IsMinusOne)
                    {
                        return(axis / -Step);
                    }
                    else
                    {
                        return((GetAbsoluteIndex(t, i, Start) + 1) / -Step);
                    }
                }
            }

            var stop  = GetAbsoluteIndex(t, i, Stop);
            var start = GetAbsoluteIndex(t, i, Start);

            return((stop - start) / Step);
        }