repixelizer/tests/test_analysis.py

28 lines
1,012 B
Python
Raw Normal View History

from __future__ import annotations
import numpy as np
2026-04-24 00:03:05 +01:00
from repixelizer.analysis import analyze_phase_field_source, analyze_tile_graph_source
2026-04-24 00:03:05 +01:00
def test_phase_field_source_analysis_cpu_device_matches_default_path() -> None:
source = np.zeros((8, 8, 4), dtype=np.float32)
source[..., 3] = 1.0
source[2:6, 3:5, :3] = np.asarray([1.0, 0.8, 0.2], dtype=np.float32)
2026-04-24 00:03:05 +01:00
default = analyze_phase_field_source(source, seed=7)
accelerated = analyze_phase_field_source(source, seed=7, device="cpu")
assert np.allclose(accelerated.edge_map, default.edge_map, atol=1e-5)
2026-04-23 17:00:24 +01:00
assert not hasattr(accelerated, "cluster_map")
2026-04-23 03:56:03 +01:00
2026-04-23 04:18:24 +01:00
def test_tile_graph_source_analysis_is_edge_only() -> None:
2026-04-23 03:56:03 +01:00
source = np.zeros((8, 8, 4), dtype=np.float32)
source[..., 3] = 1.0
source[2:6, 3:5, :3] = np.asarray([1.0, 0.8, 0.2], dtype=np.float32)
2026-04-23 04:18:24 +01:00
analysis = analyze_tile_graph_source(source, device="cpu")
2026-04-23 03:56:03 +01:00
assert analysis.edge_map.shape == source.shape[:2]
2026-04-23 04:18:24 +01:00
assert not hasattr(analysis, "cluster_map")