numeric-rust / numeric

N-dimensional matrix class for Rust
MIT License
60 stars 10 forks source link

HDF5 load Segfaults #5

Open TKGgunter opened 6 years ago

TKGgunter commented 6 years ago

Hdf5 load Segmentation fault (core dumped). I've attempted to recreate the write and load hdf5 example and it produces the set fault error.

gustavla commented 6 years ago

Do you have a code snippet that reproduces this?

TKGgunter commented 6 years ago

This was taken pretty much from test in tests/io.rs

extern` crate numeric;
use std::path::PathBuf;
use numeric::{Tensor, io};
use std::env;
use std::fs;

fn main() {
    // We can't have multiple HDF5 tests, since these functions are not thread-safe! 
    // This is why we have to string all of this together in serial, since otherwise the tests
    // might run concurrently. This is in other words the only test that is allowed to interact
    // with libhdf5.

    let mut path = PathBuf::from("");//env::temp_dir();
    println!("{:?}", path);
    path.push("numeric.h5");
    if path.exists() {
        assert!(fs::remove_file(&path).is_ok());
    }

    {
        let t: Tensor<f64> = Tensor::range(10);

        let res = t.save_hdf5(&path);
        assert!(res.is_ok());
        assert!(path.exists());

        println!("Lets try to load..."); //This runs
        let t2 = io::load_hdf5_as_f64(&path, "/data").unwrap();

        println!("Loaded"); //This does not
        assert!(t == t2);
        println!("Loaded and loaded correctly.");

        assert!(fs::remove_file(&path).is_ok());
    }

    {
        let t: Tensor<i16> = Tensor::range(1000).reshape(&[50, 20]);

        let res = t.save_hdf5(&path);
        assert!(res.is_ok());
        assert!(path.exists());

        println!("Lets try to load...");
        let t2 = io::load_hdf5_as_i16(&path, "/data").unwrap();

        assert!(t == t2);
        println!("Loaded and loaded correctly.");
        //assert!(fs::remove_file(&path).is_ok());
    }
}