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))); }
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))); }
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))); } }
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))); }
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])); }
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)))); }
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()); } }
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()); } }
internal object?[] ToArray() { return(ArrayOps.CopyArray(_data, _data.Length)); }
public object this[Slice slice] { get { return(Make(ArrayOps.GetSlice(data, data.Length, slice))); } }
public virtual bool ContainsValue(object item) { return(ArrayOps.Contains(data, data.Length, item)); }
public virtual object this[Slice slice] { get { return(MakeTuple(ArrayOps.GetSlice(_data, slice))); } }
public virtual object __getslice__(int start, int stop) { Slice.FixSliceArguments(_data.Length, ref start, ref stop); return(MakeTuple(ArrayOps.GetSlice(_data, start, stop))); }