Skip to content

Commit

Permalink
PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
rschwanhold committed Oct 29, 2020
1 parent d31277b commit ab8c39a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
1 change: 0 additions & 1 deletion python/wkw/wkw.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,6 @@ def write(self, off, data):
def is_contiguous(data):
return data.flags["F_CONTIGUOUS"] or data.flags["C_CONTIGUOUS"]

# the row-major handling of the rust lib cannot handle num_channels > 1
if not is_contiguous(data):
data = np.asfortranarray(data)

Expand Down
17 changes: 7 additions & 10 deletions rust/src/mat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ pub struct Mat<'a> {
pub data_in_c_order: bool,
}

pub fn linearize(channel: usize, x: usize, y: usize, z: usize, stride: &[usize]) -> isize {
(channel * stride[0] + x * stride[1] + y * stride[2] + z * stride[3]) as isize
}

impl<'a> Mat<'a> {
pub fn new(
data: &mut [u8],
Expand Down Expand Up @@ -96,10 +100,6 @@ impl<'a> Mat<'a> {
x_length * y_length * self.voxel_size,
];

fn linearize(channel: usize, x: usize, y: usize, z: usize, stride: &[usize]) -> isize {
(channel * stride[0] + x * stride[1] + y * stride[2] + z * stride[3]) as isize
}

let src_ptr = self.data.as_ptr();
let dst_ptr = buffer_data.as_mut_ptr();

Expand Down Expand Up @@ -137,6 +137,7 @@ impl<'a> Mat<'a> {
if src.data_in_c_order {
let num_channel = self.voxel_size / self.voxel_type.size();
if num_channel == 1 {
// if the data has only one channel, copy_from is a bit faster because it copies more items simultaneously
intermediate_buffer.copy_from(dst_pos, src, src_box)?;
} else {
// putting the channels to the back avoids that the indices (in copy_as_fortran_order) make too big jumps
Expand Down Expand Up @@ -235,8 +236,8 @@ impl<'a> Mat<'a> {
if !(dst_pos + src_box.width() < (self.shape + 1)) {
return Err(String::from("Writing out of bounds"));
}
if self.data_in_c_order != src.data_in_c_order {
return Err(String::from("Source and destination has to be the same order"));
if !(self.data_in_c_order & src.data_in_c_order) {
return Err(String::from("Source and destination have to be in c-order"));
}

let length = src_box.width();
Expand All @@ -258,10 +259,6 @@ impl<'a> Mat<'a> {
self.voxel_size,
];

fn linearize(channel: usize, x: usize, y: usize, z: usize, stride: &[usize]) -> isize {
(channel * stride[0] + x * stride[1] + y * stride[2] + z * stride[3]) as isize
}

unsafe {
let src_ptr = src.data.as_ptr().add(src.offset(src_box.min()) / num_channel);
let dst_ptr = self.data.as_mut_ptr().add(self.offset(dst_pos));
Expand Down

0 comments on commit ab8c39a

Please sign in to comment.