示例#1
0
        public virtual object __getslice__(int start, int stop)
        {
            Slice.FixSliceArguments(_data.Length, ref start, ref stop);

            if (start == 0 && stop == _data.Length &&
                this.GetType() == typeof(PythonTuple))
            {
                return(this);
            }
            return(MakeTuple(ArrayOps.GetSlice(_data, start, stop)));
        }
示例#2
0
        public virtual object AddSequence(object other)
        {
            Tuple o = other as Tuple;

            if (o == null)
            {
                throw Ops.TypeError("can only concatenate tuple (not \"{0}\") to tuple", Ops.GetDynamicType(other).__name__);
            }

            return(MakeTuple(ArrayOps.Add(data, data.Length, o.data, o.data.Length)));
        }
示例#3
0
        public virtual object this[[NotNone] Slice slice] {
            get {
                slice.Indices(_data.Length, out int start, out int stop, out int step);

                if (start == 0 && stop == _data.Length && step == 1 &&
                    this.GetType() == typeof(PythonTuple))
                {
                    return(this);
                }
                return(MakeTuple(ArrayOps.GetSlice(_data, start, stop, step)));
            }
        }
示例#4
0
 public virtual object MultiplySequence(int count)
 {
     if (count <= 0)
     {
         return(Tuple.EMPTY);
     }
     if (count == 1)
     {
         return(this);
     }
     return(MakeTuple(ArrayOps.Multiply(data, data.Length, count)));
 }
示例#5
0
        public override object Call(params object[] args)
        {
            if (args.Length != 1)
            {
                throw Ops.TypeError("array expects one and only 1 argument");
            }
            if (this.type == typeof(Array))
            {
                throw Ops.TypeError("general array type is not callable");
            }

            return(ArrayOps.CreateArray(this.type.GetElementType(), args[0]));
        }
示例#6
0
        public virtual object GetSlice(int start, int stop)
        {
            if (start < 0)
            {
                start = 0;
            }
            if (stop > GetLength())
            {
                stop = GetLength();
            }

            return(Make(ArrayOps.GetSlice(data, data.Length, new Slice(start, stop))));
        }
示例#7
0
        private static object[] MakeItems(object o)
        {
            var t = o.GetType();

            // Only use fast paths if we have an exact tuple/list, otherwise use iter
            if (t == typeof(PythonTuple))
            {
                return(((PythonTuple)o)._data);
            }
            else if (t == typeof(PythonList))
            {
                return(((PythonList)o).GetObjectArray());
            }
            else if (o is string)
            {
                string   s   = (string)o;
                object[] res = new object[s.Length];
                for (int i = 0; i < res.Length; i++)
                {
                    res[i] = ScriptingRuntimeHelpers.CharToString(s[i]);
                }
                return(res);
            }
            else if (o is object[] arr)
            {
                return(ArrayOps.CopyArray(arr, arr.Length));
            }
            else
            {
                PerfTrack.NoteEvent(PerfTrack.Categories.OverAllocate, "TupleOA: " + PythonTypeOps.GetName(o));

                List <object> l = new List <object>();
                IEnumerator   i = PythonOps.GetEnumerator(o);
                while (i.MoveNext())
                {
                    l.Add(i.Current);
                }

                return(l.ToArray());
            }
        }
示例#8
0
        private static object[] MakeItems(object o)
        {
            object[] arr;
            if (o is PythonTuple)
            {
                return(((PythonTuple)o)._data);
            }
            else if (o is string)
            {
                string   s   = (string)o;
                object[] res = new object[s.Length];
                for (int i = 0; i < res.Length; i++)
                {
                    res[i] = ScriptingRuntimeHelpers.CharToString(s[i]);
                }
                return(res);
            }
            else if (o is List)
            {
                return(((List)o).GetObjectArray());
            }
            else if ((arr = o as object[]) != null)
            {
                return(ArrayOps.CopyArray(arr, arr.Length));
            }
            else
            {
                PerfTrack.NoteEvent(PerfTrack.Categories.OverAllocate, "TupleOA: " + PythonTypeOps.GetName(o));

                List <object> l = new List <object>();
                IEnumerator   i = PythonOps.GetEnumerator(o);
                while (i.MoveNext())
                {
                    l.Add(i.Current);
                }

                return(l.ToArray());
            }
        }
示例#9
0
 internal object?[] ToArray()
 {
     return(ArrayOps.CopyArray(_data, _data.Length));
 }
示例#10
0
 public object this[Slice slice] {
     get {
         return(Make(ArrayOps.GetSlice(data, data.Length, slice)));
     }
 }
示例#11
0
 public virtual bool ContainsValue(object item)
 {
     return(ArrayOps.Contains(data, data.Length, item));
 }
示例#12
0
 public virtual object this[Slice slice] {
     get {
         return(MakeTuple(ArrayOps.GetSlice(_data, slice)));
     }
 }
示例#13
0
        public virtual object __getslice__(int start, int stop)
        {
            Slice.FixSliceArguments(_data.Length, ref start, ref stop);

            return(MakeTuple(ArrayOps.GetSlice(_data, start, stop)));
        }