Skip to content

Commit

Permalink
remove float match literal
Browse files Browse the repository at this point in the history
  • Loading branch information
jcmgray committed May 8, 2024
1 parent d1ea4f8 commit 369260b
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -963,8 +963,15 @@ fn optimize_random_greedy_track_flops(
use_ssa: Option<bool>,
) -> (Vec<Vec<Node>>, Score) {
py.allow_threads(|| {
let (costmodmin, costmodmax) = costmod.unwrap_or((0.1, 4.0));
let (tempmin, tempmax) = temperature.unwrap_or((0.001, 1.0));
let (costmod_min, costmod_max) = costmod.unwrap_or((0.1, 4.0));
let costmod_diff = (costmod_max - costmod_min).abs();
let is_const_costmod = costmod_diff < Score::EPSILON;

let (temp_min, temp_max) = temperature.unwrap_or((0.001, 1.0));
let log_temp_min = Score::ln(temp_min);
let log_temp_max = Score::ln(temp_max);
let log_temp_diff = (log_temp_max - log_temp_min).abs();
let is_const_temp = log_temp_diff < Score::EPSILON;

let mut rng = match seed {
Some(seed) => rand::rngs::StdRng::seed_from_u64(seed),
Expand All @@ -982,22 +989,21 @@ fn optimize_random_greedy_track_flops(
let mut best_path = None;
let mut best_flops = f32::INFINITY;

let logtempmin = f32::ln(tempmin);
let logtempmax = f32::ln(tempmax);

for seed in seeds {
let mut cp = cp0.clone();

// uniform sample for costmod
let costmod = match costmodmax - costmodmin {
0.0 => costmodmin,
diff => costmodmin + rng.gen::<f32>() * diff,
let costmod = if is_const_costmod {
costmod_min
} else {
costmod_min + rng.gen::<f32>() * costmod_diff
};

// log-uniform sample for temperature
let temperature = match logtempmax - logtempmin {
0.0 => tempmin,
diff => f32::exp(logtempmin + rng.gen::<f32>() * diff),
let temperature = if is_const_temp {
temp_min
} else {
f32::exp(log_temp_min + rng.gen::<f32>() * log_temp_diff)
};

// greedily contract each connected subgraph
Expand Down

0 comments on commit 369260b

Please sign in to comment.