-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: move functions to test_utils
- Loading branch information
1 parent
5e380e7
commit ac08002
Showing
2 changed files
with
35 additions
and
26 deletions.
There are no files selected for viewing
This file contains 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 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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
use pathfinder_crypto::Felt; | ||
use rand::Rng; | ||
use std::time::Duration; | ||
|
||
pub fn mean(data: &[Duration]) -> Duration { | ||
data.iter() | ||
.sum::<Duration>() | ||
.checked_div(data.len().try_into().unwrap()) | ||
.unwrap() | ||
} | ||
|
||
#[allow(clippy::as_conversions)] | ||
pub fn std_deviation(data: &[Duration]) -> Duration { | ||
let mean = mean(data).as_secs_f32(); | ||
let mut variance = data | ||
.iter() | ||
.map(|x| { | ||
let diff = (*x).as_secs_f32() - mean; | ||
diff * diff | ||
}) | ||
.sum::<f32>(); | ||
variance /= data.len() as f32; | ||
Duration::from_secs_f32(variance.sqrt()) | ||
} | ||
|
||
pub fn random_felt() -> Felt { | ||
let mut buf: [u8; 32] = rand::thread_rng().gen(); | ||
buf[0] &= 0x07; // clear the 5 most significant bits | ||
Felt::from_be_bytes(buf).expect("Overflow ;(") | ||
} |