Skip to content

Instantly share code, notes, and snippets.

View almarklein's full-sized avatar

Almar Klein almarklein

View GitHub Profile
from wgpu.gui.auto import WgpuCanvas, run
import pygfx as gfx
import pylinalg as la
import numpy as np
def set_position(ob, pos):
# compat between old and new api
if hasattr(ob, "local"):
ob.local.position = pos
"""
In https://github.com/pygfx/wgpu-py/issues/114 we tried to find a way
to invalidate numpy/memoryview views when the base memory was released.
This file lists some attempts (and related cases) that demonstrates how
thet do not work.
In the end, we've not found a way to do it.
"""
import ctypes
@almarklein
almarklein / glfwcanvas.py
Last active April 10, 2025 07:15
rendercanvas glfw playground
import sys
import time
import glfw
from rendercanvas.base import BaseRenderCanvas, BaseCanvasGroup
from rendercanvas.asyncio import loop
from rendercanvas._coreutils import SYSTEM_IS_WAYLAND, weakbind, logger
import time
import numpy as np
import imageio.v2 as iio
import pygfx as gfx
from rendercanvas.offscreen import RenderCanvas
canvas = RenderCanvas(size=(1920, 1080), pixel_ratio=1)
@almarklein
almarklein / kernel_opt.py
Created June 25, 2025 14:35
Produce optimal wglsl kernel samplers
"""
Produce WGSL code to sample a kernel with fixed weights using a trick
that uses bilinear interpolation to drastically reduce the number of texture lookups.
"""
# %%%%% Functions
import numpy as np
import scipy
@almarklein
almarklein / label_compression.py
Created January 9, 2026 10:47
label_compression.py
"""
Quick benchmark to investigate compression of labels: separate arrays vs bitpacked.
"""
import imageio.v3 as iio
import numcodecs
filename_base = os.path.abspath(os.path.join(__file__, "..", "tmp", "astronaut"))