{"id":15253592,"url":"https://github.com/dennis-van-gils/python-dvg-ringbuffer","last_synced_at":"2025-10-17T10:02:34.850Z","repository":{"id":37207314,"uuid":"281201490","full_name":"Dennis-van-Gils/python-dvg-ringbuffer","owner":"Dennis-van-Gils","description":"Numpy ring buffer at a fixed memory address to allow for significantly sped up numpy, sigpy, numba \u0026 pyFFTW calculations.","archived":false,"fork":false,"pushed_at":"2024-06-22T09:42:21.000Z","size":55,"stargazers_count":26,"open_issues_count":0,"forks_count":6,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-24T03:05:18.537Z","etag":null,"topics":["buffer","circular","deque","numba","numpy","pyfftw","ring","scipy"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/dvg-ringbuffer/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Dennis-van-Gils.png","metadata":{"files":{"readme":"README.rst","changelog":"CHANGELOG.rst","contributing":"CONTRIBUTING.rst","funding":".github/FUNDING.yml","license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":"AUTHORS.rst","dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"Dennis-van-Gils","patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"lfx_crowdfunding":null,"custom":null}},"created_at":"2020-07-20T18:56:07.000Z","updated_at":"2025-04-23T15:23:52.000Z","dependencies_parsed_at":"2024-09-29T22:00:30.177Z","dependency_job_id":null,"html_url":"https://github.com/Dennis-van-Gils/python-dvg-ringbuffer","commit_stats":{"total_commits":60,"total_committers":2,"mean_commits":30.0,"dds":"0.033333333333333326","last_synced_commit":"d5765dff59033673f81a8c55a2b733f8201093b9"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Dennis-van-Gils%2Fpython-dvg-ringbuffer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Dennis-van-Gils%2Fpython-dvg-ringbuffer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Dennis-van-Gils%2Fpython-dvg-ringbuffer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Dennis-van-Gils%2Fpython-dvg-ringbuffer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Dennis-van-Gils","download_url":"https://codeload.github.com/Dennis-van-Gils/python-dvg-ringbuffer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250552074,"owners_count":21449164,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["buffer","circular","deque","numba","numpy","pyfftw","ring","scipy"],"created_at":"2024-09-29T22:00:26.236Z","updated_at":"2025-10-17T10:02:34.756Z","avatar_url":"https://github.com/Dennis-van-Gils.png","language":"Python","funding_links":["https://github.com/sponsors/Dennis-van-Gils"],"categories":[],"sub_categories":[],"readme":".. image:: https://static.pepy.tech/personalized-badge/dvg-ringbuffer?period=month\u0026units=international_system\u0026left_color=gray\u0026right_color=blue\u0026left_text=%E2%86%93%20per%20month\n    :target: https://pepy.tech/project/dvg-ringbuffer\n.. image:: https://img.shields.io/pypi/v/dvg-ringbuffer\n    :target: https://pypi.org/project/dvg-ringbuffer\n.. image:: https://img.shields.io/pypi/pyversions/dvg-ringbuffer\n    :target: https://pypi.org/project/dvg-ringbuffer\n.. image:: https://github.com/Dennis-van-Gils/python-dvg-ringbuffer/actions/workflows/python-package.yml/badge.svg\n    :target: https://github.com/Dennis-van-Gils/python-dvg-ringbuffer/actions/workflows/python-package.yml\n.. image:: https://coveralls.io/repos/github/Dennis-van-Gils/python-dvg-ringbuffer/badge.svg\n    :target: https://coveralls.io/github/Dennis-van-Gils/python-dvg-ringbuffer\n.. image:: https://img.shields.io/badge/code%20style-black-000000.svg\n    :target: https://github.com/psf/black\n.. image:: https://img.shields.io/badge/License-MIT-purple.svg\n    :target: https://github.com/Dennis-van-Gils/python-dvg-ringbuffer/blob/master/LICENSE.txt\n\nDvG_RingBuffer\n==============\n*Provides a numpy ring buffer at a fixed memory address to allow for\nsignificantly sped up* ``numpy``, ``sigpy``, ``numba`` *\u0026* ``pyFFTW``\n*calculations.*\n\n- Github: https://github.com/Dennis-van-Gils/python-dvg-ringbuffer\n- PyPI: https://pypi.org/project/dvg-ringbuffer\n\nInstallation::\n\n    pip install dvg-ringbuffer\n\nBased on:\n\n    https://pypi.org/project/numpy_ringbuffer/ by Eric Wieser.\n\n    ``DvG_RingBuffer`` can be used as a drop-in replacement for\n    ``numpy_ringbuffer`` and provides several optimizations and extra features,\n    but requires Python 3.\n\nIf and only if the ring buffer is completely full, will it return its array\ndata as a contiguous C-style numpy array at a single fixed memory address per\nring buffer instance. It does so by unwrapping the discontiguous ring buffer\narray into a second extra *unwrap* buffer that is a private member of the ring\nbuffer class. This is advantegeous for other accelerated computations by, e.g.,\n``numpy``, ``sigpy``, ``numba`` \u0026 ``pyFFTW``, that benefit from being fed with\ncontiguous arrays at the same memory address each time again, such that compiler\noptimizations and data planning are made possible.\n\nWhen the ring buffer is not completely full, it will return its data as a\ncontiguous C-style numpy array, but at different memory addresses. This is how\nthe original ``numpy-buffer`` always operates.\n\nCommonly, ``collections.deque()`` is used to act as a ring buffer. The\nbenefits of a deque is that it is thread safe and fast (enough) for most\nsituations. However, there is an overhead whenever the deque -- a list-like\ncontainer -- needs to be transformed into a numpy array. Because\n``DvG_RingBuffer`` already returns numpy arrays it will outperform a\n``collections.deque()`` easily, tested to be a factor of ~60.\n\n.. warning::\n\n    * This ring buffer is not thread safe. You'll have to implement your own\n      mutex locks when using this ring buffer in multithreaded operations.\n\n    * The data array that is returned by a full ring buffer is a pass by\n      reference of the *unwrap* buffer. It is not a copy! Hence, changing\n      values in the returned data array is identical to changing values in the\n      *unwrap* buffer.\n\nAPI\n===\n\n``class RingBuffer(capacity, dtype=np.float64, allow_overwrite=True)``\n----------------------------------------------------------------------\n    Create a new ring buffer with the given capacity and element type.\n\n        Args:\n            capacity (``int``):\n                The maximum capacity of the ring buffer\n\n            dtype (``data-type``, optional):\n                Desired type of buffer elements. Use a type like ``(float, 2)``\n                to produce a buffer with shape ``(capacity, 2)``.\n\n                Default: ``np.float64``\n\n            allow_overwrite (``bool``, optional):\n                If ``False``, throw an IndexError when trying to append to an\n                already full buffer.\n\n                Default: ``True``\n\nMethods\n-------\n* ``clear()``\n* ``append(value)``\n    Append a single value to the ring buffer.\n\n    .. code-block:: python\n\n        rb = RingBuffer(3, dtype=np.int)  #  []\n        rb.append(1)                      #  [1]\n        rb.append(2)                      #  [1, 2]\n        rb.append(3)                      #  [1, 2, 3]\n        rb.append(4)                      #  [2, 3, 4]\n\n* ``appendleft(value)``\n    Append a single value to the ring buffer from the left side.\n\n    .. code-block:: python\n\n        rb = RingBuffer(3, dtype=np.int)  #  []\n        rb.appendleft(1)                  #  [1]\n        rb.appendleft(2)                  #  [2, 1]\n        rb.appendleft(3)                  #  [3, 2, 1]\n        rb.appendleft(4)                  #  [4, 3, 2]\n\n* ``extend(values)``\n    Extend the ring buffer with a list of values.\n\n    .. code-block:: python\n\n        rb = RingBuffer(3, dtype=np.int)  #  []\n        rb.extend([1])                    #  [1]\n        rb.extend([2, 3])                 #  [1, 2, 3]\n        rb.extend([4, 5, 6, 7])           #  [5, 6, 7]\n\n* ``extendleft(values)``\n    Extend the ring buffer with a list of values from the left side.\n\n    .. code-block:: python\n\n        rb = RingBuffer(3, dtype=np.int)  #  []\n        rb.extendleft([1])                #  [1]\n        rb.extendleft([3, 2])             #  [3, 2, 1]\n        rb.extendleft([7, 6, 5, 4])       #  [7, 6, 5]\n\n* ``pop()``\n    Remove the right-most item from the ring buffer and return it.\n\n* ``popleft()``\n    Remove the left-most item from the ring buffer and return it.\n\nProperties\n----------\n* ``is_full``\n* ``unwrap_address``\n* ``current_address``\n* ``dtype``\n* ``shape``\n* ``maxlen``\n\nIndexing \u0026 slicing\n------------------\n* ``[]`` including negative indices and slicing\n\n    .. code-block:: python\n\n        from dvg_ringbuffer import RingBuffer\n\n        rb = RingBuffer(4, dtype=np.int)  # --\u003e rb[:] = array([], dtype=int32)\n        rb.extend([1, 2, 3, 4, 5])        # --\u003e rb[:] = array([2, 3, 4, 5])\n        x = rb[0]                         # --\u003e x = 2\n        x = rb[-1]                        # --\u003e x = 5\n        x = rb[:3]                        # --\u003e x = array([2, 3, 4])\n        x = rb[np.array([0, 2, -1])]      # --\u003e x = array([2, 4, 5])\n\n        rb = RingBuffer(5, dtype=(np.int, 2))  # --\u003e rb[:] = array([], shape=(0, 2), dtype=int32)\n        rb.append([1, 2])                      # --\u003e rb[:] = array([[1, 2]])\n        rb.append([3, 4])                      # --\u003e rb[:] = array([[1, 2], [3, 4]])\n        rb.append([5, 6])                      # --\u003e rb[:] = array([[1, 2], [3, 4], [5, 6]])\n        x = rb[0]                              # --\u003e x = array([1, 2])\n        x = rb[0, :]                           # --\u003e x = array([1, 2])\n        x = rb[:, 0]                           # --\u003e x = array([1, 3, 5])\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdennis-van-gils%2Fpython-dvg-ringbuffer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdennis-van-gils%2Fpython-dvg-ringbuffer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdennis-van-gils%2Fpython-dvg-ringbuffer/lists"}