Skip to main content

A multiprocess-safe buffer for PyTorch tensors with live rendering using Pygame.

Project description

MatrixBuffer

MatrixBuffer is a Python package that provides a multiprocess-safe buffer for PyTorch tensors, specifically designed for rendering RGB matrices using Pygame. This package allows for efficient sharing of tensor data between processes, making it suitable for applications that require real-time rendering and updates.

Features

  • Multiprocess Safe: Utilizes shared memory and locks to ensure safe access to tensor data across multiple processes.
  • Flexible Modes: Supports both numerical and RGB modes for tensor data.
  • Easy Integration: Designed to work seamlessly with Pygame for rendering visual data.

Installation

You can install the MatrixBuffer package using pip. Run the following command:

pip install matrixbuffer

Usage

Here is a simple example of how to use the MatrixBuffer package:

import pygame
from matrixbuffer.MatrixBuffer import MultiprocessSafeTensorBuffer, Render, update_buffer_process
import multiprocessing

# Initialize Pygame and create a window
pygame.init()
screen = pygame.display.set_mode((800, 600))

# Create a multiprocess-safe tensor buffer
rgb_buffer = MultiprocessSafeTensorBuffer(n=240, m=320, mode="rgb")

# Create a renderer
renderer = Render(rgb_buffer, screen)

# Start the worker process to update the buffer
stop_event = multiprocessing.Event()
worker_process = multiprocessing.Process(target=update_buffer_process, args=(rgb_buffer, stop_event))
worker_process.start()

# Main loop for rendering
running = True
while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False

    renderer.render()

# Clean up
stop_event.set()
worker_process.join()
pygame.quit()

License

This project is licensed under the MIT License. See the LICENSE file for more details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

matrixbuffer-0.1.0.tar.gz (5.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

matrixbuffer-0.1.0-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

Details for the file matrixbuffer-0.1.0.tar.gz.

File metadata

  • Download URL: matrixbuffer-0.1.0.tar.gz
  • Upload date:
  • Size: 5.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.11

File hashes

Hashes for matrixbuffer-0.1.0.tar.gz
Algorithm Hash digest
SHA256 f17d1d3b952fd3cb98be0805743df7acaf4611c5eced666333b448cb935c2308
MD5 717364d808419ac7e7e47aaa2365786c
BLAKE2b-256 97a3431e0536db5118db939117b285e9fd0aa9dacb12a8f58f813d6254e235ee

See more details on using hashes here.

File details

Details for the file matrixbuffer-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: matrixbuffer-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.11

File hashes

Hashes for matrixbuffer-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5939411a71a30836548fa562b91e9a88dbf4f85a26dd022c70a8d6c9f944d07b
MD5 0955b19bfea604efb6395bffec66e050
BLAKE2b-256 b5d9bdde4b98a001a96a7105148d0f1952aa23012a326b2d3af6f451fd2b02ab

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page