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
extern crate serde;
extern crate serde_pickle;
use std::fs::File;
use std::io::prelude::*;
use std::env;
use std::process::Command;
extern crate rand;
pub fn plot(basic_vectors: &(Vec<f64>, Vec<f64>)) {
let global_path = env::current_dir().unwrap();
let ser_path: &str = &format!("{}/output.tmp.pkl", global_path.to_str().unwrap());
let serialized = serde_pickle::to_vec(basic_vectors, true).unwrap();
let mut buffer = File::create(ser_path).unwrap();
match buffer.write(&serialized) {
Err(_x) => panic!(
"Failed to write serialized data to file at path = \"{}\"",
ser_path
),
_ => {}
};
let py_path = &format!("{}/plotter.py", global_path.to_str().unwrap());
let _new_command = Command::new("pythonw")
.arg(py_path)
.arg(ser_path)
.status()
.expect("Failed to start plotter.");
match std::fs::remove_file(ser_path) {
Err(_x) => panic!("Failed to remove temporary file at path = \"{}\"", ser_path),
_ => {}
};
}
#[cfg(test)]
mod tests {
use rand::{thread_rng, Rng};
#[test]
fn test_serialize() {
let mut a: Vec<f64> = vec![];
let mut b: Vec<f64> = vec![];
let mut rng = thread_rng();
for i in 0..100000 {
let x: f64 = rng.gen();
let y: f64 = rng.gen();
a.push(x);
b.push(y);
}
let serialized = serde_pickle::to_vec(&(&a, &b), true).unwrap();
let deserialized = serde_pickle::from_slice(&serialized).unwrap();
assert_eq!((a, b), deserialized);
}
#[test]
fn test_fs() {}
}