Giter VIP home page Giter VIP logo

numpy_ringbuffer's Introduction

numpy_ringbuffer

Build Status codecov

Ring (aka circular) buffers backed by a numpy array, supporting:

  • Operations from collections.deque
    • b.append(val)
    • b.appendleft(val)
    • b.extend(val)
    • b.extendleft(val)
    • b.pop(val)
    • b.popleft(val)
  • The collections.Sequence protocol (unoptimized)
  • C-side unwrapping into an array with np.array(b)
  • Arbitrary element dtypes, including extra dimensions like RingBuffer(N, dtype=(int, 3))

For example:

import numpy as np
from numpy_ringbuffer import RingBuffer

r = RingBuffer(capacity=4, dtype=bool)
r.append(True)
r.appendleft(False)
print(np.array(r))  # array([False, True])

numpy_ringbuffer's People

Contributors

eric-wieser avatar pauljurczak avatar stuaxo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

numpy_ringbuffer's Issues

pip install numpy-ringbuffer fails with pypandoc errors

First I tried installing from scratch and got errors because pypandoc was not available, installed and tried again but still not quite there.

OS: Ubuntu 16.04
Python: 3.5

$ pip install numpy-ringbuffer
Collecting numpy-ringbuffer
  Downloading numpy_ringbuffer-0.2.0.zip
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "/tmp/pip-build-9r6sqi7d/numpy-ringbuffer/setup.py", line 7, in <module>
        import pypandoc
    ImportError: No module named 'pypandoc'
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-build-9r6sqi7d/numpy-ringbuffer/setup.py", line 11, in <module>
        long_description = open('README.md').read()
    FileNotFoundError: [Errno 2] No such file or directory: 'README.md'
    No
    
    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-9r6sqi7d/numpy-ringbuffer/

$ pip install pypandoc
Collecting pypandoc
  Downloading pypandoc-1.3.3.tar.gz
Requirement already satisfied: setuptools in /mnt/data/home/stu/.virtualenvs/cord-py3/lib/python3.5/site-packages (from pypandoc)
Requirement already satisfied: pip>=8.1.0 in /mnt/data/home/stu/.virtualenvs/cord-py3/lib/python3.5/site-packages (from pypandoc)
Requirement already satisfied: wheel>=0.25.0 in /mnt/data/home/stu/.virtualenvs/cord-py3/lib/python3.5/site-packages (from pypandoc)
Building wheels for collected packages: pypandoc
  Running setup.py bdist_wheel for pypandoc ... done
  Stored in directory: /home/stu/.cache/pip/wheels/ae/ad/24/8ae56cccee848926ed5cb93f2d80dc3e9b6840b179d9b4936e
Successfully built pypandoc
Installing collected packages: pypandoc
Successfully installed pypandoc-1.3.3
  $ pip install numpy-ringbuffer
Collecting numpy-ringbuffer
  Using cached numpy_ringbuffer-0.2.0.zip
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-build-nb17gbac/numpy-ringbuffer/setup.py", line 8, in <module>
        long_description = pypandoc.convert('README.md', 'rst')
      File "/mnt/data/home/stu/.virtualenvs/cord-py3/lib/python3.5/site-packages/pypandoc/__init__.py", line 66, in convert
        raise RuntimeError("Format missing, but need one (identified source as text as no "
    RuntimeError: Format missing, but need one (identified source as text as no file with that name was found).
    
    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-nb17gbac/numpy-ringbuffer/

class RingBuffer(Sequence)

The Readme.md says that collections.deque operations are available, but RingBuffer inherits from collections ABC, Sequence? At any rate, I can't access the deque.clear() method.

Am I missing something?

README.md missing in archive

setup.py complains when doing the pypi install. You have to provide a MANIFEST.in file, which contains README.md to automatically ship it

compatible with python3?

This don't appear to be capable to work with python3,
Have any one make the conversion?

thansk

DepretiationWarning

/Users/gandalf/Documents/Src/core.F/venv/lib/python3.7/site-packages/numpy_ringbuffer/__init__.py:2: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated since Python 3.3,and in 3.9 it will stop working from collections import Sequence

indexing an empty buffer doesn't raise an IndexError

If you index a RingBuffer before having appended any values to it, you will unsafely get whatever was in memory at the buffer's location

from numpy_ringbuffer import RingBuffer
r = RingBuffer(10)
print(r[0])
# -2.6815615859885194e+154

`__getitem__` does not obey `_left_index` and `_right_index`

Hi @eric-wieser, simple indexing does not work as expected in combination with pop(). E.g.,

r = RingBuffer(capacity=4, dtype=np.int32)
r.extend((1,2,3,4))
r.pop()
print(r[-1])
>>> 4

One would expect to see r[-1] = 3. The reason is that simple indexing does not check whether requested index is within the range between _left_index and _right_index.

Negative indices in unfull buffers unsafely access memory

In a partly-full buffer, if you take a negative index, it will refer that index to the end of the full length of the buffer as apposed to the end of the full portion of the buffer.

from numpy_ringbuffer import RingBuffer
r = RingBuffer(10)
for i in range(5):
    r.append(i)
print(r[-1])
# 3.5097786643241087e+64

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.