From 69a4bafb322f7aad8ffd0c622cff70a891b03f33 Mon Sep 17 00:00:00 2001 From: Arun Isaac Date: Tue, 15 Jul 2025 01:10:30 +0100 Subject: Add pool subcommand. * pyhegp/pyhegp.py: Import namedtuple from collections, and read_summary from pyhegp.serialization. (Stats): New type. (pool_stats, pool): New functions. * tests/test_pyhegp.py: Import Stats and pool_stats from pyhegp.pyhegp. (test_pool_stats): New test. --- tests/test_pyhegp.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'tests/test_pyhegp.py') diff --git a/tests/test_pyhegp.py b/tests/test_pyhegp.py index 61358e5..2d3e0b8 100644 --- a/tests/test_pyhegp.py +++ b/tests/test_pyhegp.py @@ -21,7 +21,23 @@ from hypothesis.extra.numpy import arrays, array_shapes import numpy as np from pytest import approx -from pyhegp.pyhegp import hegp_encrypt, hegp_decrypt, random_key +from pyhegp.pyhegp import Stats, hegp_encrypt, hegp_decrypt, random_key, pool_stats + +@given(st.lists(st.lists(arrays("float64", + st.shared(array_shapes(min_dims=1, max_dims=1), + key="pool-vector-length"), + elements=st.floats(min_value=-100, max_value=100)), + min_size=2), + min_size=1)) +def test_pool_stats(pools): + combined_pool = sum(pools, []) + pooled_stats = pool_stats([Stats(len(pool), + np.mean(pool, axis=0), + np.std(pool, axis=0, ddof=1)) + for pool in pools]) + assert (pooled_stats.n == len(combined_pool) + and pooled_stats.mean == approx(np.mean(combined_pool, axis=0)) + and pooled_stats.std == approx(np.std(combined_pool, axis=0, ddof=1))) @given(st.one_of( arrays("int32", -- cgit v1.2.3