diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index a300226e9..d548fbd4e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -104,7 +104,7 @@ repos: # Enforce that type annotations are used instead of type comments - id: python-use-type-annotations - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.8.6 + rev: v0.9.1 hooks: # Run the linter. - id: ruff diff --git a/benchmark/blobs_benchmark_visualiser.py b/benchmark/blobs_benchmark_visualiser.py index 899819bd5..302fb65ac 100644 --- a/benchmark/blobs_benchmark_visualiser.py +++ b/benchmark/blobs_benchmark_visualiser.py @@ -66,8 +66,8 @@ def plot_benchmarking_results(data): for i, metric in enumerate(metrics): ax = axs[i] ax.set_title( - f'{metric.replace("_", " ").title()} vs ' - f'Coreset Size (n_samples = {n_samples})', + f"{metric.replace('_', ' ').title()} vs " + f"Coreset Size (n_samples = {n_samples})", fontsize=14, ) @@ -83,7 +83,7 @@ def plot_benchmarking_results(data): ax.plot(coreset_sizes, metric_values, marker="o", label=algo) ax.set_xlabel("Coreset Size") - ax.set_ylabel(f'{metric.replace("_", " ").title()}') + ax.set_ylabel(f"{metric.replace('_', ' ').title()}") ax.set_yscale("log") # log scale for better visualization ax.legend() diff --git a/coreax/util.py b/coreax/util.py index a50192fca..b60c4fdb9 100644 --- a/coreax/util.py +++ b/coreax/util.py @@ -434,8 +434,7 @@ def speed_comparison_test( ) else: _logger.info( - "Compilation time: %s ± %s per run " - "(mean ± std. dev. of %s runs)", + "Compilation time: %s ± %s per run (mean ± std. dev. of %s runs)", format_time(mean[0].item()), format_time(std[0].item()), num_runs, diff --git a/examples/herding_approximate_gram_matrix.py b/examples/herding_approximate_gram_matrix.py index cc93a1e05..3a39a3927 100644 --- a/examples/herding_approximate_gram_matrix.py +++ b/examples/herding_approximate_gram_matrix.py @@ -138,8 +138,7 @@ def main(out_path: Optional[Path] = None) -> tuple[float, float]: ) plt.axis("off") plt.title( - f"Stein kernel herding, m={coreset_size}, " - f"MMD={round(float(herding_mmd), 6)}" + f"Stein kernel herding, m={coreset_size}, MMD={round(float(herding_mmd), 6)}" ) plt.show() @@ -150,7 +149,7 @@ def main(out_path: Optional[Path] = None) -> tuple[float, float]: s=10, color="red", ) - plt.title(f"Random, m={coreset_size}, " f"MMD={round(float(random_mmd), 6)}") + plt.title(f"Random, m={coreset_size}, MMD={round(float(random_mmd), 6)}") plt.axis("off") if out_path is not None: diff --git a/examples/herding_basic.py b/examples/herding_basic.py index 0a97fa138..1cd34d037 100644 --- a/examples/herding_basic.py +++ b/examples/herding_basic.py @@ -159,9 +159,7 @@ def main(out_path: Optional[Path] = None) -> tuple[float, float, float, float]: color="red", ) plt.axis("off") - plt.title( - f"Kernel herding, m={coreset_size}, " f"MMD={round(float(herding_mmd), 6)}" - ) + plt.title(f"Kernel herding, m={coreset_size}, MMD={round(float(herding_mmd), 6)}") plt.show() plt.scatter(x[:, 0], x[:, 1], s=2.0, alpha=0.1) @@ -172,7 +170,7 @@ def main(out_path: Optional[Path] = None) -> tuple[float, float, float, float]: color="red", ) plt.axis("off") - plt.title(f"RP Cholesky, m={coreset_size}, " f"MMD={round(float(rpc_mmd), 6)}") + plt.title(f"RP Cholesky, m={coreset_size}, MMD={round(float(rpc_mmd), 6)}") plt.show() plt.scatter(x[:, 0], x[:, 1], s=2.0, alpha=0.1) @@ -183,7 +181,7 @@ def main(out_path: Optional[Path] = None) -> tuple[float, float, float, float]: color="red", ) plt.axis("off") - plt.title(f"Stein thinning, m={coreset_size}, " f"MMD={round(float(stein_mmd), 6)}") + plt.title(f"Stein thinning, m={coreset_size}, MMD={round(float(stein_mmd), 6)}") plt.show() plt.scatter(x[:, 0], x[:, 1], s=2.0, alpha=0.1) @@ -193,7 +191,7 @@ def main(out_path: Optional[Path] = None) -> tuple[float, float, float, float]: s=10, color="red", ) - plt.title(f"Random, m={coreset_size}, " f"MMD={round(float(random_mmd), 6)}") + plt.title(f"Random, m={coreset_size}, MMD={round(float(random_mmd), 6)}") plt.axis("off") if out_path is not None: diff --git a/examples/herding_basic_weighted.py b/examples/herding_basic_weighted.py index d375493f4..de8f815dc 100644 --- a/examples/herding_basic_weighted.py +++ b/examples/herding_basic_weighted.py @@ -163,9 +163,7 @@ def main(out_path: Optional[Path] = None) -> tuple[float, float, float, float]: color="red", ) plt.axis("off") - plt.title( - f"Kernel herding, m={coreset_size}, " f"MMD={round(float(herding_mmd), 6)}" - ) + plt.title(f"Kernel herding, m={coreset_size}, MMD={round(float(herding_mmd), 6)}") plt.show() plt.scatter(x[:, 0], x[:, 1], s=2.0, alpha=0.1) @@ -176,7 +174,7 @@ def main(out_path: Optional[Path] = None) -> tuple[float, float, float, float]: color="red", ) plt.axis("off") - plt.title(f"Stein thinning, m={coreset_size}, " f"MMD={round(float(stein_mmd), 6)}") + plt.title(f"Stein thinning, m={coreset_size}, MMD={round(float(stein_mmd), 6)}") plt.show() plt.scatter(x[:, 0], x[:, 1], s=2.0, alpha=0.1) @@ -187,7 +185,7 @@ def main(out_path: Optional[Path] = None) -> tuple[float, float, float, float]: color="red", ) plt.axis("off") - plt.title(f"RP Cholesky, m={coreset_size}, " f"MMD={round(float(rpc_mmd), 6)}") + plt.title(f"RP Cholesky, m={coreset_size}, MMD={round(float(rpc_mmd), 6)}") plt.show() plt.scatter(x[:, 0], x[:, 1], s=2.0, alpha=0.1) @@ -197,7 +195,7 @@ def main(out_path: Optional[Path] = None) -> tuple[float, float, float, float]: s=10, color="red", ) - plt.title(f"Random, m={coreset_size}, " f"MMD={round(float(random_mmd), 6)}") + plt.title(f"Random, m={coreset_size}, MMD={round(float(random_mmd), 6)}") plt.axis("off") if out_path is not None: diff --git a/examples/herding_duo_composite_kernel.py b/examples/herding_duo_composite_kernel.py index 19fdca6b6..967a3aa64 100644 --- a/examples/herding_duo_composite_kernel.py +++ b/examples/herding_duo_composite_kernel.py @@ -133,9 +133,7 @@ def main(out_path: Optional[Path] = None) -> tuple[float, float, float, float]: color="red", ) plt.axis("off") - plt.title( - f"Kernel herding, m={coreset_size}, " f"MMD={round(float(herding_mmd), 6)}" - ) + plt.title(f"Kernel herding, m={coreset_size}, MMD={round(float(herding_mmd), 6)}") plt.show() plt.scatter(x[:, 0], x[:, 1], s=2.0, alpha=0.1) @@ -145,7 +143,7 @@ def main(out_path: Optional[Path] = None) -> tuple[float, float, float, float]: s=10, color="red", ) - plt.title(f"Random, m={coreset_size}, " f"MMD={round(float(random_mmd), 6)}") + plt.title(f"Random, m={coreset_size}, MMD={round(float(random_mmd), 6)}") plt.axis("off") if out_path is not None: diff --git a/examples/herding_refine_weighted.py b/examples/herding_refine_weighted.py index a49b94f91..8ef46b62f 100644 --- a/examples/herding_refine_weighted.py +++ b/examples/herding_refine_weighted.py @@ -173,9 +173,7 @@ def main(out_path: Optional[Path] = None) -> tuple[float, float, float, float]: color="red", ) plt.axis("off") - plt.title( - f"Kernel herding, m={coreset_size}, " f"MMD={round(float(herding_mmd), 6)}" - ) + plt.title(f"Kernel herding, m={coreset_size}, MMD={round(float(herding_mmd), 6)}") plt.show() plt.scatter(x[:, 0], x[:, 1], s=2.0, alpha=0.1) @@ -186,7 +184,7 @@ def main(out_path: Optional[Path] = None) -> tuple[float, float, float, float]: color="red", ) plt.axis("off") - plt.title(f"RP Cholesky, m={coreset_size}, " f"MMD={round(float(rpc_mmd), 6)}") + plt.title(f"RP Cholesky, m={coreset_size}, MMD={round(float(rpc_mmd), 6)}") plt.show() plt.scatter(x[:, 0], x[:, 1], s=2.0, alpha=0.1) @@ -197,7 +195,7 @@ def main(out_path: Optional[Path] = None) -> tuple[float, float, float, float]: color="red", ) plt.axis("off") - plt.title(f"Stein thinning, m={coreset_size}, " f"MMD={round(float(stein_mmd), 6)}") + plt.title(f"Stein thinning, m={coreset_size}, MMD={round(float(stein_mmd), 6)}") plt.show() plt.scatter(x[:, 0], x[:, 1], s=2.0, alpha=0.1) @@ -207,7 +205,7 @@ def main(out_path: Optional[Path] = None) -> tuple[float, float, float, float]: s=10, color="red", ) - plt.title(f"Random, m={coreset_size}, " f"MMD={round(float(random_mmd), 6)}") + plt.title(f"Random, m={coreset_size}, MMD={round(float(random_mmd), 6)}") plt.axis("off") if out_path is not None: diff --git a/examples/herding_stein_weighted.py b/examples/herding_stein_weighted.py index 8104bb5bc..7be15d1a4 100644 --- a/examples/herding_stein_weighted.py +++ b/examples/herding_stein_weighted.py @@ -152,8 +152,7 @@ def main(out_path: Optional[Path] = None) -> tuple[float, float]: ) plt.axis("off") plt.title( - f"Stein kernel herding, m={coreset_size}, " - f"MMD={round(float(herding_mmd), 6)}" + f"Stein kernel herding, m={coreset_size}, MMD={round(float(herding_mmd), 6)}" ) plt.show() @@ -164,7 +163,7 @@ def main(out_path: Optional[Path] = None) -> tuple[float, float]: s=10, color="red", ) - plt.title(f"Random, m={coreset_size}, " f"MMD={round(float(random_mmd), 6)}") + plt.title(f"Random, m={coreset_size}, MMD={round(float(random_mmd), 6)}") plt.axis("off") if out_path is not None: diff --git a/examples/herding_stein_weighted_ssm.py b/examples/herding_stein_weighted_ssm.py index 4889b0b48..710463165 100644 --- a/examples/herding_stein_weighted_ssm.py +++ b/examples/herding_stein_weighted_ssm.py @@ -165,8 +165,7 @@ def main(out_path: Optional[Path] = None) -> tuple[float, float]: ) plt.axis("off") plt.title( - f"Stein kernel herding, m={coreset_size}, " - f"MMD={round(float(herding_mmd), 6)}" + f"Stein kernel herding, m={coreset_size}, MMD={round(float(herding_mmd), 6)}" ) plt.show() @@ -177,7 +176,7 @@ def main(out_path: Optional[Path] = None) -> tuple[float, float]: s=10, color="red", ) - plt.title(f"Random, m={coreset_size}, " f"MMD={round(float(random_mmd), 6)}") + plt.title(f"Random, m={coreset_size}, MMD={round(float(random_mmd), 6)}") plt.axis("off") if out_path is not None: diff --git a/tests/unit/test_solvers.py b/tests/unit/test_solvers.py index fc8f8db7e..340bf882d 100644 --- a/tests/unit/test_solvers.py +++ b/tests/unit/test_solvers.py @@ -1994,15 +1994,15 @@ def test_map_reduce_diverse_selection(self): coreset, _ = solver.reduce(Data(dataset)) selected_indices = coreset.nodes.data - assert jnp.any( - selected_indices >= coreset_size - ), "MapReduce should select points beyond the first few" + assert jnp.any(selected_indices >= coreset_size), ( + "MapReduce should select points beyond the first few" + ) # Check if there are indices from different partitions partitions_represented = jnp.unique(selected_indices // leaf_size) - assert ( - len(partitions_represented) > 1 - ), "MapReduce should select points from multiple partitions" + assert len(partitions_represented) > 1, ( + "MapReduce should select points from multiple partitions" + ) def test_map_reduce_analytic(self): r"""