private MemoryView(MemoryView mv, int newStart, int newStop, int newStep, int newLen) : this(mv) { Debug.Assert(_numDims > 0); Debug.Assert(newLen <= _shape[0]); var oldLen = _shape[0]; var newShape = _shape.ToArray(); newShape[0] = newLen; _shape = newShape; _offset += newStart * _strides[0]; if (newLen > 1) { var newStrides = _strides.ToArray(); newStrides[0] *= newStep; _strides = newStrides; } if (oldLen != 0) { _numItems /= oldLen; } _numItems *= newLen; _isCContig = _isCContig && newStep == 1; _isFContig = _isCContig && _numDims <= 1; // TODO: support for ND Fortran arrays not implemented }
public ByteArray InPlaceAdd(MemoryView other) { lock (this) { _bytes.AddRange(other.tobytes()); return(this); } }
public bool __eq__(CodeContext /*!*/ context, [NotNull] MemoryView value) { if (_buffer == null) { return(value._buffer == null); } // TODO: comparing flat bytes is oversimplification; besides, no data copyimg return(tobytes().Equals(value.tobytes())); }
public override bool Equals(object obj) { MemoryView mv = obj as MemoryView; if ((object)mv != null) { return(this == mv); } return(false); }
private MemoryView(MemoryView @object, BufferFlags flags) : this(@object) { // flags already checked for consistency with the underlying buffer _flags = flags; if (!_flags.HasFlag(BufferFlags.ND)) { // flatten _numDims = 1; _shape = new[] { _numItems }; _isCContig = _isFContig = true; } }
public MemoryView([NotNone] MemoryView @object) { _exporter = @object._exporter; _flags = BufferFlags.RecordsRO; _buffer = _exporter.GetBuffer(_flags); _offset = @object._offset; _isReadOnly = @object._isReadOnly; _numDims = @object._numDims; _format = @object._format; _itemSize = @object._itemSize; _shape = @object._shape; _strides = @object._strides; _isCContig = @object._isCContig; _isFContig = @object._isFContig; _numItems = @object._numItems; }
private MemoryView(MemoryView mv, string newFormat, int newItemSize, IReadOnlyList <int> newShape) : this(mv) { // arguments already checked for consistency // reformat _format = newFormat; _numItems *= _itemSize; _numItems /= newItemSize; _itemSize = newItemSize; // reshape _shape = newShape; _numDims = _shape.Count; _strides = GetContiguousStrides(_shape, _itemSize); }
internal MemoryView(MemoryView mv, bool readOnly) : this(mv) { _isReadOnly = _isReadOnly || readOnly; }
public MemoryView(MemoryView @object) : this(@object._buffer, @object._start, @object._end, @object._step, @object._format, @object._shape) { }
public MemoryView(MemoryView obj) : this(obj._buffer, obj._start, obj._end) { }
public bool __ne__(CodeContext /*!*/ context, [NotNull] MemoryView value) => !__eq__(context, value);
public MemoryView(MemoryView obj) { _buffer = obj._buffer; _start = obj._start; _end = obj._end; }
public PythonTuple recvfrom_into(MemoryView buffer, [DefaultParameterValue(0)]int nbytes, [DefaultParameterValue(0)]int flags){ int bytesRead; byte[] byteBuffer = buffer.tobytes().ToByteArray(); IPEndPoint remoteIPEP = new IPEndPoint(IPAddress.Any, 0); EndPoint remoteEP = remoteIPEP; try { bytesRead = _socket.ReceiveFrom(byteBuffer, (SocketFlags)flags, ref remoteEP); } catch (Exception e) { throw MakeRecvException(e, SocketError.InvalidArgument); } buffer[new Slice(0, bytesRead)] = byteBuffer.Slice(new Slice(0, bytesRead)); PythonTuple remoteAddress = EndPointToTuple((IPEndPoint)remoteEP); return PythonTuple.MakeTuple(bytesRead, remoteAddress); }
public int recv_into(MemoryView buffer, [DefaultParameterValue(0)]int nbytes, [DefaultParameterValue(0)]int flags) { int bytesRead; byte[] byteBuffer = buffer.tobytes().ToByteArray(); try { bytesRead = _socket.Receive(byteBuffer, (SocketFlags)flags); } catch (Exception e) { if (_socket.SendTimeout == 0) { var s = new SocketException((int)SocketError.NotConnected); throw PythonExceptions.CreateThrowable(error(_context), (int)SocketError.NotConnected, s.Message); } else throw MakeException(_context, e); } buffer[new Slice(0, bytesRead)] = byteBuffer.Slice(new Slice(0, bytesRead)); return bytesRead; }
public static Bytes hexlify(MemoryView data) { return hexlify(data.tobytes()); }
public MemoryView([NotNull] MemoryView @object) : this(@object._buffer, @object._start, @object._end, @object._step, @object._format, @object._shape, @object._isReadOnly) { }
public bool __eq__(CodeContext /*!*/ context, [NotNull] MemoryView value) => tobytes().Equals(value.tobytes());
public MemoryView(MemoryView obj) : this(obj._buffer, obj._start, obj._end, obj._step, obj._format, obj._shape) { }