♻️🍱 config, cli, vanth, vanth_derive, varo: Reformatted code and added editor configuration files

- Added `.zed/settings.json` to configure rust-analyzer with `leptosfmt`.
- Created `rustfmt.toml` with max width 120 and comment wrapping settings.
- Applied consistent formatting across all modified crates using rustfmt.
- Reorganized import statements and improved code style in multiple modules.
This commit is contained in:
Markus Scully 2025-08-07 12:49:33 +03:00
parent 87957bfbf8
commit 9e7979931c
Signed by: mascully
GPG key ID: 93CA5814B698101C
15 changed files with 141 additions and 161 deletions

View file

@ -1,5 +1,5 @@
use rand_core::{RngCore, SeedableRng};
use rand_chacha::ChaCha8Rng;
use rand_core::{RngCore, SeedableRng};
use serde::{Deserialize, Serialize};
use std::f32::consts::PI;
use vanth_derive::Vanth;
@ -10,11 +10,15 @@ pub struct Rng {
}
pub fn rng_new() -> Rng {
Rng { inner: ChaCha8Rng::from_seed([0u8; 32]) }
Rng {
inner: ChaCha8Rng::from_seed([0u8; 32]),
}
}
pub fn rng_from_seed(seed: [u8; 32]) -> Rng {
Rng { inner: ChaCha8Rng::from_seed(seed) }
Rng {
inner: ChaCha8Rng::from_seed(seed),
}
}
pub fn rng_set_stream(rng: &mut Rng, stream: u64) {
@ -82,7 +86,7 @@ impl From<f32> for Score {
#[derive(Clone, Debug, Deserialize, Serialize, Vanth)]
pub struct OptimizationResult {
/// List of pairs of evaluation score and Rng used to generate the value.
pub values: Vec<(Rng, f32)>
pub values: Vec<(Rng, f32)>,
}
pub fn optimize<T: Varo>(evaluator: impl Fn(T) -> Score, rng: &mut Rng, rounds: u32) -> OptimizationResult {

View file

@ -1,24 +1,24 @@
use varo::{optimize, Rng, Score, Varo};
use varo::{Rng, Score, Varo, optimize};
#[test]
fn test_optimize() {
struct Foo {
x: f32,
}
impl Varo for Foo {
fn next(digest: &mut varo::Rng) -> Self {
let x = varo::rng_gen_f32(digest) * 10.0;
Foo { x }
}
}
fn evaluate(foo: Foo) -> Score {
let x = foo.x;
let score = -0.9 * x.powi(3) + 2.6 * x.powi(2) - 4.0 * x;
score.into()
}
let mut rng = varo::rng_new();
let optimization_result = optimize(evaluate, &mut rng, 10);
assert_eq!(optimization_result.values.len(), 10);