-
Notifications
You must be signed in to change notification settings - Fork 5.5k
refactor: use unitfloat in more places #14396
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
Changes from 4 commits
b46c1e9
d68720c
d6fccf7
a39e5f9
2388799
5e6758a
d06309e
70295b3
933a157
856a63c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -60,7 +60,7 @@ class ThreadLocalOverloadStateImpl : public ThreadLocalOverloadState { | |
| void setState(NamedOverloadActionSymbolTable::Symbol action, OverloadActionState state) { | ||
| actions_[action.index()] = state; | ||
| if (scaled_timer_action_.has_value() && scaled_timer_action_.value() == action) { | ||
| scaled_timer_manager_->setScaleFactor(1 - state.value()); | ||
| scaled_timer_manager_->setScaleFactor(UnitFloat(1 - state.value().value())); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -86,7 +86,7 @@ class ThresholdTriggerImpl final : public OverloadAction::Trigger { | |
| const OverloadActionState state = actionState(); | ||
| state_ = | ||
| value >= threshold_ ? OverloadActionState::saturated() : OverloadActionState::inactive(); | ||
| return state.value() != actionState().value(); | ||
| return state.value().value() != actionState().value().value(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you are going to fall back to this, I don't think we've actually improved anything, right? 2 other options I've thought of:
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This makes the floating point equality comparison visible instead of hiding it behind
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In this file, on line 63, you set the value to 1-value. If this is not exact, then we have a potential problem, right?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And if you still don't like the approximate comparison (which I can understand) it looks like it would be easy enough for you to replace the 1-value pattern with an exactness-preserving inversion operation. I think if you just pull the floats out and compare them then this is a bit of a leaky abstraction, right?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see the 1-value on line 63, but I'm having trouble understanding the potential problem. Are you worried that
UnitFloat only guarantees that if you call
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Talked offline with @jmarantz; added comments and |
||
| } | ||
|
|
||
| OverloadActionState actionState() const override { return state_; } | ||
|
|
@@ -117,7 +117,7 @@ class ScaledTriggerImpl final : public OverloadAction::Trigger { | |
| state_ = OverloadActionState( | ||
| UnitFloat((value - scaling_threshold_) / (saturated_threshold_ - scaling_threshold_))); | ||
| } | ||
| return state_.value() != old_state.value(); | ||
| return state_.value().value() != old_state.value().value(); | ||
| } | ||
|
|
||
| OverloadActionState actionState() const override { return state_; } | ||
|
|
@@ -258,7 +258,7 @@ bool OverloadAction::updateResourcePressure(const std::string& name, double pres | |
| } | ||
| const auto trigger_new_state = it->second->actionState(); | ||
| active_gauge_.set(trigger_new_state.isSaturated() ? 1 : 0); | ||
| scale_percent_gauge_.set(trigger_new_state.value() * 100); | ||
| scale_percent_gauge_.set(trigger_new_state.value().value() * 100); | ||
|
|
||
| { | ||
| // Compute the new state as the maximum over all trigger states. | ||
|
|
@@ -272,7 +272,7 @@ bool OverloadAction::updateResourcePressure(const std::string& name, double pres | |
| state_ = new_state; | ||
| } | ||
|
|
||
| return state_.value() != old_state.value(); | ||
| return state_.value().value() != old_state.value().value(); | ||
| } | ||
|
|
||
| OverloadActionState OverloadAction::getState() const { return state_; } | ||
|
|
||
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.
Are there any usages of this where the precision downgrade will make a difference?
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.
No, this might make a difference of a few milliseconds on a 10 minute timer but that's not worth worrying about.