xicor 0.1.0

An implementation of Sourav Chatterjee's xi-correlation coefficient
Documentation
use std::fs::File;
use std::io::Read;
use std::time::Instant;
use xicor::xicorf;



fn main() {
    let n = 10_000_000;

    println!("Initialising arrays...");
    
    let rands = randf(n*2);
    let x = &rands[..n];
    let y = &rands[n..];

    println!("Initialised. Calculating xi...");

    let inst = Instant::now();
    let xi = xicorf(&x, &y);
    let time = inst.elapsed().as_secs_f32();

    println!("Xi = {xi}");
    println!("Calculated in {time} s");
}

// Generate uniform floats in the range [0, 1) by reading from /dev/urandom
fn randf(n: usize) -> Vec<f64> {
    let mut f = File::open("/dev/urandom").unwrap();
    let mut buf = vec![0u8; n*8];

    f.read_exact(&mut buf).unwrap();

    buf.chunks(8)
        .map(|c| u64::from_ne_bytes(c.try_into().unwrap()))
        .map(|x| x as f64/u64::MAX as f64)
        .collect()
}