Skip to main content

A Python package for high-performance GPU/CPU buffer rendering with support for tables, text, and graphics.

Project description

MatrixBuffer

MatrixBuffer is a Python package that provides a multiprocess-safe buffer for PyTorch tensors, specifically designed for rendering RGB matrices and tables 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.
  • Table Rendering: Built-in utilities to render structured tabular data directly on the screen.
  • Easy Integration: Designed to work seamlessly with Pygame for rendering visual data.

Installation

You can install the MatrixBuffer package using pip:

pip install matrixbuffer

Usage

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

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

# 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()

# Example table data
headers = ["ID", "Name", "Score"]
rows = [
    [1, "Alice", 95],
    [2, "Bob", 87],
    [3, "Charlie", 78],
]

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

    # Render tensor buffer
    renderer.render()

    # Draw a table on top
    draw_table(screen, headers, rows, (50, 50))

    pygame.display.flip()

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

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.2.0.tar.gz (8.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.2.0-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for matrixbuffer-0.2.0.tar.gz
Algorithm Hash digest
SHA256 59ceab994b199be291f99a0a8cbb5bcb21b0af3a1f0db137355f5d1005728a60
MD5 d619aae62c1792216bcffd0dbfb13429
BLAKE2b-256 2818625439416d86b04323be4295c92a2e4c2df915c76b5b3ce78705332bd478

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for matrixbuffer-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 37608e1e0b771893741b67de103052f351bcfbbe81a10c5b3a22c271c90660c8
MD5 3e4727a14997427b85bec1193438659d
BLAKE2b-256 df2ee6abee2ba17c741ff377334732c11937b9726f9577ff4a22a046512fd416

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