-
Notifications
You must be signed in to change notification settings - Fork 1k
Fix compile errors for Linux #2378
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
WalkthroughThe update changes the Changes
Poem
✨ Finishing Touches
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes a Linux build error by removing the non-portable std::logf call and using the C logf function instead.
- Replace
std::logfwithlogfinTenVadModel::Impl::LogMelto compile on Linux.
Comments suppressed due to low confidence (3)
sherpa-onnx/csrc/ten-vad-model.cc:324
- Prefer using the C++
<cmath>overloadstd::log(float)instead of the globallogfto keep code in the standard namespace and avoid potential include issues:out[i] = std::log(in[i] + 1e-10f) - 20.79441541679836f;
out[i] = logf(in[i] + 1e-10) - 20.79441541679836f;
sherpa-onnx/csrc/ten-vad-model.cc:324
- [nitpick] Change the literal
1e-10to a float literal1e-10fto avoid implicit double-to-float conversions.
out[i] = logf(in[i] + 1e-10) - 20.79441541679836f;
sherpa-onnx/csrc/ten-vad-model.cc:324
- [nitpick] Extract the magic constant
20.79441541679836finto a namedconstexpr(e.g.,kLogScalingValue) for clarity and easier future modifications.
out[i] = logf(in[i] + 1e-10) - 20.79441541679836f;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
sherpa-onnx/csrc/ten-vad-model.cc (1)
321-325: Remove magic number; keep portability with an internal constant / helper.The switch from
std::logfto::logfis a pragmatic fix for the Linux build issue – LGTM.
However, the hard-coded20.79441541679836f(“log(32768 × 32768)”) is a magic number that hurts readability and invites mistakes during future refactors. Extract it into aconstexpr(or at least a namedstatic const float) so the intent is self-documenting and maintainable:- // 20.79441541679836 is log(32768*32768) - out[i] = logf(in[i] + 1e-10) - 20.79441541679836f; + // log(32768 * 32768) == 20.79441541679836 + static constexpr float kLog32768Squared = 20.79441541679836f; + out[i] = ::logf(in[i] + 1e-10f) - kLog32768Squared;(No functional change, but the code becomes self-explanatory and easier to audit.)
Somehow it fails only on Linux, but works on macos and windows.
Summary by CodeRabbit