Skip to content

Commit

Permalink
Use fast approximation of exp
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom committed Feb 2, 2024
1 parent 82a80b8 commit 1273074
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
16 changes: 16 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ num = "0.4"
chumsky = "1.0.0-alpha.4"
nalgebra = "0.32"
kurbo = "0.10"
fast-math = "0.1"

truck-modeling = "0.5.*"
truck-polymesh = "0.5.*"
truck-meshalgo = "*"
truck-topology = "*"
truck-topology = "*"
3 changes: 2 additions & 1 deletion eq/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ rust-version = "1.71"
[dependencies]
heapless.workspace = true
num.workspace = true
fast-math.workspace = true

chumsky.workspace = true
nalgebra.workspace = true
nalgebra.workspace = true
6 changes: 4 additions & 2 deletions eq/src/dumbass_solve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,13 +256,15 @@ impl DumbassSolver {
// the proportion of variables which are non-zero
let total_terms = st.vars.len() as f64;
for mut col in j.column_iter_mut() {
let exp_sum = col.iter().fold(0.0, |acc, x| acc + x.exp());
let exp_sum = col
.iter()
.fold(0.0, |acc, x| acc + fast_math::exp(*x as f32) as f64);
let terms_non_zero = col
.iter()
.map(|j| *j == 0.0)
.fold(0.0, |acc, zero| acc + if zero { 0.0 } else { 1.0 });
for j in col.iter_mut() {
*j *= j.exp() / exp_sum * terms_non_zero / total_terms;
*j *= fast_math::exp(*j as f32) as f64 / exp_sum * terms_non_zero / total_terms;
}
}

Expand Down

0 comments on commit 1273074

Please sign in to comment.