diff --git a/tests/array.rs b/tests/array.rs index 3bc077c59..92b85dd54 100644 --- a/tests/array.rs +++ b/tests/array.rs @@ -461,7 +461,7 @@ fn to_owned_works() { #[test] fn copy_to_works() { - pyo3::Python::with_gil(|py| { + Python::with_gil(|py| { let arr1 = PyArray::arange(py, 2.0, 5.0, 1.0); let arr2 = unsafe { PyArray::::new(py, [3], false) }; @@ -470,3 +470,22 @@ fn copy_to_works() { assert_eq!(arr2.readonly().as_slice().unwrap(), &[2, 3, 4]); }); } + +#[test] +fn get_works() { + Python::with_gil(|py| { + let array = pyarray![py, [[1, 2], [3, 4]], [[5, 6], [7, 8]], [[9, 10], [11, 12]]]; + + unsafe { + assert_eq!(array.get([0, 0, 0]), Some(&1)); + assert_eq!(array.get([2, 1, 1]), Some(&12)); + assert_eq!(array.get([0, 0, 2]), None); + assert_eq!(array.get([0, 2, 0]), None); + assert_eq!(array.get([3, 0, 0]), None); + + assert_eq!(*array.uget([1, 0, 0]), 5); + assert_eq!(*array.uget_mut([0, 1, 0]), 3); + assert_eq!(*array.uget_raw([0, 0, 1]), 2); + } + }); +} diff --git a/tests/to_py.rs b/tests/to_py.rs index abd51ee59..b62ec8b50 100644 --- a/tests/to_py.rs +++ b/tests/to_py.rs @@ -19,6 +19,16 @@ fn to_pyarray_vec() { }); } +#[test] +fn to_pyarray_boxed_slice() { + Python::with_gil(|py| { + let arr = vec![1, 2, 3].into_boxed_slice().to_pyarray(py); + + assert_eq!(arr.shape(), [3]); + assert_eq!(arr.readonly().as_slice().unwrap(), &[1, 2, 3]) + }); +} + #[test] fn to_pyarray_array() { Python::with_gil(|py| { @@ -31,7 +41,7 @@ fn to_pyarray_array() { .map(|dim| dim * size_of::() as isize) .collect::>(); - let py_arr = arr.to_pyarray(py); + let py_arr = PyArray::from_array(py, &arr); assert_eq!(py_arr.shape(), shape.as_slice()); assert_eq!(py_arr.strides(), strides.as_slice()); @@ -105,6 +115,15 @@ fn into_pyarray_vec() { }); } +#[test] +fn into_pyarray_boxed_slice() { + Python::with_gil(|py| { + let arr = vec![1, 2, 3].into_boxed_slice().into_pyarray(py); + + assert_eq!(arr.readonly().as_slice().unwrap(), &[1, 2, 3]) + }); +} + #[test] fn into_pyarray_array() { Python::with_gil(|py| {