style: apply rustfmt across all crates and demos
Consistent formatting pass: line wrapping, import sorting, trailing whitespace removal, let-chain indentation, merged derive attributes, and unsafe block reformatting. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
This commit is contained in:
@@ -59,7 +59,7 @@ impl Default for BenchmarkConfig {
|
||||
|
||||
impl BenchmarkConfig {
|
||||
/// Create config for quick benchmarking (fewer problems, lower resolutions)
|
||||
#[must_use]
|
||||
#[must_use]
|
||||
pub fn quick() -> Self {
|
||||
Self {
|
||||
resolutions: vec![32, 64],
|
||||
@@ -71,7 +71,7 @@ impl BenchmarkConfig {
|
||||
}
|
||||
|
||||
/// Create config for comprehensive benchmarking
|
||||
#[must_use]
|
||||
#[must_use]
|
||||
pub fn comprehensive() -> Self {
|
||||
Self {
|
||||
resolutions: vec![32, 64, 128, 256],
|
||||
@@ -83,7 +83,7 @@ impl BenchmarkConfig {
|
||||
}
|
||||
|
||||
/// Set PDE type
|
||||
#[must_use]
|
||||
#[must_use]
|
||||
pub fn with_pde_type(mut self, pde_type: PDEType) -> Self {
|
||||
self.pde_type = pde_type;
|
||||
self
|
||||
@@ -103,7 +103,7 @@ pub enum PDEType {
|
||||
|
||||
impl PDEType {
|
||||
/// Get human-readable name
|
||||
#[must_use]
|
||||
#[must_use]
|
||||
pub fn name(&self) -> &'static str {
|
||||
match self {
|
||||
Self::Poisson => "Poisson",
|
||||
@@ -154,35 +154,35 @@ impl BenchmarkResult {
|
||||
}
|
||||
|
||||
/// Set solve time
|
||||
#[must_use]
|
||||
#[must_use]
|
||||
pub fn with_time(mut self, time_ms: f64) -> Self {
|
||||
self.solve_time_ms = time_ms;
|
||||
self
|
||||
}
|
||||
|
||||
/// Set L2 error
|
||||
#[must_use]
|
||||
#[must_use]
|
||||
pub fn with_l2_error(mut self, error: f64) -> Self {
|
||||
self.l2_error = Some(error);
|
||||
self
|
||||
}
|
||||
|
||||
/// Set max error
|
||||
#[must_use]
|
||||
#[must_use]
|
||||
pub fn with_max_error(mut self, error: f64) -> Self {
|
||||
self.max_error = Some(error);
|
||||
self
|
||||
}
|
||||
|
||||
/// Set memory usage
|
||||
#[must_use]
|
||||
#[must_use]
|
||||
pub fn with_memory(mut self, memory_mb: f64) -> Self {
|
||||
self.memory_mb = memory_mb;
|
||||
self
|
||||
}
|
||||
|
||||
/// Set iterations
|
||||
#[must_use]
|
||||
#[must_use]
|
||||
pub fn with_iterations(mut self, iterations: usize) -> Self {
|
||||
self.iterations = Some(iterations);
|
||||
self
|
||||
@@ -253,7 +253,7 @@ impl BenchmarkSummary {
|
||||
}
|
||||
|
||||
/// Compute speedup factor vs another solver
|
||||
#[must_use]
|
||||
#[must_use]
|
||||
pub fn speedup_vs(&self, other: &Self) -> f64 {
|
||||
other.avg_time_ms / self.avg_time_ms
|
||||
}
|
||||
@@ -290,7 +290,7 @@ pub struct FdmSolver {
|
||||
|
||||
impl FdmSolver {
|
||||
/// Create a new FDM solver
|
||||
#[must_use]
|
||||
#[must_use]
|
||||
pub fn new(resolution: usize) -> Self {
|
||||
let h = 1.0 / (resolution - 1) as f64;
|
||||
Self {
|
||||
@@ -302,14 +302,14 @@ impl FdmSolver {
|
||||
}
|
||||
|
||||
/// Set maximum iterations
|
||||
#[must_use]
|
||||
#[must_use]
|
||||
pub fn with_max_iterations(mut self, max_iter: usize) -> Self {
|
||||
self.max_iterations = max_iter;
|
||||
self
|
||||
}
|
||||
|
||||
/// Set convergence tolerance
|
||||
#[must_use]
|
||||
#[must_use]
|
||||
pub fn with_tolerance(mut self, tol: f64) -> Self {
|
||||
self.tolerance = tol;
|
||||
self
|
||||
@@ -322,7 +322,7 @@ impl FdmSolver {
|
||||
///
|
||||
/// # Returns
|
||||
/// Tuple of (solution, iterations)
|
||||
#[must_use]
|
||||
#[must_use]
|
||||
pub fn solve_jacobi(&self, rhs: &[f64]) -> (Vec<f64>, usize) {
|
||||
let n = self.resolution;
|
||||
let h2 = self.h * self.h;
|
||||
@@ -367,7 +367,7 @@ impl FdmSolver {
|
||||
}
|
||||
|
||||
/// Solve using Gauss-Seidel iteration (faster convergence than Jacobi).
|
||||
#[must_use]
|
||||
#[must_use]
|
||||
pub fn solve_gauss_seidel(&self, rhs: &[f64]) -> (Vec<f64>, usize) {
|
||||
let n = self.resolution;
|
||||
let h2 = self.h * self.h;
|
||||
@@ -410,7 +410,7 @@ impl FdmSolver {
|
||||
/// Solve using Successive Over-Relaxation (SOR) - even faster convergence.
|
||||
///
|
||||
/// Optimal omega for Poisson on unit square: ω = 2 / (1 + sin(π*h))
|
||||
#[must_use]
|
||||
#[must_use]
|
||||
pub fn solve_sor(&self, rhs: &[f64], omega: Option<f64>) -> (Vec<f64>, usize) {
|
||||
let n = self.resolution;
|
||||
let h2 = self.h * self.h;
|
||||
@@ -462,7 +462,7 @@ impl FdmSolver {
|
||||
}
|
||||
|
||||
/// Estimate memory usage in MB
|
||||
#[must_use]
|
||||
#[must_use]
|
||||
pub fn memory_usage_mb(&self) -> f64 {
|
||||
// Two N×N arrays of f64 (8 bytes each)
|
||||
2.0 * (self.resolution * self.resolution * 8) as f64 / (1024.0 * 1024.0)
|
||||
@@ -492,7 +492,7 @@ pub struct FemSolver {
|
||||
|
||||
impl FemSolver {
|
||||
/// Create a new FEM solver
|
||||
#[must_use]
|
||||
#[must_use]
|
||||
pub fn new(resolution: usize) -> Self {
|
||||
let h = 1.0 / (resolution - 1) as f64;
|
||||
Self {
|
||||
@@ -504,14 +504,14 @@ impl FemSolver {
|
||||
}
|
||||
|
||||
/// Set maximum iterations
|
||||
#[must_use]
|
||||
#[must_use]
|
||||
pub fn with_max_iterations(mut self, max_iter: usize) -> Self {
|
||||
self.max_iterations = max_iter;
|
||||
self
|
||||
}
|
||||
|
||||
/// Set convergence tolerance
|
||||
#[must_use]
|
||||
#[must_use]
|
||||
pub fn with_tolerance(mut self, tol: f64) -> Self {
|
||||
self.tolerance = tol;
|
||||
self
|
||||
@@ -527,7 +527,7 @@ impl FemSolver {
|
||||
///
|
||||
/// # Returns
|
||||
/// Tuple of (solution, iterations)
|
||||
#[must_use]
|
||||
#[must_use]
|
||||
pub fn solve_cg(&self, rhs: &[f64]) -> (Vec<f64>, usize) {
|
||||
let n = self.resolution;
|
||||
|
||||
@@ -649,7 +649,7 @@ impl FemSolver {
|
||||
}
|
||||
|
||||
/// Estimate memory usage in MB
|
||||
#[must_use]
|
||||
#[must_use]
|
||||
pub fn memory_usage_mb(&self) -> f64 {
|
||||
// Four N×N arrays of f64: x, r, p, ap
|
||||
4.0 * (self.resolution * self.resolution * 8) as f64 / (1024.0 * 1024.0)
|
||||
@@ -668,7 +668,7 @@ pub struct BenchmarkRunner {
|
||||
|
||||
impl BenchmarkRunner {
|
||||
/// Create a new benchmark runner
|
||||
#[must_use]
|
||||
#[must_use]
|
||||
pub fn new(config: BenchmarkConfig) -> Self {
|
||||
Self { config }
|
||||
}
|
||||
@@ -676,7 +676,7 @@ impl BenchmarkRunner {
|
||||
/// Run benchmarks for FDM and FEM solvers
|
||||
///
|
||||
/// Note: FNO benchmarks require a trained model and are run separately.
|
||||
#[must_use]
|
||||
#[must_use]
|
||||
pub fn run_classical_benchmarks(&self) -> Vec<BenchmarkResult> {
|
||||
let mut results = Vec::new();
|
||||
|
||||
@@ -792,7 +792,7 @@ impl BenchmarkRunner {
|
||||
}
|
||||
|
||||
/// Run multiple benchmark iterations and compute summary statistics
|
||||
#[must_use]
|
||||
#[must_use]
|
||||
pub fn run_with_statistics(&self, n_runs: usize) -> Vec<BenchmarkSummary> {
|
||||
let mut all_results: Vec<Vec<BenchmarkResult>> = Vec::new();
|
||||
|
||||
@@ -833,9 +833,11 @@ impl BenchmarkRunner {
|
||||
|
||||
for result in results {
|
||||
let l2_str = result
|
||||
.l2_error.map_or_else(|| "N/A".to_string(), |e| format!("{e:.2e}"));
|
||||
.l2_error
|
||||
.map_or_else(|| "N/A".to_string(), |e| format!("{e:.2e}"));
|
||||
let iter_str = result
|
||||
.iterations.map_or_else(|| "N/A".to_string(), |i| i.to_string());
|
||||
.iterations
|
||||
.map_or_else(|| "N/A".to_string(), |i| i.to_string());
|
||||
|
||||
println!(
|
||||
"{:<12} {:>10} {:>12.2} {:>12} {:>12.2} {:>10}",
|
||||
@@ -865,7 +867,8 @@ impl BenchmarkRunner {
|
||||
|
||||
for summary in summaries {
|
||||
let l2_str = summary
|
||||
.avg_l2_error.map_or_else(|| "N/A".to_string(), |e| format!("{e:.2e}"));
|
||||
.avg_l2_error
|
||||
.map_or_else(|| "N/A".to_string(), |e| format!("{e:.2e}"));
|
||||
|
||||
println!(
|
||||
"{:<12} {:>10} {:>10.2}ms {:>10.2}ms {:>12}",
|
||||
@@ -891,7 +894,7 @@ impl BenchmarkRunner {
|
||||
///
|
||||
/// # Returns
|
||||
/// Benchmark result with timing and error metrics
|
||||
#[must_use]
|
||||
#[must_use]
|
||||
pub fn benchmark_fno(&self, model: &FNO2d<CpuBackend>, resolution: usize) -> BenchmarkResult {
|
||||
let device = CpuDevice::default();
|
||||
|
||||
@@ -991,7 +994,7 @@ impl BenchmarkRunner {
|
||||
///
|
||||
/// # Returns
|
||||
/// Vector of benchmark results for all methods and resolutions
|
||||
#[must_use]
|
||||
#[must_use]
|
||||
pub fn run_all_benchmarks(&self, model: Option<&FNO2d<CpuBackend>>) -> Vec<BenchmarkResult> {
|
||||
let mut results = Vec::new();
|
||||
|
||||
@@ -1019,7 +1022,7 @@ impl BenchmarkRunner {
|
||||
/// Compute speedup factors comparing FNO to classical methods
|
||||
///
|
||||
/// Returns a formatted string summarizing speedup results.
|
||||
#[must_use]
|
||||
#[must_use]
|
||||
pub fn compute_speedup_report(results: &[BenchmarkResult]) -> String {
|
||||
let mut report = String::new();
|
||||
report.push('\n');
|
||||
|
||||
Reference in New Issue
Block a user