Ejemplo n.º 1
0
            public PythonArray InPlaceAdd(PythonArray other) {
                if (typecode != other.typecode) throw PythonOps.TypeError("cannot add different typecodes");

                if (other._data.Length != 0) {
                    extend(other);
                }

                return this;
            }
Ejemplo n.º 2
0
            public static PythonArray operator +(PythonArray self, PythonArray other) {
                if (self.typecode != other.typecode) throw PythonOps.TypeError("cannot add different typecodes");

                PythonArray res = new PythonArray(self.typecode, Type.Missing);
                foreach (object o in self) {
                    res.append(o);
                }

                foreach (object o in other) {
                    res.append(o);
                }

                return res;
            }
Ejemplo n.º 3
0
            public object this[Slice index] {
                get {
                    if (index == null) throw PythonOps.TypeError("expected Slice, got None");

                    int start, stop, step;
                    index.indices(_data.Length, out start, out stop, out step);

                    PythonArray pa = new PythonArray(new string(_typeCode, 1), Type.Missing);
                    if (step < 0) {
                        for (int i = start; i > stop; i += step) {
                            pa._data.Append(_data.GetData(i));
                        }
                    } else {
                        for (int i = start; i < stop; i += step) {
                            pa._data.Append(_data.GetData(i));
                        }
                    }
                    return pa;
                }
                set {
                    if (index == null) throw PythonOps.TypeError("expected Slice, got None");

                    PythonArray pa = value as PythonArray;
                    if (pa != null && pa._typeCode != _typeCode) {
                        throw PythonOps.TypeError("bad array type");
                    }

                    if (index.step != null) {
                        if (Object.ReferenceEquals(value, this)) value = this.tolist();

                        index.DoSliceAssign(SliceAssign, _data.Length, value);
                    } else {
                        int start, stop, step;
                        index.indices(_data.Length, out start, out stop, out step);
                        if (stop < start) {
                            stop = start;
                        }

                        // replace between start & stop w/ values
                        IEnumerator ie = PythonOps.GetEnumerator(value);

                        ArrayData newData = CreateData(_typeCode);
                        for (int i = 0; i < start; i++) {
                            newData.Append(_data.GetData(i));
                        }

                        while (ie.MoveNext()) {
                            newData.Append(ie.Current);
                        }

                        for (int i = stop; i < _data.Length; i++) {
                            newData.Append(_data.GetData(i));
                        }

                        _data = newData;
                    }
                }
            }
Ejemplo n.º 4
0
 public static PythonArray operator *(int value, PythonArray array) {
     PythonArray data = new PythonArray(array.typecode, Type.Missing);
     for (int i = 0; i < value; i++) {
         data.extend(array);
     }
     return data;
 }
Ejemplo n.º 5
0
 public PythonArray ReverseMultiply(int value)
 {
     PythonArray data = new PythonArray(new string(TypeCode, 1), Type.Missing);
     for (int i = 0; i < value; i++) {
         data.Extend(this);
     }
     return data;
 }
Ejemplo n.º 6
0
            public PythonArray Add(PythonArray other)
            {
                if (TypeCode != other.TypeCode) throw Ops.TypeError("cannot add different typecodes");

                PythonArray res = new PythonArray(new string(TypeCode, 1), Type.Missing);
                foreach (object o in this) {
                    res.Append(o);
                }

                foreach (object o in other) {
                    res.Append(o);
                }

                return res;
            }
Ejemplo n.º 7
0
 public static PythonArray operator *(int value, PythonArray array) {
     if ((BigInteger)value * array.__len__() * array.itemsize > SysModule.maxsize) {
         throw PythonOps.MemoryError("");
     }
     PythonArray data = new PythonArray(array.typecode, Type.Missing);
     for (int i = 0; i < value; i++) {
         data.extend(array);
     }
     return data;
 }
Ejemplo n.º 8
0
            public object this[Slice index] {
                get {
                    if (index == null) throw PythonOps.TypeError("expected Slice, got None");

                    int start, stop, step;
                    index.indices(_data.Length, out start, out stop, out step);

                    PythonArray pa = new PythonArray(new string(_typeCode, 1), Type.Missing);
                    if (step < 0) {
                        for (int i = start; i > stop; i += step) {
                            pa._data.Append(_data.GetData(i));
                        }
                    } else {
                        for (int i = start; i < stop; i += step) {
                            pa._data.Append(_data.GetData(i));
                        }
                    }
                    return pa;
                }
                set {
                    if (index == null) throw PythonOps.TypeError("expected Slice, got None");

                    CheckSliceAssignType(value);

                    if (index.step != null) {
                        if (Object.ReferenceEquals(value, this)) value = this.tolist();

                        index.DoSliceAssign(SliceAssign, _data.Length, value);
                    } else {
                        int start, stop, step;
                        index.indices(_data.Length, out start, out stop, out step);
                        if (stop < start) {
                            stop = start;
                        }

                        SliceNoStep(value, start, stop);
                    }
                }
            }