Utilities Module

The bayes_hdc.utils module provides utility functions.

bayes_hdc.utils.normalize(x, axis=-1, eps=1e-08)[source]

Normalize vectors to unit length.

Parameters:
  • x (Array) – Input array

  • axis (int) – Axis along which to normalize (default: -1)

  • eps (float) – Small constant to avoid division by zero

Return type:

Array

bayes_hdc.utils.benchmark_function(fn, *args, num_trials=100, warmup=10, **kwargs)[source]

Benchmark a JAX function with proper warmup and async handling.

Parameters:
  • fn (Callable[[...], Any]) – Function to benchmark

  • *args (Any) – Positional arguments to fn

  • num_trials (int) – Number of trials to run

  • warmup (int) – Number of warmup trials

  • **kwargs (Any) – Keyword arguments to fn

Returns:

Dictionary with timing statistics (mean, std, min, max, median in ms)

Return type:

dict[str, float | int]