pub fn read_slice<T, S, D>(&self, slice: &SliceInfo<S, D>) -> Result<Array<T, D>>
    where
        T: H5Type,
        S: AsRef<[SliceOrIndex]>,
        D: ndarray::Dimension,
    {
        ensure!(!self.obj.is_attr(), "slicing cannot be used on attribute datasets");

        let shape = self.obj.get_shape()?;

        let slice_s: &[SliceOrIndex] = slice.as_ref();
        let slice_dim = slice_s.len();
        if shape.ndim() != slice_dim {
            let obj_ndim = shape.ndim();
            ensure!(
                obj_ndim == slice_dim,
                "slice dimension mismatch: dataset has {} dims, slice has {} dims",
                obj_ndim,
                slice_dim
            );
        }

        if shape.ndim() == 0 {
            // Check that return dimensionality is 0.
            if let Some(ndim) = D::NDIM {
                let obj_ndim = 0;
                ensure!(
                    obj_ndim == ndim,
                    "ndim mismatch: slice outputs dims {}, output type dims {}",
                    obj_ndim,
                    ndim
                );
            }

            // Fall back to a simple read for the scalar case
            // Slicing has no effect
            self.read()
        } else {
            let fspace = self.obj.space()?;
            let out_shape = fspace.select_slice(slice)?;

            // Remove dimensions from out_shape that were SliceOrIndex::Index in the slice
            let reduced_shape: Vec<_> = slice_s
                .iter()
                .zip(out_shape.iter().cloned())
                .filter_map(|(slc, sz)| match slc {
                    SliceOrIndex::Index(_) => None,
                    _ => Some(sz),
                })
                .collect();

            // *Output* dimensionality must match the reduced shape,
            // (i.e. dimensionality after singleton 'SliceOrIndex::Index'
            // axes are dropped.
            if let Some(ndim) = D::NDIM {
                let obj_ndim = reduced_shape.len();
                ensure!(
                    obj_ndim == ndim,
                    "ndim mismatch: slice outputs dims {}, output type dims {}",
                    obj_ndim,
                    ndim
                );
            }

            let mspace = Dataspace::try_new(&out_shape, false)?;
            let size = out_shape.iter().product();
            let mut vec = Vec::with_capacity(size);
            unsafe {
                vec.set_len(size);
            }

            self.read_into_buf(vec.as_mut_ptr(), Some(&fspace), Some(&mspace))?;

            let arr = ArrayD::from_shape_vec(reduced_shape, vec)?;
            Ok(arr.into_dimensionality()?)
        }
    }
