From 59c66f44c69f47c9c3545cdb9c7546f9e3f0b619 Mon Sep 17 00:00:00 2001 From: Christoph Lehner Date: Sat, 15 Jun 2024 15:58:59 +0200 Subject: [PATCH] checkerboard ui --- lib/gpt/core/checkerboard.py | 8 +++++++- tests/core/core.py | 15 +++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/lib/gpt/core/checkerboard.py b/lib/gpt/core/checkerboard.py index 7762c12cf..d8775e6b5 100644 --- a/lib/gpt/core/checkerboard.py +++ b/lib/gpt/core/checkerboard.py @@ -53,7 +53,13 @@ def str_to_cb(s): assert 0 -def pick_checkerboard(cb, dst, src): +def pick_checkerboard(cb, dst, src = None): + if src is None: + src = dst + dst = gpt.lattice(src.grid.checkerboarded(gpt.redblack), src.otype) + pick_checkerboard(cb, dst, src) + return dst + assert len(src.v_obj) == len(dst.v_obj) for i in src.otype.v_idx: cgpt.lattice_pick_checkerboard(cb.tag, src.v_obj[i], dst.v_obj[i]) diff --git a/tests/core/core.py b/tests/core/core.py index 7fb4e1f6b..427d5fb8e 100755 --- a/tests/core/core.py +++ b/tests/core/core.py @@ -487,7 +487,22 @@ def correlate_test_4d(a, b, x): g.message(f"Test sparse slice: {eps}") assert eps < l.grid.precision.eps * 1e3 +################################################################################ +# Test checkerboard +################################################################################ +a = a[0] +b = b[0] +a_even = g.pick_checkerboard(g.even, a) +a_odd = g.pick_checkerboard(g.odd, a) +b[:] = 0 +g.set_checkerboard(b, a_even) +g.set_checkerboard(b, a_odd) +eps2 = g.norm2(a-b) +g.message(f"Checkerboard: {eps2}") +assert eps2 == 0.0 + ################################################################################ # Test mem_report ################################################################################ g.mem_report() +