You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to query non-contiguous parts of a matrix in a single HDF5 query. For this I am try to use Selection::points. It seems Selection:points needs a 2D array other wise it throws a compilation error. However when I put in a 2D array (points2) it gives a runtime error Error: Selection ndim (1) != array ndim (2)
In general, I feel better documentation and examples should be provided regarding how to use this functions.
use hdf5::Selection;use hdf5::{File,Result};use ndarray::array;use ndarray::Array1;use ndarray::Array2;fnmain() -> Result<()>{// Step 3: Create an HDF5 file and datasetlet file = File::create("example.h5")?;let dataset = file
.new_dataset::<f64>().shape((10,10)).create("dataset")?;// Initialize the dataset with some datalet data:Array2<f64> = Array2::from_shape_fn((10,10), |(i, j)| (i *10 + j + 1)asf64);println!("data:{:?}", data);
dataset.write(&data)?;// Step 4: Define point selection to read non-contiguous parts of a matrix// Define the points to select (row, column)let points2:Array2<usize> = Array2::from_shape_vec((3,2),vec![0, 2, 3, 5, 7, 9]).unwrap();let points:Array1<usize> = array![0, 3, 7, 9];println!("points ndim:{:?}", points.ndim());println!("points ndim:{:?}", points2.ndim());println!("points:{}", points);println!("points2:{}", points2);// Read the selected points from the dataset//let array2: Array2<f64> = dataset.read_slice_2d(Selection::Points(points2))?; // Gives a compilation error asking add 2D array.let array2:Array2<f64> = dataset.read_slice_2d(Selection::Points(points2))?;// This compiles, but gives a runtime error: Error: Selection ndim (1) != array ndim (2) println!("Read non-contiguous matrix points: {:?}", array2);Ok(())}```
The text was updated successfully, but these errors were encountered:
I think it is working as expected as points will always be output as a 1D vector, and you are requesting a 2D output (read_slice_2d). You can modify your script as below to read the specified points.
let array:Array1<f64> = dataset.read_slice(Selection::Points(points2))?;
I am trying to query non-contiguous parts of a matrix in a single HDF5 query. For this I am try to use
Selection::points
. It seems Selection:points needs a 2D array other wise it throws a compilation error. However when I put in a 2D array (points2) it gives a runtime errorError: Selection ndim (1) != array ndim (2)
In general, I feel better documentation and examples should be provided regarding how to use this functions.
The text was updated successfully, but these errors were encountered: