Skip to content

Commit

Permalink
bump ndarray version to 0.15
Browse files Browse the repository at this point in the history
  • Loading branch information
kaizhang committed Dec 5, 2022
1 parent 95324b7 commit 3e3a3d2
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ fs2 = { version = "0.4", optional = true }
itertools = { version = "0.8", optional = true }
lz4 = { version = "1.23", optional = true }
lz-fear = { version = "0.1.1", optional = true }
ndarray = { version = "0.13", optional = true }
ndarray = { version = "0.15", optional = true }
num-traits = { version = "0.2", optional = true }
serde = { version = "1.0", features = ["derive"] }
smallvec = { version = "1", features = ["serde"] }
Expand Down
14 changes: 6 additions & 8 deletions src/ndarray.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ use itertools::Itertools;
use ndarray::{
Array,
ArrayView,
IxDyn,
ShapeBuilder,
SliceInfo,
};

use crate::{
Expand Down Expand Up @@ -117,9 +115,9 @@ impl BoundingBox {
self.offset.iter().zip(self.size.iter()).map(|(o, s)| o + s)
}

pub fn to_ndarray_slice(&self) -> CoordVec<ndarray::SliceOrIndex> {
pub fn to_ndarray_slice(&self) -> CoordVec<ndarray::SliceInfoElem> {
self.offset.iter().zip(self.end())
.map(|(&start, end)| ndarray::SliceOrIndex::Slice {
.map(|(&start, end)| ndarray::SliceInfoElem::Slice {
start: start as isize,
end: Some(end as isize),
step: 1,
Expand Down Expand Up @@ -242,14 +240,14 @@ pub trait N5NdarrayReader : N5Reader {
let block_read_bb = read_bb.clone() - &block_bb.offset;

let arr_slice = arr_read_bb.to_ndarray_slice();
let mut arr_view = arr.slice_mut(SliceInfo::<_, IxDyn>::new(arr_slice).unwrap().as_ref());
let mut arr_view = arr.slice_mut(arr_slice.as_slice());

let block_slice = block_read_bb.to_ndarray_slice();

// N5 datasets are stored f-order/column-major.
let block_data = ArrayView::from_shape(block_bb.size_ndarray_shape().f(), block.get_data())
.expect("TODO: block ndarray failed");
let block_view = block_data.slice(SliceInfo::<_, IxDyn>::new(block_slice).unwrap().as_ref());
let block_view = block_data.slice(block_slice.as_slice());

arr_view.assign(&block_view);
}
Expand Down Expand Up @@ -298,7 +296,7 @@ pub trait N5NdarrayWriter : N5Writer {
let arr_bb = write_bb.clone() - &bbox.offset;

let arr_slice = arr_bb.to_ndarray_slice();
let arr_view = array.slice(SliceInfo::<_, IxDyn>::new(arr_slice).unwrap().as_ref());
let arr_view = array.slice(arr_slice.as_slice());

if write_bb == nom_block_bb {

Expand Down Expand Up @@ -339,7 +337,7 @@ pub trait N5NdarrayWriter : N5Writer {

let block_write_bb = write_bb.clone() - &block_bb.offset;
let block_slice = block_write_bb.to_ndarray_slice();
let mut block_view = block_array.slice_mut(SliceInfo::<_, IxDyn>::new(block_slice).unwrap().as_ref());
let mut block_view = block_array.slice_mut(block_slice.as_slice());

block_view.assign(&arr_view);

Expand Down
2 changes: 0 additions & 2 deletions tests/ndarray.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#![cfg(feature = "use_ndarray")]

use std::iter::FromIterator;

use ndarray::Array;
use smallvec::smallvec;
use rand::Rng;
Expand Down

0 comments on commit 3e3a3d2

Please sign in to comment.