Skip to content

Commit 1bb9def

Browse files
committed
Use slice:as_mut_ptr instead of slice::as_ptr to enable modifications via the returned pointers.
1 parent 27d86c0 commit 1bb9def

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

src/array.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -676,9 +676,9 @@ impl<T: Element, D: Dimension> PyArray<T, D> {
676676
/// assert_eq!(pyarray.readonly().as_array(), array![[1, 2], [3, 4]]);
677677
/// });
678678
/// ```
679-
pub fn from_owned_array<'py>(py: Python<'py>, arr: Array<T, D>) -> &'py Self {
679+
pub fn from_owned_array<'py>(py: Python<'py>, mut arr: Array<T, D>) -> &'py Self {
680680
let (strides, dims) = (arr.npy_strides(), arr.raw_dim());
681-
let data_ptr = arr.as_ptr();
681+
let data_ptr = arr.as_mut_ptr();
682682
unsafe { Self::from_raw_parts(py, dims, strides.as_ptr(), data_ptr, arr) }
683683
}
684684

@@ -1071,9 +1071,9 @@ impl<D: Dimension> PyArray<PyObject, D> {
10711071
/// assert!(pyarray.readonly().as_array().get(0).unwrap().as_ref(py).is_instance_of::<CustomElement>().unwrap());
10721072
/// });
10731073
/// ```
1074-
pub fn from_owned_object_array<'py, T>(py: Python<'py>, arr: Array<Py<T>, D>) -> &'py Self {
1074+
pub fn from_owned_object_array<'py, T>(py: Python<'py>, mut arr: Array<Py<T>, D>) -> &'py Self {
10751075
let (strides, dims) = (arr.npy_strides(), arr.raw_dim());
1076-
let data_ptr = arr.as_ptr() as *const PyObject;
1076+
let data_ptr = arr.as_mut_ptr() as *const PyObject;
10771077
unsafe { PyArray::from_raw_parts(py, dims, strides.as_ptr(), data_ptr, arr) }
10781078
}
10791079
}

src/convert.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ impl<T: Element> IntoPyArray for Box<[T]> {
4848
type Item = T;
4949
type Dim = Ix1;
5050

51-
fn into_pyarray<'py>(self, py: Python<'py>) -> &'py PyArray<Self::Item, Self::Dim> {
51+
fn into_pyarray<'py>(mut self, py: Python<'py>) -> &'py PyArray<Self::Item, Self::Dim> {
5252
let dims = [self.len()];
5353
let strides = [mem::size_of::<T>() as npy_intp];
54-
let data_ptr = self.as_ptr();
54+
let data_ptr = self.as_mut_ptr();
5555
unsafe { PyArray::from_raw_parts(py, dims, strides.as_ptr(), data_ptr, self) }
5656
}
5757
}
@@ -60,10 +60,10 @@ impl<T: Element> IntoPyArray for Vec<T> {
6060
type Item = T;
6161
type Dim = Ix1;
6262

63-
fn into_pyarray<'py>(self, py: Python<'py>) -> &'py PyArray<Self::Item, Self::Dim> {
63+
fn into_pyarray<'py>(mut self, py: Python<'py>) -> &'py PyArray<Self::Item, Self::Dim> {
6464
let dims = [self.len()];
6565
let strides = [mem::size_of::<T>() as npy_intp];
66-
let data_ptr = self.as_ptr();
66+
let data_ptr = self.as_mut_ptr();
6767
unsafe { PyArray::from_raw_parts(py, dims, strides.as_ptr(), data_ptr, self) }
6868
}
6969
}

0 commit comments

Comments
 (0)