From 420bb62330d722bb7ce8d7a65319440b30a7b327 Mon Sep 17 00:00:00 2001 From: biondizzle Date: Sat, 23 May 2026 20:02:35 +0000 Subject: [PATCH] auto: pre-test commit --- test_mapping.py | 50 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 test_mapping.py diff --git a/test_mapping.py b/test_mapping.py new file mode 100644 index 00000000..11eb7cf1 --- /dev/null +++ b/test_mapping.py @@ -0,0 +1,50 @@ +#!/usr/bin/env python3 +""" +Test SMEM-P coordinate mapping for collisions. +Mapping: (m,n) -> ((m, n%16), 0, ((n//16)%4, n//64), 0) +Offset: m*64 + (n%16) + ((n//16)%4)*16 + (n//64)*8192 +""" + +def compute_offset(m, n): + n0 = n % 16 + n1 = (n // 16) % 4 + n2 = n // 64 + offset = m * 64 + n0 + n1 * 16 + n2 * 8192 + return offset, (m, n0, n1, n2) + +# Test bijection +offsets = set() +collisions = [] + +for m in range(128): + for n in range(128): + offset, _ = compute_offset(m, n) + if offset in offsets: + collisions.append(((m,n), offset)) + offsets.add(offset) + +print(f"Total positions: {128*128} = {128*128}") +print(f"Unique offsets: {len(offsets)}") +print(f"Collisions: {len(collisions)}") +if collisions: + print("First few collisions:", collisions[:5]) + +# Check offset range +min_offset = min(offsets) +max_offset = max(offsets) +print(f"Offset range: {min_offset} .. {max_offset}") +print(f"Expected range: 0 .. 16383") + +# Test specific coordinates +test_coords = [(0,0), (0,1), (0,15), (0,16), (0,63), (0,64), (0,127), + (1,0), (1,1), (1,127), + (127,0), (127,63), (127,64), (127,127)] +print("\nSample offsets:") +for m,n in test_coords: + offset, decomp = compute_offset(m,n) + print(f"({m},{n}) -> {decomp} = offset {offset}") + +# Verify formula matches layout stride +# Layout: ((128,16),1,(4,2),1):((64,1),0,(16,8192),0) +# Stride for (m,n0,n1,n2): m*64 + n0*1 + n1*16 + n2*8192 +print("\nLayout stride check: OK" if max_offset == 16383 and len(offsets) == 16384 else "Layout mismatch") \ No newline at end of file