boofun.core.gpu
GPU Acceleration for Boolean Function Operations.
This module provides GPU-accelerated implementations of computationally intensive operations using CuPy. Falls back to NumPy when CuPy is unavailable.
Key accelerated operations: - Walsh-Hadamard Transform (WHT) - Influence computation - Noise stability computation - Large truth table operations
- Usage:
from boofun.core.gpu import gpu_wht, is_gpu_available
- if is_gpu_available():
fourier = gpu_wht(truth_table_pm)
- else:
# Fallback to CPU fourier = cpu_wht(truth_table_pm)
Functions
|
Decorator to automatically use GPU when beneficial. |
|
Enable or disable GPU acceleration. |
|
Get the array module (numpy or cupy) for the given array. |
|
GPU-accelerated influence computation from Fourier coefficients. |
|
GPU-accelerated noise stability computation. |
|
GPU-accelerated spectral weight computation by degree. |
|
GPU-accelerated Walsh-Hadamard Transform. |
Check if GPU acceleration is available. |
|
Check if GPU acceleration is currently enabled. |
|
|
Move array to CPU. |
|
Move array to GPU if available and enabled. |
Classes
|
GPU-accelerated operations for Boolean functions. |
- boofun.core.gpu.get_array_module(arr: ndarray | cp.ndarray) type[source]
Get the array module (numpy or cupy) for the given array.
- boofun.core.gpu.to_gpu(arr: ndarray) ndarray | cp.ndarray[source]
Move array to GPU if available and enabled.
- boofun.core.gpu.gpu_walsh_hadamard(values: ndarray, in_place: bool = False) ndarray[source]
GPU-accelerated Walsh-Hadamard Transform.
Computes the WHT in O(n * 2^n) time using GPU parallelism.
- Parameters:
values – Array of 2^n values in ±1 representation
in_place – If True, modify input array (saves memory)
- Returns:
WHT result (unnormalized, on CPU)
- boofun.core.gpu.gpu_influences(fourier_coeffs: ndarray, n_vars: int = None) ndarray[source]
GPU-accelerated influence computation from Fourier coefficients.
Inf_i[f] = Σ_{S∋i} f̂(S)²
- Parameters:
fourier_coeffs – Fourier coefficients array
n_vars – Number of variables (inferred from array size if not provided)
- Returns:
Array of influences (one per variable)
- boofun.core.gpu.gpu_noise_stability(fourier_coeffs: ndarray, rho: float) float[source]
GPU-accelerated noise stability computation.
Stab_ρ[f] = Σ_S ρ^|S| · f̂(S)²
- Parameters:
fourier_coeffs – Fourier coefficients array
rho – Correlation parameter
- Returns:
Noise stability value
- boofun.core.gpu.gpu_spectral_weight_by_degree(fourier_coeffs: ndarray) ndarray[source]
GPU-accelerated spectral weight computation by degree.
W^{=k}[f] = Σ_{|S|=k} f̂(S)²
- Parameters:
fourier_coeffs – Fourier coefficients array
- Returns:
Array of weights W^{=0}, W^{=1}, …, W^{=n}
- class boofun.core.gpu.GPUBooleanFunctionOps(truth_table: ndarray)[source]
GPU-accelerated operations for Boolean functions.
Provides a high-level interface for GPU acceleration.
- __init__(truth_table: ndarray)[source]
Initialize with a truth table.
- Parameters:
truth_table – Boolean truth table (0/1 values)