/// Reads a slice of an n-dimensional array.
/// If the dimensionality `D` has a fixed number of dimensions, it must match the dimensionality of
/// the slice, after singleton dimensions are dropped.
/// Use the multi-dimensional slice macro `s![]` from `ndarray` to conveniently create
/// a multidimensional slice.
Reads a slice of an n-dimensional array.
If the dimensionality `D` has a fixed number of dimensions, it must match the dimensionality of
the slice, after singleton dimensions are dropped.
Use the multi-dimensional slice macro `s![]` from `ndarray` to conveniently create
a multidimensional slice.
Reads a slice of an n - dimensional array . If the dimensionality ` D ` has a fixed number of dimensions it must match the dimensionality of the slice after singleton dimensions are dropped . Use the multi - dimensional slice macro ` s! [] ` from ` ndarray ` to conveniently create a multidimensional slice .
pub fn read_slice<T, S, D>(&self, slice: &SliceInfo<S, D>) -> Result<Array<T, D>>
    where
        T: H5Type,
        S: AsRef<[SliceOrIndex]>,
        D: ndarray::Dimension,
    {
        ensure!(!self.obj.is_attr(), "slicing cannot be used on attribute datasets");
        let shape = self.obj.get_shape()?;
        let slice_s: &[SliceOrIndex] = slice.as_ref();
        let slice_dim = slice_s.len();
        if shape.ndim() != slice_dim {
            let obj_ndim = shape.ndim();
            ensure!(
                obj_ndim == slice_dim,
                "slice dimension mismatch: dataset has {} dims, slice has {} dims",
                obj_ndim,
                slice_dim
            );
        }
        if shape.ndim() == 0 {
            // Check that return dimensionality is 0.
            if let Some(ndim) = D::NDIM {
                let obj_ndim = 0;
                ensure!(
                    obj_ndim == ndim,
                    "ndim mismatch: slice outputs dims {}, output type dims {}",
                    obj_ndim,
                    ndim
                );
            }
            // Fall back to a simple read for the scalar case
            // Slicing has no effect
            self.read()
        } else {
            let fspace = self.obj.space()?;
            let out_shape = fspace.select_slice(slice)?;
            // Remove dimensions from out_shape that were SliceOrIndex::Index in the slice
            let reduced_shape: Vec<_> = slice_s
                .iter()
                .zip(out_shape.iter().cloned())
                .filter_map(|(slc, sz)| match slc {
                    SliceOrIndex::Index(_) => None,
                    _ => Some(sz),
                })
                .collect();
            // *Output* dimensionality must match the reduced shape,
            // (i.e. dimensionality after singleton 'SliceOrIndex::Index'
            // axes are dropped.
            if let Some(ndim) = D::NDIM {
                let obj_ndim = reduced_shape.len();
                ensure!(
                    obj_ndim == ndim,
                    "ndim mismatch: slice outputs dims {}, output type dims {}",
                    obj_ndim,
                    ndim
                );
            }
            let mspace = Dataspace::try_new(&out_shape, false)?;
            let size = out_shape.iter().product();
            let mut vec = Vec::with_capacity(size);
            unsafe {
                vec.set_len(size);
            }
            self.read_into_buf(vec.as_mut_ptr(), Some(&fspace), Some(&mspace))?;
            let arr = ArrayD::from_shape_vec(reduced_shape, vec)?;
            Ok(arr.into_dimensionality()?)
        }
    }
pub fn read_slice < T , S , D > ( & self , slice : & SliceInfo < S , D > ) -> Result < Array < T , D > > where T : H5Type , S : AsRef < [ SliceOrIndex ] > , D : ndarray :: Dimension , { ensure ! ( self obj is_attr ( ) " " ) ; let shape = self . obj . get_shape ( ) ? ; let slice_s : & [ SliceOrIndex ] = slice . as_ref ( ) ; let slice_dim = slice_s . len ( ) ; if shape . ndim ( ) != slice_dim { let obj_ndim = shape . ndim ( ) ; ensure ! ( obj_ndim slice_dim " " obj_ndim slice_dim ) ; } if shape . ndim ( ) == 0 { // Check that return dimensionality is 0. if let Some ( ndim ) = D :: NDIM { let obj_ndim = 0 ; ensure ! ( obj_ndim ndim " " obj_ndim ndim ) ; } // Fall back to a simple read for the scalar case // Slicing has no effect self . read ( ) } else { let fspace = self . obj . space ( ) ? ; let out_shape = fspace . select_slice ( slice ) ? ; // Remove dimensions from out_shape that were SliceOrIndex::Index in the slice let reduced_shape : Vec < _ > = slice_s . iter ( ) . zip ( out_shape . iter ( ) . cloned ( ) ) . filter_map ( | ( slc , sz ) | match slc { SliceOrIndex :: Index ( _ ) => None , _ => Some ( sz ) , } ) . collect ( ) ; // *Output* dimensionality must match the reduced shape, // (i.e. dimensionality after singleton 'SliceOrIndex::Index' // axes are dropped. if let Some ( ndim ) = D :: NDIM { let obj_ndim = reduced_shape . len ( ) ; ensure ! ( obj_ndim ndim " " obj_ndim ndim ) ; } let mspace = Dataspace :: try_new ( & out_shape , false ) ? ; let size = out_shape . iter ( ) . product ( ) ; let mut vec = Vec :: with_capacity ( size ) ; unsafe { vec . set_len ( size ) ; } self . read_into_buf ( vec . as_mut_ptr ( ) , Some ( & fspace ) , Some ( & mspace ) ) ? ; let arr = ArrayD :: from_shape_vec ( reduced_shape , vec ) ? ; Ok ( arr . into_dimensionality ( ) ? ) } }
Reads a slice of an n-dimensional array.
Reads a slice of an n - dimensional array .
&self
slice
&SliceInfo<S, D>
&self
slice
&SliceInfo<S, D>