Skip to content

Commit 31219ac

Browse files
committed
remove unused code
1 parent 8e09d44 commit 31219ac

File tree

5 files changed

+55
-203
lines changed

5 files changed

+55
-203
lines changed

matlab/rust/wkw_init/Cargo.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@ version = "1.4.0"
44
authors = ["Alessandro Motta <[email protected]>"]
55
build = "build.rs"
66

7-
[dependencies.wkwrap]
8-
path = "../../../rust"
9-
107
[dependencies.wkw_mex]
118
path = "../wkw_mex"
129

matlab/rust/wkw_load/src/lib.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ mex_function!(nlhs, lhs, nrhs, rhs, {
6262
bbox_start, bbox_shape, array_shape
6363
));
6464
}
65-
println!("{:?} {:?}", bbox_start, bbox_shape);
6665
let subset = zarrs_result_to_str_error(ArraySubset::new_with_start_shape(
6766
bbox_start.clone(),
6867
bbox_shape.clone(),
@@ -89,8 +88,6 @@ mex_function!(nlhs, lhs, nrhs, rhs, {
8988
let data_all = zarrs_result_to_str_error(array.retrieve_array_subset(&subset))?;
9089
let zarr_buf = zarrs_result_to_str_error(data_all.into_fixed())?.into_owned(); // in c-order
9190

92-
println!("zarr_buf: {:?}", zarr_buf);
93-
9491
let mat_arr = create_numeric_array(&bbox_shape, mat_class, MxComplexity::Real)?;
9592

9693
copy_as_fortran_order(&zarr_buf, mat_arr, &bbox_shape, type_size)?;

matlab/rust/wkw_mex/src/lib.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,9 @@ extern crate libc;
22
extern crate wkwrap;
33

44
mod ffi;
5-
mod util;
65
mod macros;
7-
mod wkw;
6+
mod util;
87

98
pub use ffi::*;
109
pub use macros::*;
1110
pub use util::*;
12-
pub use wkw::*;

matlab/rust/wkw_mex/src/util.rs

Lines changed: 54 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -17,31 +17,6 @@ pub fn as_nat(f: f64) -> Result<u64> {
1717
}
1818
}
1919

20-
pub fn as_log2(f: f64) -> Result<u8> {
21-
let i = as_nat(f)?;
22-
23-
match i & (i - 1) == 0 {
24-
true => Ok(i.trailing_zeros() as u8),
25-
false => Err("Input must be a power of two".to_string()),
26-
}
27-
}
28-
29-
pub fn str_slice_to_mx_class_id(class_id: &str) -> Result<MxClassId> {
30-
match class_id {
31-
"uint8" => Ok(MxClassId::Uint8),
32-
"uint16" => Ok(MxClassId::Uint16),
33-
"uint32" => Ok(MxClassId::Uint32),
34-
"uint64" => Ok(MxClassId::Uint64),
35-
"single" => Ok(MxClassId::Single),
36-
"double" => Ok(MxClassId::Double),
37-
"int8" => Ok(MxClassId::Int8),
38-
"int16" => Ok(MxClassId::Int16),
39-
"int32" => Ok(MxClassId::Int32),
40-
"int64" => Ok(MxClassId::Int64),
41-
_ => Err("Unknown MxClassId name".to_string()),
42-
}
43-
}
44-
4520
pub fn mx_array_to_str<'a>(pm: MxArray) -> Result<&'a str> {
4621
let pm_ptr = unsafe { mxArrayToUTF8String(pm) };
4722

@@ -76,15 +51,6 @@ pub fn mx_array_to_f64_slice<'a>(pm: MxArray) -> Result<&'a [f64]> {
7651
}
7752
}
7853

79-
pub fn mx_array_to_f64(pm: MxArray) -> Result<f64> {
80-
let pm_slice = mx_array_to_f64_slice(pm)?;
81-
82-
match pm_slice.len() {
83-
1 => Ok(pm_slice[0]),
84-
_ => Err("MxArray contains an invalid number of doubles".to_string()),
85-
}
86-
}
87-
8854
pub fn mx_array_to_u8_slice<'a>(pm: MxArray) -> Result<&'a [u8]> {
8955
let numel = unsafe { mxGetNumberOfElements(pm) };
9056
let elem_size = unsafe { mxGetElementSize(pm) };
@@ -221,3 +187,57 @@ pub fn copy_as_fortran_order(
221187

222188
Ok(())
223189
}
190+
191+
fn f64_slice_to_vec(buf: &[f64]) -> Result<Vec<u64>> {
192+
buf.iter()
193+
.map(|x| as_nat(*x).or(Err("Invalid value".to_string())))
194+
.collect()
195+
}
196+
197+
pub fn mx_array_to_bbox(pm: MxArray, ndim: usize) -> Result<(Vec<u64>, Vec<u64>)> {
198+
let buf = mx_array_to_f64_slice(pm)?;
199+
200+
// verify shape of array
201+
let input_arg_shape = mx_array_size_to_usize_slice(pm);
202+
if input_arg_shape != &[ndim, 2] {
203+
return Err(format!(
204+
"Bounding box has invalid shape. Needs to be [{}, 2]. Got {:?}.",
205+
ndim, input_arg_shape
206+
));
207+
}
208+
209+
let bbox_min_f64 = &buf[0..ndim];
210+
let bbox_max_f64 = &buf[ndim..(ndim * 2)];
211+
let bbox_min = f64_slice_to_vec(bbox_min_f64)
212+
.or(Err(format!("Invalid lower bound. Got {:?}.", bbox_min_f64)))?;
213+
let bbox_max = f64_slice_to_vec(bbox_max_f64)
214+
.or(Err(format!("Invalid upper bound. Got {:?}.", bbox_max_f64)))?;
215+
216+
if bbox_min
217+
.iter()
218+
.zip(bbox_max.iter())
219+
.any(|(min_x, max_x)| min_x >= max_x)
220+
{
221+
return Err(format!(
222+
"Bounding box has invalid shape. Got min={:?}, max={:?}.",
223+
bbox_min, bbox_max
224+
));
225+
}
226+
227+
let bbox_shape: Vec<u64> = bbox_min
228+
.iter()
229+
.zip(bbox_max.iter())
230+
.map(|(min_x, max_x)| max_x - min_x)
231+
.collect();
232+
233+
let bbox_min = bbox_min.iter().map(|x| x - 1).collect();
234+
235+
if bbox_shape.iter().any(|x| *x < 1) {
236+
return Err(format!(
237+
"Bounding box has invalid shape. Got {:?}.",
238+
bbox_shape
239+
));
240+
}
241+
242+
Ok((bbox_min, bbox_shape))
243+
}

matlab/rust/wkw_mex/src/wkw.rs

Lines changed: 0 additions & 160 deletions
This file was deleted.

0 commit comments

Comments
 (0)