Наследование: ICodeFormattable
Пример #1
0
        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
        }
Пример #2
0
 public ByteArray InPlaceAdd(MemoryView other)
 {
     lock (this) {
         _bytes.AddRange(other.tobytes());
         return(this);
     }
 }
Пример #3
0
 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()));
 }
Пример #4
0
        public override bool Equals(object obj)
        {
            MemoryView mv = obj as MemoryView;

            if ((object)mv != null)
            {
                return(this == mv);
            }
            return(false);
        }
Пример #5
0
        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;
            }
        }
Пример #6
0
 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;
 }
Пример #7
0
        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);
        }
Пример #8
0
 internal MemoryView(MemoryView mv, bool readOnly) : this(mv) {
     _isReadOnly = _isReadOnly || readOnly;
 }
Пример #9
0
 public MemoryView(MemoryView @object) :
     this(@object._buffer, @object._start, @object._end, @object._step, @object._format, @object._shape)
 {
 }
Пример #10
0
 public MemoryView(MemoryView obj) : this(obj._buffer, obj._start, obj._end)
 {
 }
Пример #11
0
 public bool __ne__(CodeContext /*!*/ context, [NotNull] MemoryView value) => !__eq__(context, value);
Пример #12
0
 public MemoryView(MemoryView obj)
 {
     _buffer = obj._buffer;
     _start  = obj._start;
     _end    = obj._end;
 }
Пример #13
0
            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);
            }
Пример #14
0
            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;

            }
Пример #15
0
 public static Bytes hexlify(MemoryView data)
 {
     return hexlify(data.tobytes());
 }
Пример #16
0
 public MemoryView([NotNull] MemoryView @object) :
     this(@object._buffer, @object._start, @object._end, @object._step, @object._format, @object._shape, @object._isReadOnly)
 {
 }
Пример #17
0
 public bool __eq__(CodeContext /*!*/ context, [NotNull] MemoryView value) => tobytes().Equals(value.tobytes());
Пример #18
0
 public MemoryView(MemoryView obj) : this(obj._buffer, obj._start, obj._end, obj._step, obj._format, obj._shape)
 {
 }