-
Notifications
You must be signed in to change notification settings - Fork 54
test(platform): distribution log tests #2548
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
Merged
QuantumExplorer
merged 2 commits into
v2.0-dev-distributions
from
fix/distributionLogTests
Apr 16, 2025
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -254,7 +254,7 @@ impl DistributionFunction { | |
| n, | ||
| o, | ||
| start_moment, | ||
| c, | ||
| b, | ||
| min_value, | ||
| max_value, | ||
| } => { | ||
|
|
@@ -284,7 +284,7 @@ impl DistributionFunction { | |
| } | ||
|
|
||
| let exponent = (*m as f64) * (diff as f64) / (*n as f64); | ||
| let value = ((*a as f64) * exponent.exp() / (*d as f64)) + (*c as f64); | ||
| let value = ((*a as f64) * exponent.exp() / (*d as f64)) + (*b as f64); | ||
| if let Some(max_value) = max_value { | ||
| if value.is_infinite() && value.is_sign_positive() || value > *max_value as f64 | ||
| { | ||
|
|
@@ -346,22 +346,73 @@ impl DistributionFunction { | |
| return Err(ProtocolError::Overflow("Logarithmic function: argument for log is too big (max should be u64::MAX)")); | ||
| } | ||
|
|
||
| let argument = (*m as f64) * (diff as f64) / (*n as f64); | ||
| let argument = if *m == 1 { | ||
| if *n == 1 { | ||
| diff as f64 | ||
| } else { | ||
| (diff as f64) / (*n as f64) | ||
| } | ||
| } else if *n == 1 { | ||
| (*m as f64) * (diff as f64) | ||
| } else { | ||
| (*m as f64) * (diff as f64) / (*n as f64) | ||
| }; | ||
|
|
||
| let log_val = argument.ln(); | ||
| let value = ((*a as f64) * log_val / (*d as f64)) + (*b as f64); | ||
| if let Some(max_value) = max_value { | ||
| if value.is_infinite() && value.is_sign_positive() || value > *max_value as f64 | ||
| { | ||
| return Ok(*max_value); | ||
| } | ||
| } | ||
| if !value.is_finite() || value > (u64::MAX as f64) { | ||
|
|
||
| // Ensure the computed value is finite and within the u64 range. | ||
| if !log_val.is_finite() || log_val > (u64::MAX as f64) { | ||
| return Err(ProtocolError::Overflow( | ||
| "Logarithmic function evaluation overflow or negative", | ||
| "InvertedLogarithmic: evaluation overflow", | ||
| )); | ||
| } | ||
| if value < 0.0 { | ||
|
|
||
| let intermediate = if *a == 1 { | ||
| log_val | ||
| } else if *a == -1 { | ||
| -log_val | ||
| } else { | ||
| (*a as f64) * log_val | ||
| }; | ||
|
|
||
| let value = if d == &1 { | ||
| if !intermediate.is_finite() || intermediate > (i64::MAX as f64) { | ||
| if let Some(max_value) = max_value { | ||
| if intermediate.is_sign_positive() { | ||
| *max_value as i64 | ||
| } else { | ||
| return Err(ProtocolError::Overflow( | ||
| "InvertedLogarithmic: evaluation overflow intermediate bigger than i64::max", | ||
| )); | ||
| } | ||
|
Comment on lines
+370
to
+387
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. Additional mismatch in error messages. Throughout this block, references to |
||
| } else { | ||
| return Err(ProtocolError::Overflow( | ||
| "InvertedLogarithmic: evaluation overflow intermediate bigger than i64::max", | ||
| )); | ||
| } | ||
| } else { | ||
| (intermediate.floor() as i64) | ||
| .checked_add(*b as i64) | ||
| .or(max_value.map(|max| max as i64)) | ||
| .ok_or(ProtocolError::Overflow( | ||
| "InvertedLogarithmic: evaluation overflow when adding b", | ||
| ))? | ||
| } | ||
| } else { | ||
| if !intermediate.is_finite() || intermediate > (i64::MAX as f64) { | ||
| return Err(ProtocolError::Overflow( | ||
| "InvertedLogarithmic: evaluation overflow intermediate bigger than i64::max", | ||
| )); | ||
| } | ||
| ((intermediate / (*d as f64)).floor() as i64) | ||
| .checked_add(*b as i64) | ||
| .or(max_value.map(|max| max as i64)) | ||
| .ok_or(ProtocolError::Overflow( | ||
| "InvertedLogarithmic: evaluation overflow when adding b", | ||
| ))? | ||
| }; | ||
|
|
||
| if value < 0 { | ||
| return if let Some(min_value) = min_value { | ||
| Ok(*min_value) | ||
| } else { | ||
|
|
@@ -374,6 +425,12 @@ impl DistributionFunction { | |
| return Ok(*min_value); | ||
| } | ||
| } | ||
|
|
||
| if let Some(max_value) = max_value { | ||
| if value_u64 > *max_value { | ||
| return Ok(*max_value); | ||
| } | ||
| } | ||
| Ok(value_u64) | ||
| } | ||
| DistributionFunction::InvertedLogarithmic { | ||
|
|
@@ -900,7 +957,7 @@ mod tests { | |
| n: 1, | ||
| o: 0, | ||
| start_moment: Some(0), | ||
| c: 10, | ||
| b: 10, | ||
| min_value: None, | ||
| max_value: None, | ||
| }; | ||
|
|
@@ -918,7 +975,7 @@ mod tests { | |
| n: 1, | ||
| o: 0, | ||
| start_moment: Some(0), | ||
| c: 10, | ||
| b: 10, | ||
| min_value: None, | ||
| max_value: None, | ||
| }; | ||
|
|
@@ -938,7 +995,7 @@ mod tests { | |
| n: 1, | ||
| o: 0, | ||
| start_moment: Some(0), | ||
| c: 5, | ||
| b: 5, | ||
| min_value: None, | ||
| max_value: None, | ||
| }; | ||
|
|
@@ -957,7 +1014,7 @@ mod tests { | |
| n: 10, | ||
| o: 0, | ||
| start_moment: Some(0), | ||
| c: 0, | ||
| b: 0, | ||
| min_value: None, | ||
| max_value: None, | ||
| }; | ||
|
|
@@ -976,7 +1033,7 @@ mod tests { | |
| n: 1, | ||
| o: 0, | ||
| start_moment: Some(0), | ||
| c: 0, | ||
| b: 0, | ||
| min_value: None, | ||
| max_value: Some(100000000), | ||
| }; | ||
|
|
@@ -997,7 +1054,7 @@ mod tests { | |
| n: 1, | ||
| o: 0, | ||
| start_moment: Some(0), | ||
| c: 10, | ||
| b: 10, | ||
| min_value: None, | ||
| max_value: None, | ||
| }; | ||
|
|
@@ -1016,7 +1073,7 @@ mod tests { | |
| n: 1, | ||
| o: 0, | ||
| start_moment: Some(0), | ||
| c: 10, | ||
| b: 10, | ||
| min_value: Some(11), | ||
| max_value: None, | ||
| }; | ||
|
|
@@ -1035,7 +1092,7 @@ mod tests { | |
| n: 2, | ||
| o: 0, | ||
| start_moment: Some(0), | ||
| c: 10, | ||
| b: 10, | ||
| min_value: Some(1), | ||
| max_value: Some(11), // Set max at the starting value | ||
| }; | ||
|
|
@@ -1061,7 +1118,7 @@ mod tests { | |
| n: 10, | ||
| o: 0, | ||
| start_moment: Some(0), | ||
| c: 5, | ||
| b: 5, | ||
| min_value: None, | ||
| max_value: None, | ||
| }; | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Likely incorrect error label.
This line uses
"InvertedLogarithmic: evaluation overflow"within theLogarithmicvariant. The error message label seems mismatched and could confuse users.📝 Committable suggestion