Пример #1
0
        public object this[[NotNull] Slice slice] {
            get {
                CheckBuffer();
                int start, stop;
                FixSlice(slice, __len__(), out start, out stop);

                return(new MemoryView(_buffer, _start + start, _start + stop));
            }
            set {
                CheckBuffer();
                if (_buffer.ReadOnly)
                {
                    throw PythonOps.TypeError("cannot modify read-only memory");
                }

                int start, stop;
                FixSlice(slice, __len__(), out start, out stop);

                int newLen = PythonOps.Length(value);
                if (stop - start != newLen)
                {
                    throw PythonOps.ValueError("cannot resize memory view");
                }

                _buffer.SetSlice(new Slice(_start + start, _start + stop), value);
            }
        }
Пример #2
0
        public object this[[NotNull] Slice slice] {
            get {
                if (slice.step != null)
                {
                    throw PythonOps.NotImplementedError("");
                }

                return(new MemoryView(
                           _buffer,
                           slice.start == null ? _start : (Converter.ConvertToInt32(slice.start) + _start),
                           slice.stop == null ? _end : (Converter.ConvertToInt32(slice.stop) + _start)
                           ));
            }
            set {
                if (_start != 0 || _end != null)
                {
                    slice = new Slice(
                        slice.start == null ? _start : (Converter.ConvertToInt32(slice.start) + _start),
                        slice.stop == null ? _end : (Converter.ConvertToInt32(slice.stop) + _start)
                        );
                }

                int len = PythonOps.Length(value);
                int start, stop, step;
                slice.indices(PythonOps.Length(_buffer), out start, out stop, out step);
                if (stop - start != len)
                {
                    throw PythonOps.ValueError("cannot resize memory view");
                }

                _buffer.SetSlice(slice, value);
            }
        }