-
Notifications
You must be signed in to change notification settings - Fork 193
/
Copy pathtests.rs
81 lines (68 loc) · 2.18 KB
/
tests.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// Copyright (c) Facebook, Inc. and its affiliates.
//
// This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree.
use alloc::vec::Vec;
use rand_utils::rand_vector;
use crate::{
fft::fft_inputs::FftInputs,
field::{f128::BaseElement, StarkField},
polynom,
utils::get_power_series,
};
// CORE ALGORITHMS
// ================================================================================================
#[test]
fn fft_in_place() {
// degree 3
let n = 4;
let mut p = rand_vector(n);
let domain = build_domain(n);
let expected = polynom::eval_many(&p, &domain);
let twiddles = super::get_twiddles::<BaseElement>(n);
p.fft_in_place(&twiddles);
p.permute();
assert_eq!(expected, p);
// degree 7
let n = 8;
let mut p = rand_vector(n);
let domain = build_domain(n);
let twiddles = super::get_twiddles::<BaseElement>(n);
let expected = polynom::eval_many(&p, &domain);
p.fft_in_place(&twiddles);
p.permute();
assert_eq!(expected, p);
// degree 15
let n = 16;
let mut p = rand_vector(n);
let domain = build_domain(n);
let twiddles = super::get_twiddles::<BaseElement>(16);
let expected = polynom::eval_many(&p, &domain);
p.fft_in_place(&twiddles);
p.permute();
assert_eq!(expected, p);
// degree 1023
let n = 1024;
let mut p = rand_vector(n);
let domain = build_domain(n);
let expected = polynom::eval_many(&p, &domain);
let twiddles = super::get_twiddles::<BaseElement>(n);
p.fft_in_place(&twiddles);
p.permute();
assert_eq!(expected, p);
}
#[test]
fn fft_get_twiddles() {
let n = super::MIN_CONCURRENT_SIZE * 2;
let g = BaseElement::get_root_of_unity(n.ilog2());
let mut expected = get_power_series(g, n / 2);
expected.permute();
let twiddles = super::get_twiddles::<BaseElement>(n);
assert_eq!(expected, twiddles);
}
// HELPER FUNCTIONS
// ================================================================================================
fn build_domain(size: usize) -> Vec<BaseElement> {
let g = BaseElement::get_root_of_unity(size.ilog2());
get_power_series(g, size)
}