Skip to content

Commit

Permalink
perf: Cache value in trace_beam
Browse files Browse the repository at this point in the history
Cache value in `trace_beam` making rain simulation ~20% faster (saving
~69s on average).
  • Loading branch information
TomSchammo committed Nov 17, 2024
1 parent 9952ec2 commit 0769192
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions cpp/src/raytracing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,20 @@ constexpr tensor_size_t min_intersect_dist = 1;
const auto sphere = torch::tensor(
{nf[0].item<float>(), nf[1].item<float>(), nf[2].item<float>()});

if (beam_length < nf[3].item<float>()) {
const auto nf3_val = nf[3].item<float>();

if (beam_length < nf3_val) {
return -1;
}

if (const auto length_beam_sphere = rt::scalar(sphere, beam_normalized);
length_beam_sphere > 0.0) {

if (const auto dist_beam_sphere =
sqrt(nf[3].item<float>() * nf[3].item<float>() -
length_beam_sphere * length_beam_sphere);
sqrt(nf3_val * nf3_val - length_beam_sphere * length_beam_sphere);
dist_beam_sphere < nf[4].item<float>()) {

return nf[3].item<float>();
return nf3_val;
}
}
}
Expand Down

0 comments on commit 0769192

Please sign in to comment.