Skip to content

Commit d119c05

Browse files
committed
perf(luxtts): simplify euler_step — algebraic reduction from 7 tensor ops to 2 (3.3x faster)
1 parent cf062b8 commit d119c05

1 file changed

Lines changed: 6 additions & 15 deletions

File tree

cake-core/src/models/luxtts/euler_solver.rs

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -43,22 +43,13 @@ impl EulerSolver {
4343
v: &Tensor,
4444
t_cur: f32,
4545
t_next: f32,
46-
is_last: bool,
46+
_is_last: bool,
4747
) -> Result<Tensor> {
48-
// x_1_pred = x + (1 - t_cur) * v
49-
let x_1_pred = (x + (v * (1.0 - t_cur) as f64)?)?;
50-
51-
if is_last {
52-
// Last step: return x_1_pred directly
53-
return Ok(x_1_pred);
54-
}
55-
56-
// x_0_pred = x - t_cur * v
57-
let x_0_pred = (x - (v * t_cur as f64)?)?;
58-
59-
// x_next = (1 - t_next) * x_0_pred + t_next * x_1_pred
60-
let result = ((&x_0_pred * (1.0 - t_next) as f64)? + (&x_1_pred * t_next as f64)?)?;
61-
Ok(result)
48+
// Simplified: x_next = x + (t_next - t_cur) * v
49+
// (algebraically equivalent to the x_0_pred/x_1_pred formulation)
50+
// Last step (t_next=1.0): x + (1 - t_cur) * v = x_1_pred
51+
let dt = (t_next - t_cur) as f64;
52+
Ok((x + (v * dt)?)?)
6253
}
6354
}
6455

0 commit comments

Comments
 (0)