Browse Source

Add an intermediate test

master
Ivan Ukhov 9 years ago
parent
commit
8dd8e75594
  1. 8
      src/real.rs
  2. 135
      tests/fixtures.rs
  3. 9
      tests/lib.rs

8
src/real.rs

@ -7,7 +7,7 @@ use number::{Complex, c64};
/// The number of points should be a power of two. The data are replaced by the
/// positive frequency half of their complex Fourier transform. The real-valued
/// first and last components of the complex transform are returned as elements
/// data[0] and data[1], respectively.
/// `data[0]` and `data[1]`, respectively.
///
/// ## References
///
@ -47,10 +47,11 @@ pub fn forward(data: &mut [f64]) {
data[i] = part1 + factor * part2;
data[j] = (part1 - factor * part2).conj();
}
data[n / 2] = data[n / 2].conj();
}
/// Expand a compressed representation produced by `real::forward`.
/// Unpack a compressed representation produced by `real::forward`.
pub fn unpack(data: &[f64]) -> Vec<c64> {
let n = data.len();
power_of_two!(n);
@ -64,8 +65,7 @@ pub fn unpack(data: &[f64]) -> Vec<c64> {
}
cdata[n / 2] = c64(data[1], 0.0);
for i in (n / 2 + 1)..n {
let j = n - i;
cdata[i] = c64(data[2 * j], -data[2 * j + 1]);
cdata[i] = cdata[n - i].conj();
}
cdata

135
tests/fixtures.rs

@ -129,7 +129,7 @@ pub const TIME_DATA: [f64; 2 * 128] = [
0.452619465744411, 0.175360766321123,
];
pub const FREQUENCY_DATA_FROM_COMPLEX: [f64; 2 * 128] = [
pub const FREQUENCY_DATA_FOR_COMPLEX: [f64; 2 * 128] = [
6.750656266720340e+01, 6.279874768750683e+01,
7.714838837855442e-02, 5.819389938527752e+00,
-5.303978155417409e+00, -2.887549849606836e-01,
@ -260,7 +260,138 @@ pub const FREQUENCY_DATA_FROM_COMPLEX: [f64; 2 * 128] = [
-2.916435892389174e+00, 2.258137395096740e+00,
];
pub const FREQUENCY_DATA_FROM_REAL: [f64; 2 * 256] = [
pub const FREQUENCY_DATA_FOR_REAL: [f64; 2 * 128] = [
1.303053103547102e+02, 4.707814979696565e+00,
2.581170396731581e+00, 1.851687150427200e-01,
-4.712992966498972e+00, 3.386970116076342e+00,
-3.526081640989058e+00, -6.639837287112846e-01,
2.470203860537832e+00, 1.880268489878626e+00,
-6.963879517225686e+00, -1.359220918694192e+00,
-3.729301277306694e+00, 1.188929523990152e+00,
9.470909676459633e-01, -1.133537735465808e+00,
-5.515738367157939e-01, -7.532580478755273e-01,
-3.549075039135675e+00, -7.723961671240312e+00,
-4.554423293554939e+00, 3.928695392899054e+00,
-3.376141283756013e-01, 3.873091478779078e-01,
-2.239363597649239e+00, -2.622333161216239e+00,
-1.209463421383755e+00, 2.081549368638947e+00,
2.787306134089562e+00, -4.406059514292808e-01,
-5.867907573418175e-01, -1.188914452808487e+00,
-1.143465327856217e+00, 3.381662456994257e+00,
3.502762058115902e-01, 1.939344791605026e+00,
-3.966269981614960e+00, 2.578889617469153e+00,
3.152848007718109e+00, -1.882857879463846e+00,
-3.804426226346088e+00, -2.360628066063453e+00,
-1.645310465960080e+00, 1.955745233096742e-01,
8.727435711779677e-02, 5.200789512413666e+00,
1.120142690086255e+00, -1.554454960578806e+00,
-3.568747367377898e-01, -1.708135182867248e+00,
-5.343117610163509e+00, 5.248479799162289e+00,
5.372292947253843e-01, -4.845214246729507e+00,
6.450571433636446e-02, 1.463660986831282e+00,
1.455587976273307e+00, -5.712855301747826e+00,
-1.042998871212444e-01, -1.101626615691205e+00,
-4.844351629884984e+00, 2.524159012105675e+00,
-6.773746016629307e+00, -1.640287552626491e+00,
-3.831851193928845e+00, 3.944330086139181e+00,
-1.492165597423655e+00, -5.490578426839170e+00,
1.689911156425059e+00, 8.268603075350915e-01,
1.497677302367308e+00, 4.248256795204093e+00,
-3.579498902285684e+00, -1.349669158977704e+00,
3.044651859669117e+00, 1.746167472193509e+00,
7.601446066545731e-01, -3.263458881514898e+00,
5.150135192916219e+00, 2.544519592918016e+00,
-7.037646240419694e-01, 2.824304911746514e+00,
4.772947230001412e+00, 5.943735485336084e-01,
3.480135296267814e+00, -1.372346334547340e+00,
4.028770258877906e+00, 7.235631972573927e+00,
2.312768769350037e+00, 3.796429682741911e+00,
-1.782620750385733e-01, 6.191786592630610e+00,
-3.719950405898309e+00, 3.654794911963337e+00,
-2.543476747185558e+00, 1.221476001211499e+00,
1.118615654278817e+00, -1.238455571070933e+00,
-9.959356075165566e-01, -2.054128218014691e+00,
2.639682132748302e+00, -1.701633154204415e+00,
2.173264828603092e+00, 8.248948121629960e-01,
-2.798464518993120e+00, 2.355688055046297e+00,
-8.937461326272580e-01, 7.588584122960707e-01,
2.021391810490336e-02, -1.805385996360098e+00,
-4.681753970646021e+00, -6.445270984734714e+00,
-3.901614280067266e+00, -6.215718415805858e+00,
-4.468302161079752e+00, 6.560811803588424e-01,
-8.057225542680853e-01, 1.502186010252237e+00,
-3.574988339289839e+00, -4.774591638105148e-01,
-2.126408608816460e+00, 6.496133889843871e-01,
3.088495481715207e+00, -4.835922591012089e+00,
3.119768676762977e+00, -2.647386306731720e+00,
-7.608791527035967e+00, 1.199605557244359e+00,
-3.991693675979821e+00, 2.395612192990072e+00,
-3.174227772880592e+00, 3.445449943922660e+00,
-1.555563215691437e+00, -4.167697436792233e+00,
-2.644960216780778e+00, 1.689639671556236e+00,
2.017147084475464e+00, -3.909911542141398e+00,
-1.572925906246434e+00, 2.734328259634700e+00,
2.238378162968156e+00, -3.333393703264437e+00,
-1.135715370257395e+00, 5.432062981893454e+00,
3.141032040974915e+00, 4.233118739006381e+00,
-2.244646753286111e+00, -8.133506606215242e+00,
6.183938698585162e-01, 9.413936219073087e-01,
5.074411884642282e+00, 2.371137223330094e+00,
1.508419785650108e+00, 7.575939593955647e-01,
-3.307128656712730e-01, 1.491213952741355e+00,
-1.664463833645839e+00, -7.738272374453388e+00,
1.691355121676643e+00, -5.149258565119262e+00,
3.234961768517784e+00, -2.208252455058216e+00,
-3.050344297876333e-01, 5.928476092041176e+00,
-2.585342599501458e+00, 1.416415611654855e-01,
-1.623242793328372e+00, -7.524531068476570e-01,
3.370243371985904e-02, 3.533526922763765e+00,
5.114525363780102e-01, 3.372272082430228e+00,
3.270734032557804e+00, -4.681342238696375e+00,
-2.751931334150639e+00, -2.651729205325560e+00,
3.840150506416120e+00, -1.699490542466287e+00,
-3.775415231602213e+00, 2.718975366537331e-01,
2.794228129172392e-01, -5.617586502190706e-01,
4.044899973907196e+00, 3.871341157699513e+00,
-5.667678788988394e+00, 2.665378472115218e+00,
2.032171253558433e+00, 5.788737425987882e+00,
3.842811024005548e+00, 2.182079534549411e+00,
5.732968806672321e+00, 6.229199225361914e+00,
2.016971203832224e+00, -3.163328419816367e+00,
1.125523162622214e+00, -1.354631807011866e+00,
-2.586009495883931e+00, 2.331792485469409e+00,
-2.717460886180260e+00, 1.425577896601247e+00,
6.404452401830746e+00, -1.278706155866981e+00,
1.963612499177015e+00, -7.149444742400527e-01,
2.854512196711251e+00, -1.617625082200844e-01,
-6.170863635190775e-01, 4.618556574885895e+00,
9.087219524177452e-01, -2.422226101938949e+00,
-1.786745383326708e+00, -1.276937137201354e+00,
5.230935547165801e+00, -1.293868043086649e+00,
3.687342499608546e+00, 3.666842103111982e-01,
4.690446349542574e-01, 3.354686164448831e+00,
1.459522623361331e+00, -7.836282087117324e-01,
-1.556476042488201e+00, 9.977746254405300e+00,
3.615874982837306e+00, 7.587231541051005e-01,
-1.663885294732292e+00, -4.893547445581648e+00,
6.195623059940029e+00, 6.233312200748059e-01,
-7.389630549527273e+00, -1.774569316216396e+00,
-9.065368226930491e-01, -5.980324595351290e+00,
3.272997662902597e+00, -8.599788876820809e-01,
2.931287676659427e+00, -4.844159203841096e+00,
-6.026900117940131e+00, -5.010921049858613e+00,
7.092481670250209e-01, -2.703433464882526e+00,
-3.310419708767941e+00, 3.606335895631942e+00,
-1.115479477600923e+01, -4.306474671574700e+00,
-7.448658248653062e-01, 5.402306741679653e+00,
7.270283940301629e+00, 1.866320798541252e+00,
2.470666768058557e+00, 3.302494992111579e+00,
3.949947040413505e+00, -6.999949435933990e+00,
-1.804396937714904e+00, 8.514196593390323e-01,
-5.420457900742201e+00, -3.376083828388293e+00,
];
pub const FREQUENCY_DATA_FOR_REAL_UNPACKED: [f64; 2 * 256] = [
1.303053103547102e+02, 0.000000000000000e+00,
2.581170396731584e+00, 1.851687150427199e-01,
-4.712992966498973e+00, 3.386970116076343e+00,

9
tests/lib.rs

@ -10,12 +10,12 @@ mod fixtures;
fn complex_forward() {
let mut data = fixtures::TIME_DATA.to_vec();
fft::complex::forward(as_c64_mut(&mut data));
assert::close(&data, &fixtures::FREQUENCY_DATA_FROM_COMPLEX[..], 1e-14);
assert::close(&data, &fixtures::FREQUENCY_DATA_FOR_COMPLEX[..], 1e-14);
}
#[test]
fn complex_inverse() {
let mut data = fixtures::FREQUENCY_DATA_FROM_COMPLEX.to_vec();
let mut data = fixtures::FREQUENCY_DATA_FOR_COMPLEX.to_vec();
fft::complex::inverse(as_c64_mut(&mut data), true);
assert::close(&data, &fixtures::TIME_DATA[..], 1e-14);
}
@ -26,12 +26,13 @@ fn real_forward() {
{
let mut data = to_c64(&data);
fft::complex::forward(&mut data);
assert::close(as_f64(&data), &fixtures::FREQUENCY_DATA_FROM_REAL[..], 1e-13);
assert::close(as_f64(&data), &fixtures::FREQUENCY_DATA_FOR_REAL_UNPACKED[..], 1e-13);
}
{
fft::real::forward(&mut data);
assert::close(&data, &fixtures::FREQUENCY_DATA_FOR_REAL[..], 1e-13);
let data = fft::real::unpack(&data);
assert::close(as_f64(&data), &fixtures::FREQUENCY_DATA_FROM_REAL[..], 1e-13);
assert::close(as_f64(&data), &fixtures::FREQUENCY_DATA_FOR_REAL_UNPACKED[..], 1e-13);
}
}

Loading…
Cancel
Save