pub fn plot(raw_values: Vec<f32>, title: &'static str, window_x: u16, window_y: u16) {
// copy from float vector to Array
let dims = Dim4::new(&[raw_values.len() as u64, 1, 1, 1]);
let values = &Array::new(dims, &raw_values.as_ref(), Aftype::F32).unwrap();
// create a window
let title_str = String::from(title); // if we don't .clone() we get a crash!
let wnd = match af::Window::new(window_x as i32, window_y as i32, title_str) {
Ok(v) => v,
Err(e) => panic!("Window creation failed: {}", e), //XXX: handle better
};
// display till closed
loop {
wnd.draw_plot(&af::range(dims, 0, af::Aftype::F32).unwrap(), &values, None);
if wnd.is_closed().unwrap() == true { break; }
}
}
results in:
2015-08-26 14:44:37.785 perceptron[11818:5138515] *** Assertion failure in -[GLFWWindow setTitle:], /SourceCache/AppKit/AppKit-1348.17/AppKit.subproj/NSWindow.m:3068
thread '<main>' panicked at 'Window creation failed: Unkown Error', src/plot.rs:14
An unknown error occurred
Possible solution: run .clone() internally in the appropriate functions