Skip to content

Commit 4df8836

Browse files
committed
Add array_cast test for 2 dimentional array
1 parent 7357a1e commit 4df8836

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

tests/array.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,3 +181,17 @@ macro_rules! small_array_test {
181181
}
182182

183183
small_array_test!(i8 u8 i16 u16 i32 u32 i64 u64);
184+
185+
#[test]
186+
fn array_cast() {
187+
let gil = pyo3::Python::acquire_gil();
188+
let py = gil.python();
189+
let np = PyArrayModule::import(py).unwrap();
190+
let vec2 = vec![vec![1.0, 2.0, 3.0]; 2];
191+
let arr_f64 = PyArray::from_vec2(gil.python(), &np, &vec2).unwrap();
192+
let arr_i32: PyArray<i32> = arr_f64.cast(py, &np, false).unwrap();
193+
assert_eq!(
194+
arr_i32.as_array().unwrap(),
195+
array![[1, 2, 3], [1, 2, 3]].into_dyn()
196+
);
197+
}

0 commit comments

Comments
 (0)